@vtex/api 6.47.0 → 6.48.1-beta
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 +0 -3
- package/lib/{clients/apps → HttpClient}/AppClient.d.ts +3 -3
- package/lib/{clients/apps → HttpClient}/AppClient.js +5 -10
- package/lib/{clients/apps → HttpClient}/AppGraphQLClient.d.ts +3 -3
- package/lib/{clients/apps → HttpClient}/AppGraphQLClient.js +5 -10
- package/lib/{clients/external → HttpClient}/ExternalClient.d.ts +3 -3
- package/lib/{clients/external → HttpClient}/ExternalClient.js +2 -9
- package/lib/HttpClient/GraphQLClient.d.ts +1 -2
- package/lib/HttpClient/GraphQLClient.js +1 -4
- package/lib/HttpClient/HttpClient.d.ts +5 -6
- package/lib/HttpClient/HttpClient.js +21 -63
- package/lib/{clients → HttpClient}/IOClient.d.ts +4 -4
- package/lib/HttpClient/IOClient.js +14 -0
- package/lib/{clients → HttpClient}/IOGraphQLClient.d.ts +4 -4
- package/lib/{clients → HttpClient}/IOGraphQLClient.js +2 -2
- package/lib/{clients/infra → HttpClient}/InfraClient.d.ts +3 -3
- package/lib/{clients/infra → HttpClient}/InfraClient.js +4 -9
- package/lib/{clients/janus → HttpClient}/JanusClient.d.ts +3 -3
- package/lib/{clients/janus → HttpClient}/JanusClient.js +3 -7
- package/lib/HttpClient/factories/index.d.ts +8 -0
- package/lib/HttpClient/factories/index.js +31 -0
- package/lib/HttpClient/index.d.ts +7 -1
- package/lib/HttpClient/index.js +7 -1
- package/lib/HttpClient/middlewares/cache.d.ts +2 -8
- package/lib/HttpClient/middlewares/cache.js +31 -120
- package/lib/HttpClient/middlewares/cancellationToken.d.ts +1 -1
- package/lib/HttpClient/middlewares/cancellationToken.js +1 -2
- package/lib/HttpClient/middlewares/memoization.js +1 -8
- package/lib/HttpClient/middlewares/metrics.js +31 -12
- package/lib/HttpClient/middlewares/recorder.d.ts +1 -1
- package/lib/HttpClient/middlewares/recorder.js +13 -16
- package/lib/HttpClient/middlewares/request.d.ts +10 -0
- package/lib/HttpClient/middlewares/request.js +87 -0
- package/lib/HttpClient/typings.d.ts +9 -43
- package/lib/IODataSource.d.ts +27 -0
- package/lib/IODataSource.js +46 -0
- package/lib/caches/LRUCache.js +1 -5
- package/lib/caches/LRUDiskCache.js +1 -5
- package/lib/clients/Apps.d.ts +84 -0
- package/lib/clients/Apps.js +326 -0
- package/lib/clients/Assets.d.ts +21 -0
- package/lib/clients/{infra/Assets.js → Assets.js} +19 -74
- package/lib/clients/Billing.d.ts +11 -0
- package/lib/clients/{apps/Billing.js → Billing.js} +3 -8
- package/lib/clients/BillingMetrics.d.ts +12 -0
- package/lib/clients/BillingMetrics.js +10 -0
- package/lib/clients/{apps/Builder.d.ts → Builder.d.ts} +11 -12
- package/lib/clients/{apps/Builder.js → Builder.js} +22 -49
- package/lib/clients/Events.d.ts +6 -0
- package/lib/clients/Events.js +19 -0
- package/lib/clients/Housekeeper.d.ts +11 -0
- package/lib/clients/Housekeeper.js +24 -0
- package/lib/clients/ID.d.ts +22 -0
- package/lib/clients/ID.js +48 -0
- package/lib/clients/IOClients.d.ts +24 -29
- package/lib/clients/IOClients.js +26 -36
- package/lib/clients/LicenseManager.d.ts +6 -0
- package/lib/clients/{janus/LicenseManager.js → LicenseManager.js} +8 -23
- package/lib/clients/Logger.d.ts +27 -0
- package/lib/clients/Logger.js +32 -0
- package/lib/clients/Messages.d.ts +18 -0
- package/lib/clients/Messages.js +20 -0
- package/lib/clients/MessagesGraphQL.d.ts +63 -0
- package/lib/clients/MessagesGraphQL.js +50 -0
- package/lib/clients/Metadata.d.ts +25 -0
- package/lib/clients/Metadata.js +53 -0
- package/lib/clients/Registry.d.ts +61 -0
- package/lib/clients/{infra/Registry.js → Registry.js} +33 -93
- package/lib/clients/Router.d.ts +33 -0
- package/lib/clients/Router.js +50 -0
- package/lib/clients/{janus/Segment.d.ts → Segment.d.ts} +11 -7
- package/lib/clients/Segment.js +69 -0
- package/lib/clients/{janus/Session.d.ts → Session.d.ts} +4 -4
- package/lib/clients/{janus/Session.js → Session.js} +13 -24
- package/lib/clients/{apps/Settings.d.ts → Settings.d.ts} +4 -5
- package/lib/clients/{apps/Settings.js → Settings.js} +20 -14
- package/lib/clients/Sphinx.d.ts +12 -0
- package/lib/clients/Sphinx.js +19 -0
- package/lib/clients/{janus/Tenant.d.ts → Tenant.d.ts} +7 -6
- package/lib/clients/Tenant.js +13 -0
- package/lib/clients/VBase.d.ts +57 -0
- package/lib/clients/VBase.js +116 -0
- package/lib/clients/Workspaces.d.ts +17 -0
- package/lib/clients/Workspaces.js +38 -0
- package/lib/clients/index.d.ts +21 -9
- package/lib/clients/index.js +21 -12
- package/lib/constants.d.ts +1 -49
- package/lib/constants.js +1 -54
- package/lib/errors/ResolverError.d.ts +1 -1
- package/lib/errors/ResolverError.js +2 -2
- package/lib/errors/ResolverWarning.d.ts +1 -1
- package/lib/errors/ResolverWarning.js +2 -2
- package/lib/index.d.ts +7 -9
- package/lib/index.js +6 -8
- package/lib/metrics/MetricsAccumulator.d.ts +18 -1
- package/lib/metrics/MetricsAccumulator.js +22 -38
- package/lib/responses.d.ts +44 -3
- package/lib/service/Runtime.d.ts +18 -0
- package/lib/service/Runtime.js +57 -0
- package/lib/service/{worker/runtime/Service.d.ts → Service.d.ts} +5 -5
- package/lib/service/{worker/runtime/Service.js → Service.js} +1 -2
- package/lib/service/events/index.d.ts +3 -0
- package/lib/service/events/index.js +21 -0
- package/lib/service/graphql/index.d.ts +7 -0
- package/lib/service/graphql/index.js +33 -0
- package/lib/service/graphql/middlewares/error.js +107 -0
- package/lib/service/graphql/middlewares/formatters.d.ts +2 -0
- package/lib/service/graphql/middlewares/formatters.js +64 -0
- package/lib/service/graphql/middlewares/query.d.ts +2 -0
- package/lib/service/graphql/middlewares/query.js +32 -0
- package/lib/service/graphql/middlewares/response.js +36 -0
- package/lib/service/graphql/middlewares/run.d.ts +4 -0
- package/lib/service/graphql/middlewares/run.js +55 -0
- package/lib/service/graphql/middlewares/schema.d.ts +2 -0
- package/lib/service/graphql/middlewares/schema.js +8 -0
- package/lib/service/graphql/middlewares/timings.d.ts +2 -0
- package/lib/service/graphql/middlewares/timings.js +10 -0
- package/lib/service/graphql/middlewares/upload.d.ts +7 -0
- package/lib/service/graphql/schema/index.d.ts +3 -0
- package/lib/service/graphql/schema/index.js +66 -0
- package/lib/service/graphql/schema/messagesLoader.d.ts +4 -0
- package/lib/service/graphql/schema/messagesLoader.js +41 -0
- package/lib/service/graphql/schema/messagesLoaderV2.d.ts +5 -0
- package/lib/service/graphql/schema/messagesLoaderV2.js +44 -0
- package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/Auth.d.ts +0 -1
- package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/Auth.js +5 -11
- package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/Sanitize.d.ts +0 -1
- package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/Sanitize.js +0 -6
- package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/SmartCacheDirective.d.ts +0 -1
- package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/SmartCacheDirective.js +3 -8
- package/lib/service/{worker/runtime/graphql/schema/schemaDirectives/TranslateTo.d.ts → graphql/schema/schemaDirectives/Translatable.d.ts} +1 -2
- package/lib/service/graphql/schema/schemaDirectives/Translatable.js +54 -0
- package/lib/service/graphql/schema/schemaDirectives/TranslatableV2.d.ts +13 -0
- package/lib/service/graphql/schema/schemaDirectives/TranslatableV2.js +67 -0
- package/lib/service/graphql/schema/schemaDirectives/index.d.ts +13 -0
- package/lib/service/graphql/schema/schemaDirectives/index.js +17 -0
- package/lib/service/graphql/schema/typeDefs/index.d.ts +16 -0
- package/lib/service/graphql/schema/typeDefs/index.js +21 -0
- package/lib/service/graphql/schema/typeDefs/ioMessage.d.ts +8 -0
- package/lib/service/graphql/schema/typeDefs/ioMessage.js +33 -0
- package/lib/service/{worker/runtime/graphql → graphql}/schema/typeDefs/sanitizedString.js +1 -5
- package/lib/service/graphql/typings.d.ts +21 -0
- package/lib/service/graphql/utils/cacheControl.d.ts +6 -0
- package/lib/service/graphql/utils/cacheControl.js +38 -0
- package/lib/service/graphql/utils/maxAgeEnum.d.ts +6 -0
- package/lib/service/graphql/utils/maxAgeEnum.js +17 -0
- package/lib/service/http/index.d.ts +3 -0
- package/lib/service/http/index.js +18 -0
- package/lib/service/http/middlewares/authTokens.d.ts +3 -0
- package/lib/service/http/middlewares/cancellationToken.d.ts +3 -0
- package/lib/service/{worker/runtime/http → http}/middlewares/cancellationToken.js +1 -2
- package/lib/service/http/middlewares/clients.d.ts +4 -0
- package/lib/service/http/middlewares/error.d.ts +3 -0
- package/lib/service/{worker/runtime/http → http}/middlewares/error.js +10 -19
- package/lib/service/{worker/runtime/http → http}/middlewares/requestStats.d.ts +3 -3
- package/lib/service/http/middlewares/setCookie.d.ts +3 -0
- package/lib/service/http/middlewares/timings.d.ts +3 -0
- package/lib/service/{worker/runtime/http → http}/middlewares/timings.js +8 -21
- package/lib/service/http/middlewares/vary.d.ts +3 -0
- package/lib/service/{worker/runtime/http → http}/middlewares/vary.js +3 -3
- package/lib/service/logger/index.d.ts +28 -2
- package/lib/service/logger/index.js +68 -5
- package/lib/service/method.d.ts +9 -0
- package/lib/service/{worker/runtime/typings.d.ts → typings.d.ts} +36 -70
- package/lib/service/utils/compose.d.ts +4 -0
- package/lib/service/{worker/runtime/utils → utils}/compose.js +2 -2
- package/lib/utils/MineWinsConflictsResolver.d.ts +4 -5
- package/lib/utils/MineWinsConflictsResolver.js +17 -23
- package/lib/utils/MineWinsConflictsResolver.test.d.ts +1 -0
- package/lib/utils/MineWinsConflictsResolver.test.js +134 -0
- package/lib/utils/app.d.ts +1 -3
- package/lib/utils/app.js +1 -3
- package/lib/utils/appsStaleIfError.d.ts +1 -1
- package/lib/utils/appsStaleIfError.js +2 -2
- package/lib/utils/billingOptions.d.ts +3 -36
- package/lib/utils/billingOptions.js +3 -7
- package/lib/utils/binding.d.ts +3 -3
- package/lib/utils/cancel.d.ts +2 -2
- package/lib/utils/cancel.js +1 -2
- package/lib/utils/log.d.ts +3 -1
- package/lib/utils/log.js +2 -2
- package/lib/utils/message.js +1 -4
- package/lib/utils/tenant.d.ts +3 -3
- package/lib/utils/time.d.ts +2 -4
- package/lib/utils/time.js +2 -9
- package/lib/utils/unhandled.d.ts +1 -0
- package/lib/{service/worker/listeners.js → utils/unhandled.js} +15 -9
- package/package.json +2 -2
- package/CHANGELOG.md +0 -1846
- package/lib/HttpClient/agents.d.ts +0 -3
- package/lib/HttpClient/agents.js +0 -24
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +0 -11
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +0 -30
- package/lib/HttpClient/middlewares/request/index.d.ts +0 -18
- package/lib/HttpClient/middlewares/request/index.js +0 -84
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +0 -1
- package/lib/HttpClient/middlewares/request/setupAxios/index.js +0 -20
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +0 -2
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +0 -53
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +0 -2
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +0 -7
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +0 -8
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +0 -53
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +0 -4
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +0 -29
- package/lib/HttpClient/middlewares/tracing.d.ts +0 -15
- package/lib/HttpClient/middlewares/tracing.js +0 -56
- package/lib/clients/IOClient.js +0 -19
- package/lib/clients/apps/Billing.d.ts +0 -12
- package/lib/clients/apps/MessagesGraphQL.d.ts +0 -61
- package/lib/clients/apps/MessagesGraphQL.js +0 -121
- package/lib/clients/apps/catalogGraphQL/brand.d.ts +0 -13
- package/lib/clients/apps/catalogGraphQL/brand.js +0 -18
- package/lib/clients/apps/catalogGraphQL/category.d.ts +0 -11
- package/lib/clients/apps/catalogGraphQL/category.js +0 -16
- package/lib/clients/apps/catalogGraphQL/index.d.ts +0 -22
- package/lib/clients/apps/catalogGraphQL/index.js +0 -88
- package/lib/clients/apps/catalogGraphQL/product.d.ts +0 -25
- package/lib/clients/apps/catalogGraphQL/product.js +0 -30
- package/lib/clients/apps/catalogGraphQL/sku.d.ts +0 -26
- package/lib/clients/apps/catalogGraphQL/sku.js +0 -30
- package/lib/clients/apps/index.d.ts +0 -7
- package/lib/clients/apps/index.js +0 -12
- package/lib/clients/external/ID.d.ts +0 -23
- package/lib/clients/external/ID.js +0 -60
- package/lib/clients/external/Masterdata.d.ts +0 -94
- package/lib/clients/external/Masterdata.js +0 -224
- package/lib/clients/external/PaymentProvider.d.ts +0 -31
- package/lib/clients/external/PaymentProvider.js +0 -42
- package/lib/clients/external/index.d.ts +0 -4
- package/lib/clients/external/index.js +0 -9
- package/lib/clients/infra/Apps.d.ts +0 -88
- package/lib/clients/infra/Apps.js +0 -508
- package/lib/clients/infra/Assets.d.ts +0 -34
- package/lib/clients/infra/BillingMetrics.d.ts +0 -13
- package/lib/clients/infra/BillingMetrics.js +0 -15
- package/lib/clients/infra/Events.d.ts +0 -12
- package/lib/clients/infra/Events.js +0 -33
- package/lib/clients/infra/Housekeeper.d.ts +0 -10
- package/lib/clients/infra/Housekeeper.js +0 -30
- package/lib/clients/infra/Metadata.d.ts +0 -26
- package/lib/clients/infra/Metadata.js +0 -83
- package/lib/clients/infra/Registry.d.ts +0 -59
- package/lib/clients/infra/Router.d.ts +0 -34
- package/lib/clients/infra/Router.js +0 -81
- package/lib/clients/infra/Sphinx.d.ts +0 -13
- package/lib/clients/infra/Sphinx.js +0 -29
- package/lib/clients/infra/VBase.d.ts +0 -60
- package/lib/clients/infra/VBase.js +0 -196
- package/lib/clients/infra/Workspaces.d.ts +0 -18
- package/lib/clients/infra/Workspaces.js +0 -65
- package/lib/clients/infra/index.d.ts +0 -12
- package/lib/clients/infra/index.js +0 -17
- package/lib/clients/janus/LicenseManager.d.ts +0 -7
- package/lib/clients/janus/Segment.js +0 -88
- package/lib/clients/janus/Tenant.js +0 -28
- package/lib/clients/janus/index.d.ts +0 -5
- package/lib/clients/janus/index.js +0 -10
- package/lib/service/index.d.ts +0 -2
- package/lib/service/index.js +0 -30
- package/lib/service/loaders.d.ts +0 -8
- package/lib/service/loaders.js +0 -54
- package/lib/service/logger/console.d.ts +0 -10
- package/lib/service/logger/console.js +0 -36
- package/lib/service/logger/logger.d.ts +0 -29
- package/lib/service/logger/logger.js +0 -61
- package/lib/service/logger/metricsLogger.d.ts +0 -40
- package/lib/service/logger/metricsLogger.js +0 -149
- package/lib/service/master.d.ts +0 -2
- package/lib/service/master.js +0 -87
- package/lib/service/metrics/requestMetricsMiddleware.d.ts +0 -2
- package/lib/service/metrics/requestMetricsMiddleware.js +0 -44
- package/lib/service/tracing/TracerSingleton.d.ts +0 -7
- package/lib/service/tracing/TracerSingleton.js +0 -48
- package/lib/service/tracing/metrics/MetricNames.d.ts +0 -60
- package/lib/service/tracing/metrics/MetricNames.js +0 -44
- package/lib/service/tracing/metrics/instruments.d.ts +0 -9
- package/lib/service/tracing/metrics/instruments.js +0 -11
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.d.ts +0 -9
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +0 -25
- package/lib/service/tracing/tracingMiddlewares.d.ts +0 -5
- package/lib/service/tracing/tracingMiddlewares.js +0 -107
- package/lib/service/worker/index.d.ts +0 -11
- package/lib/service/worker/index.js +0 -195
- package/lib/service/worker/listeners.d.ts +0 -3
- package/lib/service/worker/runtime/builtIn/handlers.d.ts +0 -4
- package/lib/service/worker/runtime/builtIn/handlers.js +0 -30
- package/lib/service/worker/runtime/builtIn/middlewares.d.ts +0 -4
- package/lib/service/worker/runtime/builtIn/middlewares.js +0 -40
- package/lib/service/worker/runtime/events/index.d.ts +0 -4
- package/lib/service/worker/runtime/events/index.js +0 -46
- package/lib/service/worker/runtime/events/middlewares/body.d.ts +0 -3
- package/lib/service/worker/runtime/events/middlewares/body.js +0 -22
- package/lib/service/worker/runtime/events/middlewares/context.d.ts +0 -3
- package/lib/service/worker/runtime/events/middlewares/context.js +0 -22
- package/lib/service/worker/runtime/events/router.d.ts +0 -2
- package/lib/service/worker/runtime/events/router.js +0 -27
- package/lib/service/worker/runtime/graphql/index.d.ts +0 -6
- package/lib/service/worker/runtime/graphql/index.js +0 -27
- package/lib/service/worker/runtime/graphql/middlewares/context.d.ts +0 -2
- package/lib/service/worker/runtime/graphql/middlewares/context.js +0 -16
- package/lib/service/worker/runtime/graphql/middlewares/error.js +0 -93
- package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +0 -2
- package/lib/service/worker/runtime/graphql/middlewares/query.js +0 -52
- package/lib/service/worker/runtime/graphql/middlewares/response.js +0 -38
- package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +0 -2
- package/lib/service/worker/runtime/graphql/middlewares/run.js +0 -19
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +0 -4
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +0 -28
- package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +0 -4
- package/lib/service/worker/runtime/graphql/schema/index.d.ts +0 -7
- package/lib/service/worker/runtime/graphql/schema/index.js +0 -31
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +0 -6
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +0 -79
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.d.ts +0 -7
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +0 -37
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.d.ts +0 -11
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +0 -61
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.d.ts +0 -7
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +0 -40
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.d.ts +0 -6
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +0 -34
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.d.ts +0 -7
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +0 -39
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +0 -33
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.d.ts +0 -22
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +0 -36
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +0 -7
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +0 -12
- package/lib/service/worker/runtime/graphql/typings.d.ts +0 -31
- package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +0 -1
- package/lib/service/worker/runtime/graphql/utils/cacheControl.js +0 -32
- package/lib/service/worker/runtime/graphql/utils/error.d.ts +0 -1
- package/lib/service/worker/runtime/graphql/utils/error.js +0 -76
- package/lib/service/worker/runtime/graphql/utils/translations.d.ts +0 -14
- package/lib/service/worker/runtime/graphql/utils/translations.js +0 -38
- package/lib/service/worker/runtime/http/index.d.ts +0 -5
- package/lib/service/worker/runtime/http/index.js +0 -58
- package/lib/service/worker/runtime/http/middlewares/authTokens.d.ts +0 -3
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.d.ts +0 -3
- package/lib/service/worker/runtime/http/middlewares/clients.d.ts +0 -4
- package/lib/service/worker/runtime/http/middlewares/context.d.ts +0 -4
- package/lib/service/worker/runtime/http/middlewares/context.js +0 -36
- package/lib/service/worker/runtime/http/middlewares/error.d.ts +0 -2
- package/lib/service/worker/runtime/http/middlewares/rateLimit.d.ts +0 -6
- package/lib/service/worker/runtime/http/middlewares/rateLimit.js +0 -42
- package/lib/service/worker/runtime/http/middlewares/setCookie.d.ts +0 -3
- package/lib/service/worker/runtime/http/middlewares/settings.d.ts +0 -9
- package/lib/service/worker/runtime/http/middlewares/settings.js +0 -44
- package/lib/service/worker/runtime/http/middlewares/timings.d.ts +0 -3
- package/lib/service/worker/runtime/http/middlewares/vary.d.ts +0 -3
- package/lib/service/worker/runtime/http/router.d.ts +0 -2
- package/lib/service/worker/runtime/http/router.js +0 -23
- package/lib/service/worker/runtime/http/routes.d.ts +0 -19
- package/lib/service/worker/runtime/http/routes.js +0 -12
- package/lib/service/worker/runtime/method.d.ts +0 -9
- package/lib/service/worker/runtime/statusTrack.d.ts +0 -14
- package/lib/service/worker/runtime/statusTrack.js +0 -37
- package/lib/service/worker/runtime/utils/compose.d.ts +0 -5
- package/lib/service/worker/runtime/utils/context.d.ts +0 -2
- package/lib/service/worker/runtime/utils/context.js +0 -40
- package/lib/service/worker/runtime/utils/diff.d.ts +0 -12
- package/lib/service/worker/runtime/utils/diff.js +0 -21
- package/lib/service/worker/runtime/utils/recorder.d.ts +0 -8
- package/lib/service/worker/runtime/utils/recorder.js +0 -37
- package/lib/service/worker/runtime/utils/tokenBucket.d.ts +0 -2
- package/lib/service/worker/runtime/utils/tokenBucket.js +0 -16
- package/lib/tracing/LogEvents.d.ts +0 -31
- package/lib/tracing/LogEvents.js +0 -3
- package/lib/tracing/LogFields.d.ts +0 -66
- package/lib/tracing/LogFields.js +0 -3
- package/lib/tracing/Tags.d.ts +0 -81
- package/lib/tracing/Tags.js +0 -7
- package/lib/tracing/UserLandTracer.d.ts +0 -27
- package/lib/tracing/UserLandTracer.js +0 -56
- package/lib/tracing/errorReporting/ErrorReport.d.ts +0 -31
- package/lib/tracing/errorReporting/ErrorReport.js +0 -70
- package/lib/tracing/index.d.ts +0 -9
- package/lib/tracing/index.js +0 -19
- package/lib/tracing/spanReference/SpanReferenceTypes.d.ts +0 -4
- package/lib/tracing/spanReference/SpanReferenceTypes.js +0 -7
- package/lib/tracing/spanReference/createSpanReference.d.ts +0 -3
- package/lib/tracing/spanReference/createSpanReference.js +0 -8
- package/lib/tracing/utils.d.ts +0 -13
- package/lib/tracing/utils.js +0 -40
- package/lib/utils/conflicts.mock.d.ts +0 -17
- package/lib/utils/conflicts.mock.js +0 -27
- /package/lib/service/{worker/runtime/graphql → graphql}/middlewares/error.d.ts +0 -0
- /package/lib/service/{worker/runtime/graphql → graphql}/middlewares/response.d.ts +0 -0
- /package/lib/service/{worker/runtime/graphql → graphql}/middlewares/upload.js +0 -0
- /package/lib/service/{worker/runtime/graphql → graphql}/schema/typeDefs/ioUpload.d.ts +0 -0
- /package/lib/service/{worker/runtime/graphql → graphql}/schema/typeDefs/ioUpload.js +0 -0
- /package/lib/service/{worker/runtime/graphql → graphql}/schema/typeDefs/sanitizedString.d.ts +0 -0
- /package/lib/service/{worker/runtime/graphql → graphql}/typings.js +0 -0
- /package/lib/service/{worker/runtime/utils/toArray.d.ts → graphql/utils/array.d.ts} +0 -0
- /package/lib/service/{worker/runtime/utils/toArray.js → graphql/utils/array.js} +0 -0
- /package/lib/service/{worker/runtime/graphql → graphql}/utils/pathname.d.ts +0 -0
- /package/lib/service/{worker/runtime/graphql → graphql}/utils/pathname.js +0 -0
- /package/lib/service/{worker/runtime/http → http}/middlewares/authTokens.js +0 -0
- /package/lib/service/{worker/runtime/http → http}/middlewares/clients.js +0 -0
- /package/lib/service/{worker/runtime/http → http}/middlewares/requestStats.js +0 -0
- /package/lib/service/{worker/runtime/http → http}/middlewares/setCookie.js +0 -0
- /package/lib/service/{worker/runtime/method.js → method.js} +0 -0
- /package/lib/service/{worker/runtime/typings.js → typings.js} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bluebird_1 = require("bluebird");
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
6
|
+
const messagesLoader_1 = require("../messagesLoader");
|
|
7
|
+
class Translatable extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
8
|
+
visitFieldDefinition(field) {
|
|
9
|
+
const { resolve = graphql_1.defaultFieldResolver } = field;
|
|
10
|
+
const { behavior = 'FULL' } = this.args;
|
|
11
|
+
field.resolve = async (root, args, context, info) => {
|
|
12
|
+
const { clients: { segment }, clients, vtex: { logger } } = context;
|
|
13
|
+
if (Math.random() < 0.1) {
|
|
14
|
+
logger.warn(`Translatable directive in use by: ${context.vtex.account} (Operation Id: ${context.vtex.operationId})`);
|
|
15
|
+
}
|
|
16
|
+
if (!context.loaders || !context.loaders.messages) {
|
|
17
|
+
context.loaders = Object.assign({}, context.loaders, { messages: messagesLoader_1.messagesLoader(clients) });
|
|
18
|
+
}
|
|
19
|
+
const response = await resolve(root, args, context, info);
|
|
20
|
+
const handler = handleSingleString(context, behavior);
|
|
21
|
+
return Array.isArray(response) ? await bluebird_1.map(response, handler) : await handler(response);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Translatable = Translatable;
|
|
26
|
+
const handleSingleString = (context, behavior) => async (response) => {
|
|
27
|
+
// Messages only knows how to process non empty strings.
|
|
28
|
+
if ((typeof response !== 'string' && typeof response !== 'object') || Array.isArray(response) || response == null) {
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
const resObj = typeof response === 'string'
|
|
32
|
+
? {
|
|
33
|
+
content: response,
|
|
34
|
+
description: '',
|
|
35
|
+
from: undefined,
|
|
36
|
+
id: response,
|
|
37
|
+
}
|
|
38
|
+
: response;
|
|
39
|
+
const { content, from, id } = resObj;
|
|
40
|
+
const { clients: { segment }, vtex: { locale } } = context;
|
|
41
|
+
const to = locale != null
|
|
42
|
+
? locale
|
|
43
|
+
: (await segment.getSegment()).cultureInfo;
|
|
44
|
+
if (content == null && id == null) {
|
|
45
|
+
throw new Error(`@translatable directive needs a content or id to translate, but received ${JSON.stringify(response)}`);
|
|
46
|
+
}
|
|
47
|
+
// If the message is already in the target locale, return the content.
|
|
48
|
+
if (!to || from === to) {
|
|
49
|
+
return content;
|
|
50
|
+
}
|
|
51
|
+
return context.loaders.messages.load(Object.assign({}, resObj, { behavior,
|
|
52
|
+
from,
|
|
53
|
+
to }));
|
|
54
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GraphQLField } from 'graphql';
|
|
2
|
+
import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
3
|
+
import { ServiceContext } from '../../../typings';
|
|
4
|
+
export declare class TranslatableV2 extends SchemaDirectiveVisitor {
|
|
5
|
+
visitFieldDefinition(field: GraphQLField<any, ServiceContext>): void;
|
|
6
|
+
}
|
|
7
|
+
export interface TranslatableMessageV2 {
|
|
8
|
+
from?: string;
|
|
9
|
+
content: string;
|
|
10
|
+
context?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const parseTranslatableStringV2: (rawMessage: string) => TranslatableMessageV2;
|
|
13
|
+
export declare const formatTranslatableStringV2: ({ from, content, context }: TranslatableMessageV2) => string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bluebird_1 = require("bluebird");
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
6
|
+
const ramda_1 = require("ramda");
|
|
7
|
+
const messagesLoaderV2_1 = require("../messagesLoaderV2");
|
|
8
|
+
const CONTEXT_REGEX = /\(\(\((?<context>(.)*)\)\)\)/;
|
|
9
|
+
const FROM_REGEX = /\<\<\<(?<from>(.)*)\>\>\>/;
|
|
10
|
+
const CONTENT_REGEX = /\(\(\((?<context>(.)*)\)\)\)|\<\<\<(?<from>(.)*)\>\>\>/g;
|
|
11
|
+
class TranslatableV2 extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
12
|
+
visitFieldDefinition(field) {
|
|
13
|
+
const { resolve = graphql_1.defaultFieldResolver } = field;
|
|
14
|
+
const { behavior = 'FULL', withAppsMetaInfo = false } = this.args;
|
|
15
|
+
field.resolve = async (root, args, ctx, info) => {
|
|
16
|
+
if (!ctx.loaders || !ctx.loaders.messagesV2) {
|
|
17
|
+
ctx.loaders = Object.assign({}, ctx.loaders, { messagesV2: messagesLoaderV2_1.messagesLoaderV2(ctx.clients) });
|
|
18
|
+
}
|
|
19
|
+
const response = await resolve(root, args, ctx, info);
|
|
20
|
+
const { vtex, loaders: { messagesV2 } } = ctx;
|
|
21
|
+
const handler = handleSingleString(vtex, messagesV2, behavior, withAppsMetaInfo);
|
|
22
|
+
return Array.isArray(response) ? await bluebird_1.map(response, handler) : await handler(response);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.TranslatableV2 = TranslatableV2;
|
|
27
|
+
exports.parseTranslatableStringV2 = (rawMessage) => {
|
|
28
|
+
const context = ramda_1.path(['groups', 'context'], rawMessage.match(CONTEXT_REGEX) || {});
|
|
29
|
+
const from = ramda_1.path(['groups', 'from'], rawMessage.match(FROM_REGEX) || {});
|
|
30
|
+
const content = rawMessage.replace(CONTENT_REGEX, '');
|
|
31
|
+
return {
|
|
32
|
+
content: content && content.trim(),
|
|
33
|
+
context: context && context.trim(),
|
|
34
|
+
from: from && from.trim(),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.formatTranslatableStringV2 = ({ from, content, context }) => `${content} ${context ? `(((${context})))` : ''} ${from ? `<<<${from}>>>` : ''}`;
|
|
38
|
+
const handleSingleString = (ctx, messagesV2, behavior, withAppsMetaInfo) => async (rawMessage) => {
|
|
39
|
+
// Messages only knows how to process non empty strings.
|
|
40
|
+
if (rawMessage == null) {
|
|
41
|
+
return rawMessage;
|
|
42
|
+
}
|
|
43
|
+
const { content, context, from: maybeFrom } = exports.parseTranslatableStringV2(rawMessage);
|
|
44
|
+
const { binding, locale: to, tenant } = ctx;
|
|
45
|
+
if (content == null) {
|
|
46
|
+
throw new Error(`@translatableV2 directive needs a content to translate, but received ${JSON.stringify(rawMessage)}`);
|
|
47
|
+
}
|
|
48
|
+
if (to == null) {
|
|
49
|
+
throw new Error('@translatableV2 directive needs the locale variable available in IOContext. You can do this by either setting \`ctx.vtex.locale\` directly or calling this app with \`x-vtex-locale\` header');
|
|
50
|
+
}
|
|
51
|
+
const from = maybeFrom || (binding && binding.locale) || (tenant && tenant.locale);
|
|
52
|
+
if (from == null) {
|
|
53
|
+
throw new Error('@translatableV2 directive needs a source language to translate from. You can do this by either setting \`ctx.vtex.tenant\` variable, call this app with the header \`x-vtex-tenant\` or format the string with the \`formatTranslatableStringV2\` function with the \`from\` option set');
|
|
54
|
+
}
|
|
55
|
+
// If the message is already in the target locale, return the content.
|
|
56
|
+
if (!to || from === to) {
|
|
57
|
+
return content;
|
|
58
|
+
}
|
|
59
|
+
return messagesV2.load({
|
|
60
|
+
behavior,
|
|
61
|
+
content,
|
|
62
|
+
context,
|
|
63
|
+
from,
|
|
64
|
+
to,
|
|
65
|
+
withAppsMetaInfo,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Auth } from './Auth';
|
|
2
|
+
import { SanitizeDirective } from './Sanitize';
|
|
3
|
+
import { SmartCacheDirective } from './SmartCacheDirective';
|
|
4
|
+
import { Translatable } from './Translatable';
|
|
5
|
+
import { TranslatableV2 } from './TranslatableV2';
|
|
6
|
+
export { parseTranslatableStringV2, formatTranslatableStringV2 } from './TranslatableV2';
|
|
7
|
+
export declare const nativeSchemaDirectives: {
|
|
8
|
+
auth: typeof Auth;
|
|
9
|
+
sanitize: typeof SanitizeDirective;
|
|
10
|
+
smartcache: typeof SmartCacheDirective;
|
|
11
|
+
translatable: typeof Translatable;
|
|
12
|
+
translatableV2: typeof TranslatableV2;
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Auth_1 = require("./Auth");
|
|
4
|
+
const Sanitize_1 = require("./Sanitize");
|
|
5
|
+
const SmartCacheDirective_1 = require("./SmartCacheDirective");
|
|
6
|
+
const Translatable_1 = require("./Translatable");
|
|
7
|
+
const TranslatableV2_1 = require("./TranslatableV2");
|
|
8
|
+
var TranslatableV2_2 = require("./TranslatableV2");
|
|
9
|
+
exports.parseTranslatableStringV2 = TranslatableV2_2.parseTranslatableStringV2;
|
|
10
|
+
exports.formatTranslatableStringV2 = TranslatableV2_2.formatTranslatableStringV2;
|
|
11
|
+
exports.nativeSchemaDirectives = {
|
|
12
|
+
auth: Auth_1.Auth,
|
|
13
|
+
sanitize: Sanitize_1.SanitizeDirective,
|
|
14
|
+
smartcache: SmartCacheDirective_1.SmartCacheDirective,
|
|
15
|
+
translatable: Translatable_1.Translatable,
|
|
16
|
+
translatableV2: TranslatableV2_1.TranslatableV2,
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GraphQLScalarType } from 'graphql';
|
|
2
|
+
import { NativeResolverContext } from './ioMessage';
|
|
3
|
+
export declare const scalarResolversMap: {
|
|
4
|
+
'IOMessage': (ctx: NativeResolverContext) => GraphQLScalarType;
|
|
5
|
+
'IOSanitizedString': import("./sanitizedString").IOSanitizedStringType;
|
|
6
|
+
'IOUpload': GraphQLScalarType;
|
|
7
|
+
'Upload': GraphQLScalarType;
|
|
8
|
+
};
|
|
9
|
+
export declare const shouldNotCacheWhenSchemaHas: string[];
|
|
10
|
+
export declare const nativeResolvers: (ctx: NativeResolverContext) => {
|
|
11
|
+
'IOMessage': GraphQLScalarType;
|
|
12
|
+
'IOSanitizedString': import("./sanitizedString").IOSanitizedStringType;
|
|
13
|
+
'IOUpload': GraphQLScalarType;
|
|
14
|
+
'Upload': GraphQLScalarType;
|
|
15
|
+
};
|
|
16
|
+
export declare const nativeTypeDefs: (metaData: Record<string, boolean>) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const apollo_server_core_1 = require("apollo-server-core");
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
const ioMessage_1 = require("./ioMessage");
|
|
6
|
+
const ioUpload_1 = require("./ioUpload");
|
|
7
|
+
const sanitizedString_1 = require("./sanitizedString");
|
|
8
|
+
exports.scalarResolversMap = {
|
|
9
|
+
'IOMessage': ioMessage_1.resolvers,
|
|
10
|
+
'IOSanitizedString': sanitizedString_1.resolvers,
|
|
11
|
+
'IOUpload': ioUpload_1.resolvers,
|
|
12
|
+
'Upload': apollo_server_core_1.GraphQLUpload,
|
|
13
|
+
};
|
|
14
|
+
exports.shouldNotCacheWhenSchemaHas = ['IOMessage'];
|
|
15
|
+
exports.nativeResolvers = (ctx) => ({
|
|
16
|
+
'IOMessage': exports.scalarResolversMap.IOMessage(ctx),
|
|
17
|
+
'IOSanitizedString': exports.scalarResolversMap.IOSanitizedString,
|
|
18
|
+
'IOUpload': exports.scalarResolversMap.IOUpload,
|
|
19
|
+
'Upload': exports.scalarResolversMap.Upload,
|
|
20
|
+
});
|
|
21
|
+
exports.nativeTypeDefs = (metaData) => ramda_1.reduce((acc, scalar) => !metaData[scalar] ? `${acc}\nscalar ${scalar}\n` : acc, '', ramda_1.keys(exports.scalarResolversMap));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import DataLoader from 'dataloader';
|
|
2
|
+
import { GraphQLScalarType } from 'graphql';
|
|
3
|
+
import { IOMessage } from '../../../../utils/message';
|
|
4
|
+
export interface NativeResolverContext {
|
|
5
|
+
getLocaleTo: () => Promise<string>;
|
|
6
|
+
translationsLoader: DataLoader<IOMessage, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare const resolvers: (ctx: NativeResolverContext) => GraphQLScalarType;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const apollo_server_core_1 = require("apollo-server-core");
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const serialize = (ctx) => async (inputArgs) => {
|
|
6
|
+
const args = typeof inputArgs === 'string' ? { content: inputArgs, description: '', from: undefined, id: inputArgs } : inputArgs;
|
|
7
|
+
const { content, from } = args;
|
|
8
|
+
const { translationsLoader, getLocaleTo } = ctx;
|
|
9
|
+
const to = await getLocaleTo();
|
|
10
|
+
// If the message is already in the target locale, return the content.
|
|
11
|
+
if (!to || from === to) {
|
|
12
|
+
return content;
|
|
13
|
+
}
|
|
14
|
+
return await translationsLoader.load(Object.assign({}, args, { from,
|
|
15
|
+
to }));
|
|
16
|
+
};
|
|
17
|
+
const parseValue = (_) => {
|
|
18
|
+
throw new apollo_server_core_1.ApolloError('You cannot use IOMessage as input value', 'INVALID_INPUT_MESSAGE');
|
|
19
|
+
};
|
|
20
|
+
exports.resolvers = (ctx) => new graphql_1.GraphQLScalarType({
|
|
21
|
+
description: 'Internationalizeable String',
|
|
22
|
+
name: 'IOMessage',
|
|
23
|
+
parseLiteral(ast) {
|
|
24
|
+
switch (ast.kind) {
|
|
25
|
+
case graphql_1.Kind.STRING:
|
|
26
|
+
return ast.value;
|
|
27
|
+
default:
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
parseValue,
|
|
32
|
+
serialize: serialize(ctx),
|
|
33
|
+
});
|
|
@@ -15,11 +15,7 @@ class IOSanitizedStringType extends graphql_1.GraphQLScalarType {
|
|
|
15
15
|
constructor(options) {
|
|
16
16
|
const allowHTMLTags = options && options.allowHTMLTags;
|
|
17
17
|
const stripIgnoreTag = !options || options.stripIgnoreTag !== false;
|
|
18
|
-
const xssOptions = {
|
|
19
|
-
stripIgnoreTag,
|
|
20
|
-
...!allowHTMLTags && { whiteList: [] },
|
|
21
|
-
...stripIgnoreTag && { escapeHtml: noop },
|
|
22
|
-
};
|
|
18
|
+
const xssOptions = Object.assign({ stripIgnoreTag }, !allowHTMLTags && { whiteList: [] }, stripIgnoreTag && { escapeHtml: noop });
|
|
23
19
|
super({
|
|
24
20
|
name: options ? `Custom${defaultName}` : defaultName,
|
|
25
21
|
parseLiteral: ast => {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpQueryRequest } from 'apollo-server-core';
|
|
2
|
+
import { HttpQueryResponse } from 'apollo-server-core/dist/runHttpQuery';
|
|
3
|
+
import { GraphQLSchema } from 'graphql';
|
|
4
|
+
import { GraphQLResponse } from 'graphql-extensions';
|
|
5
|
+
import { IOClients } from '../../clients/IOClients';
|
|
6
|
+
import { GraphQLOptions, ServiceContext } from '../typings';
|
|
7
|
+
export interface GraphQLContext {
|
|
8
|
+
graphql: GraphQLOptions<IOClients, any, any> & {
|
|
9
|
+
schema?: GraphQLSchema;
|
|
10
|
+
query?: HttpQueryRequest['query'];
|
|
11
|
+
graphqlResponse?: GraphQLResponse;
|
|
12
|
+
responseInit?: HttpQueryResponse['responseInit'];
|
|
13
|
+
status?: 'success' | 'error';
|
|
14
|
+
graphQLErrors?: any[];
|
|
15
|
+
formatters?: {
|
|
16
|
+
formatError: <T>(e: T) => T;
|
|
17
|
+
formatResponse: <T>(r: T) => T;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare type GraphQLServiceContext = ServiceContext<IOClients, any, GraphQLContext>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GraphQLResponse } from 'graphql-extensions';
|
|
2
|
+
export declare const cacheControl: (response: GraphQLResponse, ctx: import("../../typings").ServiceContext<import("../../..").IOClients, any, import("../typings").GraphQLContext>) => {
|
|
3
|
+
maxAge: string;
|
|
4
|
+
scope: string;
|
|
5
|
+
segment: boolean | undefined;
|
|
6
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ramda_1 = require("ramda");
|
|
4
|
+
const domain_1 = require("../../../utils/domain");
|
|
5
|
+
const maxAgeEnum_1 = require("../utils/maxAgeEnum");
|
|
6
|
+
const linked = !!process.env.VTEX_APP_LINK;
|
|
7
|
+
const pluck = (p) => (list) => ramda_1.pluck(p, list);
|
|
8
|
+
const publicRegExp = ramda_1.compose((exp) => new RegExp(exp), (exp) => `.*${exp}.*`, ramda_1.replace('.', '\\.'));
|
|
9
|
+
const pickCacheControlHints = (response) => ramda_1.path(['extensions', 'cacheControl', 'hints'], response);
|
|
10
|
+
const minArray = (nums) => ramda_1.reduce(ramda_1.min, maxAgeEnum_1.maxAgeEnums.LONG, nums);
|
|
11
|
+
const minMaxAge = (hints) => ramda_1.compose(minArray, ramda_1.reject(ramda_1.isNil), pluck('maxAge'))(hints);
|
|
12
|
+
const anyPrivate = (hints) => ramda_1.compose(ramda_1.any(ramda_1.equals('PRIVATE')), pluck('scope'))(hints);
|
|
13
|
+
const anySegment = (hints) => ramda_1.compose(ramda_1.any(ramda_1.equals('SEGMENT')), pluck('scope'))(hints);
|
|
14
|
+
const isPrivateRoute = ({ request: { headers } }) => ramda_1.test(/_v\/graphql\/private\/v*/, headers['x-forwarded-path'] || '');
|
|
15
|
+
const isPublicEndpoint = ({ request: { headers } }) => {
|
|
16
|
+
if (headers.origin) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const host = headers['x-forwarded-host'] || '';
|
|
20
|
+
return domain_1.PUBLIC_DOMAINS.some(endpoint => ramda_1.test(publicRegExp(endpoint), host));
|
|
21
|
+
};
|
|
22
|
+
exports.cacheControl = (response, ctx) => {
|
|
23
|
+
const { vtex: { production } } = ctx;
|
|
24
|
+
const hints = response && pickCacheControlHints(response);
|
|
25
|
+
const age = hints && minMaxAge(hints);
|
|
26
|
+
const isPrivate = hints && anyPrivate(hints);
|
|
27
|
+
const segment = hints && anySegment(hints);
|
|
28
|
+
const maxAge = linked
|
|
29
|
+
? 'no-store'
|
|
30
|
+
: (isPublicEndpoint(ctx) || !production)
|
|
31
|
+
? 'no-cache'
|
|
32
|
+
: `max-age=${age}`;
|
|
33
|
+
return {
|
|
34
|
+
maxAge,
|
|
35
|
+
scope: (isPrivate || isPrivateRoute(ctx)) ? 'private' : 'public',
|
|
36
|
+
segment,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ramda_1 = require("ramda");
|
|
4
|
+
/*
|
|
5
|
+
* This file contains the enumeration -> int map for generating the max age
|
|
6
|
+
* in the graphql cacheControl
|
|
7
|
+
*/
|
|
8
|
+
exports.maxAgeEnums = {
|
|
9
|
+
LONG: 86400,
|
|
10
|
+
MEDIUM: 3600,
|
|
11
|
+
SHORT: 120,
|
|
12
|
+
};
|
|
13
|
+
exports.defaultMaxAgeFromCtx = (ctx) => {
|
|
14
|
+
const forwarded = ramda_1.path(['request', 'header', 'x-forwarded-path'], ctx);
|
|
15
|
+
const isPrivateRoute = forwarded && /_v\/graphql\/private\/v*/.test(forwarded);
|
|
16
|
+
return (isPrivateRoute) ? 0 : exports.maxAgeEnums.LONG;
|
|
17
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ClientsImplementation, IOClients } from '../../clients/IOClients';
|
|
2
|
+
import { InstanceOptions } from '../../HttpClient';
|
|
3
|
+
export declare const createHttpRoute: <ClientsT extends IOClients, StateT, CustomT>(Clients: ClientsImplementation<ClientsT>, options: Record<string, InstanceOptions>) => (handler: import("koa-compose").Middleware<import("../typings").ServiceContext<ClientsT, StateT, CustomT>> | import("koa-compose").Middleware<import("../typings").ServiceContext<ClientsT, StateT, CustomT>>[]) => import("koa-compose").ComposedMiddleware<import("../typings").ServiceContext<ClientsT, StateT, CustomT>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const compose_1 = require("../utils/compose");
|
|
4
|
+
const authTokens_1 = require("./middlewares/authTokens");
|
|
5
|
+
const cancellationToken_1 = require("./middlewares/cancellationToken");
|
|
6
|
+
const clients_1 = require("./middlewares/clients");
|
|
7
|
+
const error_1 = require("./middlewares/error");
|
|
8
|
+
const requestStats_1 = require("./middlewares/requestStats");
|
|
9
|
+
const setCookie_1 = require("./middlewares/setCookie");
|
|
10
|
+
const timings_1 = require("./middlewares/timings");
|
|
11
|
+
const vary_1 = require("./middlewares/vary");
|
|
12
|
+
exports.createHttpRoute = (Clients, options) => {
|
|
13
|
+
return (handler) => {
|
|
14
|
+
const middlewares = Array.isArray(handler) ? handler : [handler];
|
|
15
|
+
const pipeline = [cancellationToken_1.cancellationToken, requestStats_1.trackIncomingRequestStats, vary_1.vary, authTokens_1.authTokens, clients_1.clients(Clients, options), setCookie_1.removeSetCookie, timings_1.timings, error_1.error, ...middlewares];
|
|
16
|
+
return compose_1.compose(pipeline);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -4,9 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
-
const constants_1 = require("../../../../../constants");
|
|
8
7
|
async function cancellationToken(ctx, next) {
|
|
9
|
-
if (
|
|
8
|
+
if (ctx.method.toUpperCase() === ('GET' || 'OPTIONS' || 'HEAD')) {
|
|
10
9
|
ctx.vtex.cancellation = {
|
|
11
10
|
cancelable: true,
|
|
12
11
|
cancelled: false,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ClientsImplementation, IOClients } from '../../../clients/IOClients';
|
|
2
|
+
import { InstanceOptions } from '../../../HttpClient';
|
|
3
|
+
import { ServiceContext } from '../../typings';
|
|
4
|
+
export declare function clients<T extends IOClients, U, V>(ClientsImpl: ClientsImplementation<T>, clientOptions: Record<string, InstanceOptions>): (ctx: ServiceContext<T, U, V>, next: () => Promise<any>) => Promise<void>;
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
3
|
+
const Logger_1 = require("../../../clients/Logger");
|
|
4
|
+
const constants_1 = require("../../../constants");
|
|
5
|
+
const RequestCancelledError_1 = require("../../../errors/RequestCancelledError");
|
|
6
|
+
const TooManyRequestsError_1 = require("../../../errors/TooManyRequestsError");
|
|
7
|
+
const error_1 = require("../../../utils/error");
|
|
8
8
|
const CACHE_CONTROL_HEADER = 'cache-control';
|
|
9
9
|
const META_HEADER = 'x-vtex-meta';
|
|
10
10
|
const ETAG_HEADER = 'etag';
|
|
11
11
|
const TWO_SECONDS_S = 2;
|
|
12
12
|
const production = process.env.VTEX_PRODUCTION === 'true';
|
|
13
|
-
// todo: unify GraphQL and REST exception treatment
|
|
14
13
|
const logAndRemoveSensitiveData = (ctx, err) => {
|
|
15
|
-
const { method, status, query, vtex: { operationId, requestId, route: { id, params, },
|
|
14
|
+
const { method, status, query, vtex: { operationId, requestId, route: { id, params, }, }, headers: { 'x-forwarded-path': forwardedPath, 'x-forwarded-host': forwardedHost, 'x-forwarded-proto': forwardedProto, 'x-vtex-caller': caller, 'x-vtex-platform': platform, 'x-vtex-product': product, 'x-vtex-locale': locale, }, } = ctx;
|
|
16
15
|
// Grab level from originalError, default to "error" level.
|
|
17
16
|
let level = err && err.level;
|
|
18
|
-
if (!level || !(level ===
|
|
19
|
-
level =
|
|
17
|
+
if (!level || !(level === Logger_1.LogLevel.Error || level === Logger_1.LogLevel.Warn)) {
|
|
18
|
+
level = Logger_1.LogLevel.Error;
|
|
20
19
|
}
|
|
21
|
-
const log = {
|
|
22
|
-
...err,
|
|
23
|
-
caller,
|
|
20
|
+
const log = Object.assign({}, err, { caller,
|
|
24
21
|
forwardedHost,
|
|
25
22
|
forwardedPath,
|
|
26
23
|
forwardedProto,
|
|
@@ -31,11 +28,7 @@ const logAndRemoveSensitiveData = (ctx, err) => {
|
|
|
31
28
|
platform,
|
|
32
29
|
product,
|
|
33
30
|
query,
|
|
34
|
-
requestId,
|
|
35
|
-
routeId: id,
|
|
36
|
-
serverTiming,
|
|
37
|
-
status,
|
|
38
|
-
};
|
|
31
|
+
requestId, routeId: id, status });
|
|
39
32
|
// Use sendLog directly to avoid cleaning error twice.
|
|
40
33
|
ctx.vtex.logger.log(log, level);
|
|
41
34
|
if (!constants_1.LINKED) {
|
|
@@ -45,7 +38,6 @@ const logAndRemoveSensitiveData = (ctx, err) => {
|
|
|
45
38
|
}
|
|
46
39
|
};
|
|
47
40
|
async function error(ctx, next) {
|
|
48
|
-
var _a;
|
|
49
41
|
try {
|
|
50
42
|
await next();
|
|
51
43
|
}
|
|
@@ -69,7 +61,6 @@ async function error(ctx, next) {
|
|
|
69
61
|
// Do not generate etag for errors
|
|
70
62
|
ctx.remove(META_HEADER);
|
|
71
63
|
ctx.remove(ETAG_HEADER);
|
|
72
|
-
(_a = ctx.vtex.recorder) === null || _a === void 0 ? void 0 : _a.clear();
|
|
73
64
|
// In production errors, add two second cache
|
|
74
65
|
if (production) {
|
|
75
66
|
ctx.set(CACHE_CONTROL_HEADER, `public, max-age=${TWO_SECONDS_S}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IOClients } from '
|
|
2
|
-
import {
|
|
1
|
+
import { IOClients } from '../../../clients/IOClients';
|
|
2
|
+
import { ServiceContext } from '../../typings';
|
|
3
3
|
export declare const cancelMessage = "Request cancelled";
|
|
4
4
|
declare class IncomingRequestStats {
|
|
5
5
|
aborted: number;
|
|
@@ -13,5 +13,5 @@ declare class IncomingRequestStats {
|
|
|
13
13
|
clear(): void;
|
|
14
14
|
}
|
|
15
15
|
export declare const incomingRequestStats: IncomingRequestStats;
|
|
16
|
-
export declare function trackIncomingRequestStats<T extends IOClients, U
|
|
16
|
+
export declare function trackIncomingRequestStats<T extends IOClients, U, V>(ctx: ServiceContext<T, U, V>, next: () => Promise<any>): Promise<void>;
|
|
17
17
|
export {};
|
|
@@ -4,42 +4,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const time_1 = require("../../../../../utils/time");
|
|
7
|
+
const status_1 = require("../../../utils/status");
|
|
8
|
+
const time_1 = require("../../../utils/time");
|
|
10
9
|
const APP_ELAPSED_TIME_LOCATOR = time_1.shrinkTimings(time_1.formatTimingName({
|
|
11
10
|
hopNumber: 0,
|
|
12
11
|
source: process.env.VTEX_APP_NAME,
|
|
13
12
|
target: '',
|
|
14
13
|
}));
|
|
15
|
-
const pid = chalk_1.default.magenta('[' + constants_1.PID + ']');
|
|
16
14
|
const formatDate = (date) => chalk_1.default.dim('[' + date.toISOString().split('T')[1] + ']');
|
|
17
15
|
const formatStatus = (status) => status >= 500 ? chalk_1.default.red(status.toString()) : (status >= 200 && status < 300 ? chalk_1.default.green(status.toString()) : status);
|
|
18
16
|
const formatMillis = (millis) => millis >= 500 ? chalk_1.default.red(millis.toString()) : millis >= 200 ? chalk_1.default.yellow(millis.toString()) : chalk_1.default.green(millis.toString());
|
|
19
|
-
const log = ({ vtex: { account, workspace, route: { id } }, path, method, status }, millis) => `${formatDate(new Date())}\t${
|
|
20
|
-
const logBillingInfo = ({ account, workspace, production, route: { id, type } }, millis) => JSON.stringify({
|
|
21
|
-
'__VTEX_IO_BILLING': 'true',
|
|
22
|
-
'account': account,
|
|
23
|
-
'app': constants_1.APP.ID,
|
|
24
|
-
'handler': id,
|
|
25
|
-
'isLink': constants_1.LINKED,
|
|
26
|
-
'production': production,
|
|
27
|
-
'routeType': type === 'public' ? 'public_route' : 'private_route',
|
|
28
|
-
'timestamp': Date.now(),
|
|
29
|
-
'type': 'process-time',
|
|
30
|
-
'value': millis,
|
|
31
|
-
'vendor': constants_1.APP.VENDOR,
|
|
32
|
-
'workspace': workspace,
|
|
33
|
-
});
|
|
17
|
+
const log = ({ vtex: { account, workspace, route: { id } }, path, method, status }, millis) => `${formatDate(new Date())}\t${account}/${workspace}:${id}\t${formatStatus(status)}\t${method}\t${path}\t${formatMillis(millis)} ms`;
|
|
34
18
|
async function timings(ctx, next) {
|
|
35
19
|
// Errors will be caught by the next middleware so we don't have to catch.
|
|
36
20
|
await next();
|
|
37
|
-
const { status: statusCode, vtex: { route: { id } }, timings: { total }
|
|
21
|
+
const { status: statusCode, vtex: { route: { id } }, timings: { total } } = ctx;
|
|
38
22
|
const totalMillis = time_1.hrToMillis(total);
|
|
39
23
|
console.log(log(ctx, totalMillis));
|
|
40
|
-
console.log(logBillingInfo(vtex, totalMillis));
|
|
41
24
|
const status = status_1.statusLabel(statusCode);
|
|
42
25
|
// Only batch successful responses so metrics don't consider errors
|
|
43
26
|
metrics.batch(`http-handler-${id}`, status === 'success' ? total : undefined, { [status]: 1 });
|
|
27
|
+
if (ctx.serverTiming) {
|
|
28
|
+
ctx.serverTiming[APP_ELAPSED_TIME_LOCATOR] = `${totalMillis}`;
|
|
29
|
+
ctx.set('Server-Timing', time_1.reduceTimings(ctx.serverTiming));
|
|
30
|
+
}
|
|
44
31
|
}
|
|
45
32
|
exports.timings = timings;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const constants_1 = require("
|
|
3
|
+
const constants_1 = require("../../../constants");
|
|
4
4
|
const cachingStrategies = [
|
|
5
5
|
{
|
|
6
6
|
forbidden: [],
|
|
@@ -29,9 +29,9 @@ const shouldVaryByHeader = (ctx, header, strategy) => {
|
|
|
29
29
|
};
|
|
30
30
|
async function vary(ctx, next) {
|
|
31
31
|
const { method, path } = ctx;
|
|
32
|
-
const strategy = cachingStrategies.find(
|
|
32
|
+
const strategy = cachingStrategies.find(cachingStrategy => path.indexOf(cachingStrategy.path) === 0);
|
|
33
33
|
if (strategy) {
|
|
34
|
-
strategy.forbidden.forEach(
|
|
34
|
+
strategy.forbidden.forEach(headerName => {
|
|
35
35
|
delete ctx.headers[headerName];
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -1,2 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import { IOContext } from '../../service/typings';
|
|
2
|
+
export declare enum LogLevel {
|
|
3
|
+
Debug = "debug",
|
|
4
|
+
Info = "info",
|
|
5
|
+
Warn = "warn",
|
|
6
|
+
Error = "error"
|
|
7
|
+
}
|
|
8
|
+
export declare class Logger {
|
|
9
|
+
private account;
|
|
10
|
+
private workspace;
|
|
11
|
+
private operationId;
|
|
12
|
+
private requestId;
|
|
13
|
+
private production;
|
|
14
|
+
private executed;
|
|
15
|
+
constructor(ctx: Pick<IOContext, 'account' | 'workspace' | 'requestId' | 'operationId' | 'production'>);
|
|
16
|
+
debug: (message: any) => void;
|
|
17
|
+
info: (message: any) => void;
|
|
18
|
+
warn: (warning: any) => void;
|
|
19
|
+
error: (error: any) => void;
|
|
20
|
+
log: (message: any, level: LogLevel) => void;
|
|
21
|
+
private isThirdPartyApp;
|
|
22
|
+
/**
|
|
23
|
+
* Logs splunk query so the developer can search for the errors in splunk.
|
|
24
|
+
* This function runs only once in the lifetime of the Logger class so we
|
|
25
|
+
* don't mess up with the developer's terminal
|
|
26
|
+
*/
|
|
27
|
+
private logSplunkQuery;
|
|
28
|
+
}
|