@vtex/api 6.48.1-beta → 6.48.1-beta.3
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 +2 -1
- package/lib/HttpClient/GraphQLClient.js +5 -1
- package/lib/HttpClient/HttpClient.d.ts +6 -5
- package/lib/HttpClient/HttpClient.js +64 -21
- package/lib/HttpClient/agents.d.ts +3 -0
- package/lib/HttpClient/agents.js +37 -0
- package/lib/HttpClient/index.d.ts +1 -7
- package/lib/HttpClient/index.js +17 -16
- package/lib/HttpClient/middlewares/cache.d.ts +8 -2
- package/lib/HttpClient/middlewares/cache.js +126 -33
- package/lib/HttpClient/middlewares/cancellationToken.d.ts +1 -1
- package/lib/HttpClient/middlewares/cancellationToken.js +3 -1
- package/lib/HttpClient/middlewares/inflight.js +1 -0
- package/lib/HttpClient/middlewares/memoization.js +9 -1
- package/lib/HttpClient/middlewares/metrics.js +17 -31
- package/lib/HttpClient/middlewares/notFound.js +1 -0
- package/lib/HttpClient/middlewares/recorder.d.ts +1 -1
- package/lib/HttpClient/middlewares/recorder.js +20 -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 +85 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.js +21 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +54 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +7 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +8 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +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 +30 -0
- package/lib/HttpClient/middlewares/tracing.d.ts +15 -0
- package/lib/HttpClient/middlewares/tracing.js +61 -0
- package/lib/HttpClient/typings.d.ts +44 -10
- package/lib/HttpClient/typings.js +1 -0
- package/lib/caches/DiskCache.d.ts +1 -1
- package/lib/caches/DiskCache.js +1 -0
- package/lib/caches/LRUCache.d.ts +2 -2
- package/lib/caches/LRUCache.js +6 -1
- package/lib/caches/LRUDiskCache.d.ts +1 -1
- package/lib/caches/LRUDiskCache.js +6 -1
- package/lib/caches/MultilayeredCache.d.ts +1 -1
- package/lib/caches/MultilayeredCache.js +2 -1
- package/lib/caches/index.js +16 -7
- package/lib/{HttpClient → clients}/IOClient.d.ts +4 -4
- package/lib/clients/IOClient.js +20 -0
- package/lib/clients/IOClients.d.ts +28 -24
- 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} +50 -22
- 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/{Settings.js → apps/Settings.js} +15 -20
- 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 +19 -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 +16 -0
- package/lib/clients/index.d.ts +9 -21
- package/lib/clients/index.js +23 -24
- package/lib/clients/infra/Apps.d.ts +88 -0
- package/lib/clients/infra/Apps.js +511 -0
- package/lib/clients/infra/Assets.d.ts +34 -0
- package/lib/clients/{Assets.js → infra/Assets.js} +75 -19
- 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 +59 -0
- package/lib/clients/{Registry.js → infra/Registry.js} +95 -33
- 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 +60 -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 +23 -0
- package/lib/{HttpClient → clients/janus}/JanusClient.d.ts +3 -3
- package/lib/{HttpClient → clients/janus}/JanusClient.js +8 -3
- package/lib/clients/janus/LicenseManager.d.ts +7 -0
- package/lib/clients/{LicenseManager.js → janus/LicenseManager.js} +24 -8
- 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} +6 -7
- package/lib/clients/janus/Tenant.js +29 -0
- package/lib/clients/janus/index.d.ts +5 -0
- package/lib/clients/janus/index.js +17 -0
- package/lib/constants.d.ts +49 -1
- 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 +3 -2
- 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 +18 -11
- package/lib/index.d.ts +9 -7
- package/lib/index.js +27 -16
- package/lib/metrics/MetricsAccumulator.d.ts +1 -18
- package/lib/metrics/MetricsAccumulator.js +39 -22
- package/lib/responses.d.ts +3 -44
- package/lib/service/index.d.ts +2 -0
- package/lib/service/index.js +34 -0
- package/lib/service/loaders.d.ts +8 -0
- package/lib/service/loaders.js +55 -0
- package/lib/service/logger/console.d.ts +10 -0
- package/lib/service/logger/console.js +37 -0
- package/lib/service/logger/index.d.ts +2 -28
- package/lib/service/logger/index.js +12 -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 +88 -0
- package/lib/service/metrics/requestMetricsMiddleware.d.ts +2 -0
- package/lib/service/metrics/requestMetricsMiddleware.js +45 -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 +12 -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 +114 -0
- package/lib/service/worker/index.d.ts +11 -0
- package/lib/service/worker/index.js +196 -0
- package/lib/service/worker/listeners.d.ts +3 -0
- package/lib/{utils/unhandled.js → service/worker/listeners.js} +10 -15
- 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 +31 -0
- package/lib/service/worker/runtime/builtIn/middlewares.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/middlewares.js +41 -0
- package/lib/service/worker/runtime/events/index.d.ts +4 -0
- package/lib/service/worker/runtime/events/index.js +47 -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 +28 -0
- package/lib/service/worker/runtime/graphql/index.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/index.js +28 -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 +53 -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 +20 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +5 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +29 -0
- package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +4 -0
- package/lib/service/{graphql → worker/runtime/graphql}/middlewares/upload.js +1 -0
- package/lib/service/worker/runtime/graphql/schema/index.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/index.js +32 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +80 -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 +13 -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 +6 -1
- 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 +33 -0
- package/lib/service/worker/runtime/graphql/utils/error.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/utils/error.js +77 -0
- package/lib/service/{graphql → worker/runtime/graphql}/utils/pathname.js +1 -0
- package/lib/service/worker/runtime/graphql/utils/translations.d.ts +14 -0
- package/lib/service/worker/runtime/graphql/utils/translations.js +39 -0
- package/lib/service/worker/runtime/http/index.d.ts +5 -0
- package/lib/service/worker/runtime/http/index.js +59 -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 +37 -0
- package/lib/service/worker/runtime/http/middlewares/error.d.ts +2 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/error.js +28 -15
- 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 +1 -0
- package/lib/service/worker/runtime/http/middlewares/settings.d.ts +9 -0
- package/lib/service/worker/runtime/http/middlewares/settings.js +45 -0
- package/lib/service/worker/runtime/http/middlewares/timings.d.ts +3 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/timings.js +22 -8
- 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 +24 -0
- package/lib/service/worker/runtime/http/routes.d.ts +19 -0
- package/lib/service/worker/runtime/http/routes.js +13 -0
- package/lib/service/worker/runtime/method.d.ts +9 -0
- package/lib/service/{method.js → worker/runtime/method.js} +1 -0
- package/lib/service/worker/runtime/statusTrack.d.ts +14 -0
- package/lib/service/worker/runtime/statusTrack.js +38 -0
- package/lib/service/{typings.d.ts → worker/runtime/typings.d.ts} +70 -36
- package/lib/service/worker/runtime/utils/compose.d.ts +5 -0
- package/lib/service/{utils → worker/runtime/utils}/compose.js +3 -2
- package/lib/service/worker/runtime/utils/context.d.ts +5 -0
- package/lib/service/worker/runtime/utils/context.js +41 -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/{graphql/utils/array.js → worker/runtime/utils/toArray.js} +1 -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/tracing/LogEvents.js +3 -0
- 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 +57 -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 +41 -0
- package/lib/utils/MineWinsConflictsResolver.d.ts +6 -4
- package/lib/utils/MineWinsConflictsResolver.js +35 -17
- package/lib/utils/app.d.ts +3 -1
- package/lib/utils/app.js +4 -1
- package/lib/utils/appsStaleIfError.d.ts +1 -1
- package/lib/utils/appsStaleIfError.js +20 -7
- package/lib/utils/billingOptions.d.ts +36 -3
- package/lib/utils/billingOptions.js +8 -3
- package/lib/utils/binding.d.ts +3 -3
- package/lib/utils/binding.js +1 -0
- package/lib/utils/buildFullPath.d.ts +11 -0
- package/lib/utils/buildFullPath.js +54 -0
- 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 +1 -0
- package/lib/utils/error.js +1 -0
- package/lib/utils/index.js +19 -12
- package/lib/utils/json.js +1 -0
- package/lib/utils/log.d.ts +1 -3
- package/lib/utils/log.js +3 -2
- package/lib/utils/message.js +5 -1
- package/lib/utils/renameBy.js +1 -0
- package/lib/utils/retry.js +3 -2
- package/lib/utils/status.js +1 -0
- package/lib/utils/tenant.d.ts +3 -3
- package/lib/utils/tenant.js +1 -0
- package/lib/utils/throwOnGraphQLErrors.js +1 -0
- package/lib/utils/time.d.ts +7 -7
- package/lib/utils/time.js +10 -2
- package/package.json +3 -3
- 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/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/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/Router.d.ts +0 -33
- package/lib/clients/Router.js +0 -50
- package/lib/clients/Segment.js +0 -69
- 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/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/utils/compose.d.ts +0 -4
- 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
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.graphqlError = void 0;
|
|
4
|
+
const apollo_server_errors_1 = require("apollo-server-errors");
|
|
5
|
+
const ramda_1 = require("ramda");
|
|
6
|
+
const constants_1 = require("../../../../../constants");
|
|
7
|
+
const RequestCancelledError_1 = require("../../../../../errors/RequestCancelledError");
|
|
8
|
+
const logger_1 = require("../../../../logger");
|
|
9
|
+
const error_1 = require("../utils/error");
|
|
10
|
+
const pathname_1 = require("../utils/pathname");
|
|
11
|
+
const TWO_SECONDS_S = 2;
|
|
12
|
+
const uniqErrorsByPath = (errors) => ramda_1.uniqBy(e => e.extensions && e.extensions.exception && e.extensions.exception.request
|
|
13
|
+
? e.extensions.exception.request.path
|
|
14
|
+
: e, errors);
|
|
15
|
+
const createLogErrorToSplunk = (vtex) => (err) => {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f;
|
|
17
|
+
const { route: { id }, logger, } = vtex;
|
|
18
|
+
try {
|
|
19
|
+
// Prevent logging cancellation error (it's not an error)
|
|
20
|
+
if (((_b = (_a = err === null || err === void 0 ? void 0 : err.extensions) === null || _a === void 0 ? void 0 : _a.exception) === null || _b === void 0 ? void 0 : _b.code) === RequestCancelledError_1.cancelledErrorCode) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Add pathName to each error
|
|
24
|
+
if (err.path) {
|
|
25
|
+
err.pathName = pathname_1.generatePathName(err.path);
|
|
26
|
+
}
|
|
27
|
+
const log = {
|
|
28
|
+
...err,
|
|
29
|
+
routeId: id,
|
|
30
|
+
};
|
|
31
|
+
// Grab level from originalError, default to "error" level.
|
|
32
|
+
let level = (_d = (_c = err === null || err === void 0 ? void 0 : err.extensions) === null || _c === void 0 ? void 0 : _c.exception) === null || _d === void 0 ? void 0 : _d.level;
|
|
33
|
+
if (!level || !(level === logger_1.LogLevel.Error || level === logger_1.LogLevel.Warn)) {
|
|
34
|
+
level = logger_1.LogLevel.Error;
|
|
35
|
+
}
|
|
36
|
+
logger.log(log, level);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (!constants_1.LINKED && ((_f = (_e = err === null || err === void 0 ? void 0 : err.extensions) === null || _e === void 0 ? void 0 : _e.exception) === null || _f === void 0 ? void 0 : _f.sensitive)) {
|
|
40
|
+
delete err.extensions.exception.sensitive;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
async function graphqlError(ctx, next) {
|
|
45
|
+
const { vtex: { production }, } = ctx;
|
|
46
|
+
let graphQLErrors = null;
|
|
47
|
+
try {
|
|
48
|
+
await next();
|
|
49
|
+
const response = ctx.graphql.graphqlResponse;
|
|
50
|
+
if (response && Array.isArray(response.errors)) {
|
|
51
|
+
const formatter = error_1.createFormatError(ctx);
|
|
52
|
+
graphQLErrors = apollo_server_errors_1.formatApolloErrors(response.errors, { formatter });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
if (!(e instanceof apollo_server_errors_1.ApolloError)) {
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
if (e.code === RequestCancelledError_1.cancelledErrorCode) {
|
|
60
|
+
ctx.status = RequestCancelledError_1.cancelledRequestStatus;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const formatError = error_1.createFormatError(ctx);
|
|
64
|
+
graphQLErrors = Array.isArray(e)
|
|
65
|
+
? e.map(formatError)
|
|
66
|
+
: [formatError(e)];
|
|
67
|
+
// Add response
|
|
68
|
+
ctx.status = e.statusCode || 500;
|
|
69
|
+
if (e.headers) {
|
|
70
|
+
ctx.set(e.headers);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
if (graphQLErrors) {
|
|
75
|
+
ctx.graphql.status = 'error';
|
|
76
|
+
// Filter errors from the same path in the query. This should
|
|
77
|
+
// avoid logging multiple errors from an array for example
|
|
78
|
+
const uniqueErrors = uniqErrorsByPath(graphQLErrors);
|
|
79
|
+
// Log each error to splunk individually
|
|
80
|
+
const logToSplunk = createLogErrorToSplunk(ctx.vtex);
|
|
81
|
+
uniqueErrors.forEach(logToSplunk);
|
|
82
|
+
// In production errors, add two second cache
|
|
83
|
+
if (production) {
|
|
84
|
+
ctx.graphql.cacheControl.maxAge = TWO_SECONDS_S;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
ctx.graphql.cacheControl.noCache = true;
|
|
88
|
+
ctx.graphql.cacheControl.noStore = true;
|
|
89
|
+
}
|
|
90
|
+
ctx.graphql.graphqlResponse = {
|
|
91
|
+
...ctx.graphql.graphqlResponse,
|
|
92
|
+
errors: uniqueErrors,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.graphqlError = graphqlError;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractQuery = void 0;
|
|
4
|
+
const co_body_1 = require("co-body");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
const constants_1 = require("../../../../../constants");
|
|
8
|
+
const LRUCache_1 = require("./../../../../../caches/LRUCache");
|
|
9
|
+
const documentStorage = new LRUCache_1.LRUCache({
|
|
10
|
+
max: 500,
|
|
11
|
+
});
|
|
12
|
+
const queryFromUrl = (url) => {
|
|
13
|
+
const parsedUrl = url_1.parse(url, true);
|
|
14
|
+
const { query: querystringObj } = parsedUrl;
|
|
15
|
+
// Having a BODY_HASH means the query is in the body
|
|
16
|
+
if (querystringObj && querystringObj[constants_1.BODY_HASH]) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
// We need to JSON.parse the variables since they are a stringified
|
|
20
|
+
// in the querystring
|
|
21
|
+
if (querystringObj && typeof querystringObj.variables === 'string') {
|
|
22
|
+
querystringObj.variables = JSON.parse(querystringObj.variables);
|
|
23
|
+
}
|
|
24
|
+
return querystringObj;
|
|
25
|
+
};
|
|
26
|
+
const parseAndValidateQueryToSchema = (query, schema) => {
|
|
27
|
+
const document = graphql_1.parse(query);
|
|
28
|
+
const validation = graphql_1.validate(schema, document);
|
|
29
|
+
if (Array.isArray(validation) && validation.length > 0) {
|
|
30
|
+
throw validation;
|
|
31
|
+
}
|
|
32
|
+
return document;
|
|
33
|
+
};
|
|
34
|
+
exports.extractQuery = (executableSchema) => async function parseAndValidateQuery(ctx, next) {
|
|
35
|
+
const { request, req } = ctx;
|
|
36
|
+
let query;
|
|
37
|
+
if (request.is('multipart/form-data')) {
|
|
38
|
+
query = request.body;
|
|
39
|
+
}
|
|
40
|
+
else if (request.method.toUpperCase() === 'POST') {
|
|
41
|
+
query = await co_body_1.json(req, { limit: '3mb' });
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
query = queryFromUrl(request.url) || (await co_body_1.json(req, { limit: '3mb' }));
|
|
45
|
+
}
|
|
46
|
+
// Assign the query before setting the query.document because if the
|
|
47
|
+
// validation fails we don't loose the query in our error log
|
|
48
|
+
ctx.graphql.query = query;
|
|
49
|
+
query.document = (await documentStorage.getOrSet(query.query, async () => ({
|
|
50
|
+
value: parseAndValidateQueryToSchema(query.query, executableSchema.schema),
|
|
51
|
+
})));
|
|
52
|
+
await next();
|
|
53
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.response = void 0;
|
|
4
|
+
const constants_1 = require("../../../../../constants");
|
|
5
|
+
const cacheControl_1 = require("../utils/cacheControl");
|
|
6
|
+
function setVaryHeaders(ctx, cacheControl) {
|
|
7
|
+
ctx.vary(constants_1.FORWARDED_HOST_HEADER);
|
|
8
|
+
if (cacheControl.scope === 'segment') {
|
|
9
|
+
ctx.vary(constants_1.SEGMENT_HEADER);
|
|
10
|
+
}
|
|
11
|
+
if (cacheControl.scope === 'private' || ctx.query.scope === 'private') {
|
|
12
|
+
ctx.vary(constants_1.SEGMENT_HEADER);
|
|
13
|
+
ctx.vary(constants_1.SESSION_HEADER);
|
|
14
|
+
}
|
|
15
|
+
else if (ctx.vtex.sessionToken) {
|
|
16
|
+
ctx.vtex.logger.warn({
|
|
17
|
+
message: 'GraphQL resolver receiving session token without private scope',
|
|
18
|
+
userAgent: ctx.get('user-agent'),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function response(ctx, next) {
|
|
23
|
+
var _a;
|
|
24
|
+
await next();
|
|
25
|
+
const { cacheControl, status, graphqlResponse, } = ctx.graphql;
|
|
26
|
+
const cacheControlHeader = cacheControl_1.cacheControlHTTP(ctx);
|
|
27
|
+
ctx.set(constants_1.CACHE_CONTROL_HEADER, cacheControlHeader);
|
|
28
|
+
if (status === 'error') {
|
|
29
|
+
// Do not generate etag for errors
|
|
30
|
+
ctx.remove(constants_1.META_HEADER);
|
|
31
|
+
ctx.remove(constants_1.ETAG_HEADER);
|
|
32
|
+
(_a = ctx.vtex.recorder) === null || _a === void 0 ? void 0 : _a.clear();
|
|
33
|
+
}
|
|
34
|
+
if (ctx.method.toUpperCase() === 'GET') {
|
|
35
|
+
setVaryHeaders(ctx, cacheControl);
|
|
36
|
+
}
|
|
37
|
+
ctx.body = graphqlResponse;
|
|
38
|
+
}
|
|
39
|
+
exports.response = response;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
exports.run = (executableSchema) => async function runHttpQuery(ctx, next) {
|
|
6
|
+
const { graphql: { query }, } = ctx;
|
|
7
|
+
const { document, operationName, variables: variableValues } = query;
|
|
8
|
+
const schema = executableSchema.schema;
|
|
9
|
+
const response = await graphql_1.execute({
|
|
10
|
+
contextValue: ctx,
|
|
11
|
+
document,
|
|
12
|
+
fieldResolver: (root, _, __, info) => root[info.fieldName],
|
|
13
|
+
operationName,
|
|
14
|
+
rootValue: null,
|
|
15
|
+
schema,
|
|
16
|
+
variableValues,
|
|
17
|
+
});
|
|
18
|
+
ctx.graphql.graphqlResponse = response;
|
|
19
|
+
await next();
|
|
20
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IOClients } from '../../../../../clients';
|
|
2
|
+
import { GraphQLOptions, ParamsContext, RecorderState } from '../../typings';
|
|
3
|
+
import { ExecutableSchema } from '../typings';
|
|
4
|
+
import { GraphQLServiceContext } from '../typings';
|
|
5
|
+
export declare const updateSchema: <T extends IOClients, U extends RecorderState, V extends ParamsContext>(graphql: GraphQLOptions<T, U, V>, executableSchema: ExecutableSchema) => (ctx: GraphQLServiceContext, next: () => Promise<void>) => Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateSchema = void 0;
|
|
4
|
+
const constants_1 = require("../../../../../constants");
|
|
5
|
+
const utils_1 = require("../../../../../utils");
|
|
6
|
+
const index_1 = require("../schema/index");
|
|
7
|
+
exports.updateSchema = (graphql, executableSchema) => async function updateRunnableSchema(ctx, next) {
|
|
8
|
+
const { clients: { apps }, vtex: { logger }, app, } = ctx;
|
|
9
|
+
if (!ctx.headers[constants_1.PROVIDER_HEADER]) {
|
|
10
|
+
await next();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
// fetches the new schema and generate a new runnable schema, updates the provider app,
|
|
14
|
+
if (executableSchema.hasProvider &&
|
|
15
|
+
(!executableSchema.provider ||
|
|
16
|
+
utils_1.majorEqualAndGreaterThan(utils_1.parseAppId(ctx.headers[constants_1.PROVIDER_HEADER]).version, utils_1.parseAppId(executableSchema.provider).version))) {
|
|
17
|
+
try {
|
|
18
|
+
const newSchema = (await apps.getAppFile(ctx.headers[constants_1.PROVIDER_HEADER], 'public/schema.graphql')).data.toString('utf-8');
|
|
19
|
+
graphql.schema = newSchema;
|
|
20
|
+
const newRunnableSchema = index_1.makeSchema(graphql);
|
|
21
|
+
executableSchema.schema = newRunnableSchema.schema;
|
|
22
|
+
executableSchema.provider = ctx.headers[constants_1.PROVIDER_HEADER];
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
logger.error({ error, message: 'Update schema failed', app });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
await next();
|
|
29
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IOClients } from '../../../../../clients/IOClients';
|
|
2
|
+
import { GraphQLOptions, ParamsContext, RecorderState } from '../../typings';
|
|
3
|
+
export declare type SchemaMetaData = Record<string, boolean>;
|
|
4
|
+
export declare const makeSchema: <ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext>(options: GraphQLOptions<ClientsT, StateT, CustomT>) => {
|
|
5
|
+
schema: import("graphql").GraphQLSchema;
|
|
6
|
+
hasProvider: boolean;
|
|
7
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeSchema = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
6
|
+
const ramda_1 = require("ramda");
|
|
7
|
+
const schemaDirectives_1 = require("./schemaDirectives");
|
|
8
|
+
const typeDefs_1 = require("./typeDefs");
|
|
9
|
+
const mergeTypeDefs = (appTypeDefs, schemaMetaData) => [appTypeDefs, typeDefs_1.nativeTypeDefs(schemaMetaData), schemaDirectives_1.nativeSchemaDirectivesTypeDefs].join('\n\n');
|
|
10
|
+
const hasScalar = (typeDefs) => (scalar) => new RegExp(`scalar(\\s)+${scalar}(\\s\\n)+`).test(typeDefs);
|
|
11
|
+
const extractSchemaMetaData = (typeDefs) => {
|
|
12
|
+
const scalars = ramda_1.keys(typeDefs_1.nativeResolvers);
|
|
13
|
+
const scalarsPresentInSchema = ramda_1.map(hasScalar(typeDefs), scalars);
|
|
14
|
+
return ramda_1.zipObj(scalars, scalarsPresentInSchema);
|
|
15
|
+
};
|
|
16
|
+
exports.makeSchema = (options) => {
|
|
17
|
+
const { resolvers: appResolvers, schema: appSchema, schemaDirectives: appDirectives } = options;
|
|
18
|
+
const appTypeDefs = appSchema || fs_extra_1.readFileSync('./service/schema.graphql', 'utf8');
|
|
19
|
+
const schemaMetaData = extractSchemaMetaData(appTypeDefs);
|
|
20
|
+
const executableSchema = graphql_tools_1.makeExecutableSchema({
|
|
21
|
+
resolvers: {
|
|
22
|
+
...appResolvers,
|
|
23
|
+
...typeDefs_1.nativeResolvers,
|
|
24
|
+
},
|
|
25
|
+
schemaDirectives: {
|
|
26
|
+
...appDirectives,
|
|
27
|
+
...schemaDirectives_1.nativeSchemaDirectives,
|
|
28
|
+
},
|
|
29
|
+
typeDefs: mergeTypeDefs(appTypeDefs, schemaMetaData),
|
|
30
|
+
});
|
|
31
|
+
return { schema: executableSchema, hasProvider: appSchema ? true : false };
|
|
32
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import DataLoader from 'dataloader';
|
|
2
|
+
import { Message } from '../../../../../clients/apps/MessagesGraphQL';
|
|
3
|
+
import { AppMetaInfo } from '../../../../../clients/infra/Apps';
|
|
4
|
+
import { IOClients } from './../../../../../clients/IOClients';
|
|
5
|
+
export declare const createMessagesLoader: ({ messagesGraphQL, assets }: IOClients, to: string, dependencies?: AppMetaInfo[] | undefined) => DataLoader<Message, string>;
|
|
6
|
+
export declare type MessagesLoaderV2 = ReturnType<typeof createMessagesLoader>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createMessagesLoader = void 0;
|
|
7
|
+
const dataloader_1 = __importDefault(require("dataloader"));
|
|
8
|
+
const ramda_1 = require("ramda");
|
|
9
|
+
const sortByContentAndFrom = (indexedMessages) => ramda_1.sortBy(([_, { content, from }]) => `__from:${from}__content:${content}`, indexedMessages);
|
|
10
|
+
// O(n) counting sort implementation
|
|
11
|
+
const sortByIndex = (indexedTranslations) => indexedTranslations.reduce((acc, [index, data]) => {
|
|
12
|
+
acc[index] = data;
|
|
13
|
+
return acc;
|
|
14
|
+
}, []);
|
|
15
|
+
const indexMessagesByFrom = (messages) => messages.reduce((acc, { from, context, content, behavior }) => {
|
|
16
|
+
const lastIndexed = acc.length && acc[acc.length - 1];
|
|
17
|
+
const formatted = {
|
|
18
|
+
behavior,
|
|
19
|
+
content,
|
|
20
|
+
context,
|
|
21
|
+
};
|
|
22
|
+
if (lastIndexed && lastIndexed.from === from) {
|
|
23
|
+
lastIndexed.messages.push(formatted);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
acc.push({
|
|
27
|
+
from,
|
|
28
|
+
messages: [formatted],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return acc;
|
|
32
|
+
}, []);
|
|
33
|
+
const toPairs = (x) => x.map((xx, it) => [it, xx]);
|
|
34
|
+
const splitIndex = (indexed) => indexed.reduce((acc, [index, data]) => {
|
|
35
|
+
acc[0].push(index);
|
|
36
|
+
acc[1].push(data);
|
|
37
|
+
return acc;
|
|
38
|
+
}, [[], []]);
|
|
39
|
+
const filterFromEqualsTo = (indexedMessages, to) => indexedMessages.reduce((acc, indexed) => {
|
|
40
|
+
const [index, { content, from }] = indexed;
|
|
41
|
+
if (to === from.toLowerCase() || !content) {
|
|
42
|
+
acc.original.push([index, content]);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
acc.toTranslate.push(indexed);
|
|
46
|
+
}
|
|
47
|
+
return acc;
|
|
48
|
+
}, {
|
|
49
|
+
original: [],
|
|
50
|
+
toTranslate: [],
|
|
51
|
+
});
|
|
52
|
+
const messageToKey = ({ content, context, from }) => `:content:${content}:context:${context}:from:${from}`;
|
|
53
|
+
exports.createMessagesLoader = ({ messagesGraphQL, assets }, to, dependencies) => {
|
|
54
|
+
const loweredTo = to.toLowerCase();
|
|
55
|
+
const messagesDeps = dependencies && assets.getFilteredDependencies('vtex.messages@1.x', dependencies);
|
|
56
|
+
const depTree = messagesDeps && JSON.stringify(messagesDeps);
|
|
57
|
+
return new dataloader_1.default(async (messages) => {
|
|
58
|
+
const indexedMessages = toPairs(messages);
|
|
59
|
+
const { toTranslate, original } = filterFromEqualsTo(indexedMessages, loweredTo);
|
|
60
|
+
// In case we have nothing to translate
|
|
61
|
+
if (toTranslate.length === 0) {
|
|
62
|
+
return messages.map(({ content }) => content);
|
|
63
|
+
}
|
|
64
|
+
const sortedIndexedMessages = sortByContentAndFrom(toTranslate);
|
|
65
|
+
const [originalIndexes, sortedMessages] = splitIndex(sortedIndexedMessages);
|
|
66
|
+
const indexedByFrom = indexMessagesByFrom(sortedMessages);
|
|
67
|
+
const args = { indexedByFrom, to };
|
|
68
|
+
const translations = depTree
|
|
69
|
+
? await messagesGraphQL.translateWithDependencies({ ...args, depTree })
|
|
70
|
+
: await messagesGraphQL.translate(args);
|
|
71
|
+
const indexedTranslations = ramda_1.zip(originalIndexes, translations);
|
|
72
|
+
const allIndexedTranslations = [...indexedTranslations, ...original];
|
|
73
|
+
return sortByIndex(allIndexedTranslations);
|
|
74
|
+
}, {
|
|
75
|
+
batch: true,
|
|
76
|
+
cache: true,
|
|
77
|
+
cacheKeyFn: messageToKey,
|
|
78
|
+
maxBatchSize: 200,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
@@ -3,3 +3,4 @@ import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
|
3
3
|
export declare class Auth extends SchemaDirectiveVisitor {
|
|
4
4
|
visitFieldDefinition(field: GraphQLField<any, any>): void;
|
|
5
5
|
}
|
|
6
|
+
export declare const authDirectiveTypeDefs = "\ndirective @auth(\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
|
|
@@ -3,11 +3,12 @@ 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
|
-
|
|
6
|
+
exports.authDirectiveTypeDefs = exports.Auth = void 0;
|
|
7
|
+
const apollo_server_errors_1 = require("apollo-server-errors");
|
|
7
8
|
const axios_1 = __importDefault(require("axios"));
|
|
8
9
|
const graphql_1 = require("graphql");
|
|
9
10
|
const graphql_tools_1 = require("graphql-tools");
|
|
10
|
-
async function
|
|
11
|
+
async function parseIdToken(authToken, vtexIdToken) {
|
|
11
12
|
const url = `vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=${vtexIdToken}`;
|
|
12
13
|
const req = await axios_1.default.request({
|
|
13
14
|
headers: {
|
|
@@ -21,7 +22,7 @@ async function getUserEmail(authToken, vtexIdToken) {
|
|
|
21
22
|
if (!req.data) {
|
|
22
23
|
return undefined;
|
|
23
24
|
}
|
|
24
|
-
return req.data
|
|
25
|
+
return { ...req.data };
|
|
25
26
|
}
|
|
26
27
|
async function getUserCanAccessResource(authToken, account, userEmail, productCode, resourceCode) {
|
|
27
28
|
const url = `http://${account}.vtexcommercestable.com.br/api/license-manager/pvt/accounts/${account}/products/${productCode}/logins/${userEmail}/resources/${resourceCode}/granted`;
|
|
@@ -37,20 +38,20 @@ async function getUserCanAccessResource(authToken, account, userEmail, productCo
|
|
|
37
38
|
async function auth(ctx, authArgs) {
|
|
38
39
|
const vtexIdToken = ctx.cookies.get('VtexIdclientAutCookie') || ctx.get('VtexIdclientAutCookie');
|
|
39
40
|
if (!vtexIdToken) {
|
|
40
|
-
throw new
|
|
41
|
+
throw new apollo_server_errors_1.AuthenticationError('VtexIdclientAutCookie not found.');
|
|
41
42
|
}
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
44
|
-
throw new
|
|
43
|
+
const parsedToken = await parseIdToken(ctx.vtex.authToken, vtexIdToken);
|
|
44
|
+
if (!parsedToken || parsedToken.account !== ctx.vtex.account) {
|
|
45
|
+
throw new apollo_server_errors_1.AuthenticationError('Could not find user specified by VtexIdclientAutCookie.');
|
|
45
46
|
}
|
|
46
|
-
const userCanAccessResource = await getUserCanAccessResource(ctx.vtex.authToken, ctx.vtex.account,
|
|
47
|
+
const userCanAccessResource = await getUserCanAccessResource(ctx.vtex.authToken, ctx.vtex.account, parsedToken.user, authArgs.productCode, authArgs.resourceCode);
|
|
47
48
|
if (!userCanAccessResource) {
|
|
48
|
-
throw new
|
|
49
|
+
throw new apollo_server_errors_1.ForbiddenError('User indicated by VtexIdclientAutCookie is not authorized to access the indicated resource.');
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
function parseArgs(authArgs) {
|
|
52
53
|
if (!authArgs.productCode || !authArgs.resourceCode) {
|
|
53
|
-
throw new
|
|
54
|
+
throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(productCode: String, resourceCode: String).');
|
|
54
55
|
}
|
|
55
56
|
return authArgs;
|
|
56
57
|
}
|
|
@@ -65,3 +66,9 @@ class Auth extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
exports.Auth = Auth;
|
|
69
|
+
exports.authDirectiveTypeDefs = `
|
|
70
|
+
directive @auth(
|
|
71
|
+
productCode: String
|
|
72
|
+
resourceCode: String
|
|
73
|
+
) on FIELD_DEFINITION
|
|
74
|
+
`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GraphQLField } from 'graphql';
|
|
2
|
+
import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
3
|
+
import { GraphQLServiceContext } from '../../typings';
|
|
4
|
+
export declare class CacheControl extends SchemaDirectiveVisitor {
|
|
5
|
+
visitFieldDefinition(field: GraphQLField<any, GraphQLServiceContext>): void;
|
|
6
|
+
}
|
|
7
|
+
export declare const cacheControlDirectiveTypeDefs = "\n\nenum IOCacheControlScope {\n SEGMENT\n PUBLIC\n PRIVATE\n}\n\ndirective @cacheControl(\n maxAge: Int\n scope: IOCacheControlScope\n) on FIELD_DEFINITION\n";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cacheControlDirectiveTypeDefs = exports.CacheControl = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
6
|
+
class CacheControl extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
7
|
+
visitFieldDefinition(field) {
|
|
8
|
+
const { resolve = graphql_1.defaultFieldResolver } = field;
|
|
9
|
+
const { maxAge: directiveMaxAge, scope: directiveScope, } = this.args;
|
|
10
|
+
field.resolve = (root, args, ctx, info) => {
|
|
11
|
+
const { maxAge, scope, } = ctx.graphql.cacheControl;
|
|
12
|
+
if (Number.isInteger(directiveMaxAge) && directiveMaxAge < maxAge) {
|
|
13
|
+
ctx.graphql.cacheControl.maxAge = directiveMaxAge;
|
|
14
|
+
}
|
|
15
|
+
if (directiveScope === 'PRIVATE') {
|
|
16
|
+
ctx.graphql.cacheControl.scope = 'private';
|
|
17
|
+
}
|
|
18
|
+
else if (directiveScope === 'SEGMENT' && scope === 'public') {
|
|
19
|
+
ctx.graphql.cacheControl.scope = 'segment';
|
|
20
|
+
}
|
|
21
|
+
return resolve(root, args, ctx, info);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.CacheControl = CacheControl;
|
|
26
|
+
exports.cacheControlDirectiveTypeDefs = `
|
|
27
|
+
|
|
28
|
+
enum IOCacheControlScope {
|
|
29
|
+
SEGMENT
|
|
30
|
+
PUBLIC
|
|
31
|
+
PRIVATE
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
directive @cacheControl(
|
|
35
|
+
maxAge: Int
|
|
36
|
+
scope: IOCacheControlScope
|
|
37
|
+
) on FIELD_DEFINITION
|
|
38
|
+
`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GraphQLArgument, GraphQLField, GraphQLInputField } from 'graphql';
|
|
2
|
+
import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
3
|
+
import { Logger } from '../../../../../logger/logger';
|
|
4
|
+
import { GraphQLServiceContext } from '../../typings';
|
|
5
|
+
export declare class Deprecated extends SchemaDirectiveVisitor {
|
|
6
|
+
visitArgumentDefinition(argument: GraphQLArgument): void;
|
|
7
|
+
visitInputFieldDefinition(field: GraphQLInputField): void;
|
|
8
|
+
visitFieldDefinition(field: GraphQLField<any, GraphQLServiceContext>): void;
|
|
9
|
+
protected maybeLogToSplunk<T>(payload: T, logger?: Logger): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const deprecatedDirectiveTypeDefs = "\ndirective @deprecated(\n reason: String = \"No longer supported\"\n) on\n FIELD_DEFINITION\n | INPUT_FIELD_DEFINITION\n | ARGUMENT_DEFINITION\n | FRAGMENT_DEFINITION\n";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deprecatedDirectiveTypeDefs = exports.Deprecated = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
6
|
+
const listeners_1 = require("../../../../listeners");
|
|
7
|
+
let lastLog = process.hrtime();
|
|
8
|
+
const LOG_PERIOD_S = 60;
|
|
9
|
+
const hrtimeToS = (time) => time[0] + (time[1] / 1e9);
|
|
10
|
+
class Deprecated extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
11
|
+
visitArgumentDefinition(argument) {
|
|
12
|
+
this.maybeLogToSplunk({
|
|
13
|
+
description: argument.description,
|
|
14
|
+
name: argument.name,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
visitInputFieldDefinition(field) {
|
|
18
|
+
this.maybeLogToSplunk({
|
|
19
|
+
description: field.description,
|
|
20
|
+
name: field.name,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
visitFieldDefinition(field) {
|
|
24
|
+
const { resolve = graphql_1.defaultFieldResolver, name, type } = field;
|
|
25
|
+
const { reason } = this.args;
|
|
26
|
+
field.resolve = (root, args, ctx, info) => {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
this.maybeLogToSplunk({
|
|
29
|
+
headers: ctx.request.headers,
|
|
30
|
+
name,
|
|
31
|
+
query: ((_a = ctx.graphql.query) === null || _a === void 0 ? void 0 : _a.document) && graphql_1.print((_b = ctx.graphql.query) === null || _b === void 0 ? void 0 : _b.document),
|
|
32
|
+
reason,
|
|
33
|
+
variables: (_c = ctx.graphql.query) === null || _c === void 0 ? void 0 : _c.variables,
|
|
34
|
+
}, ctx.vtex.logger);
|
|
35
|
+
return resolve(root, args, ctx, info);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
maybeLogToSplunk(payload, logger = listeners_1.logger) {
|
|
39
|
+
const now = process.hrtime();
|
|
40
|
+
const timeSinceLastLog = hrtimeToS([
|
|
41
|
+
now[0] - lastLog[0],
|
|
42
|
+
now[1] - lastLog[1],
|
|
43
|
+
]);
|
|
44
|
+
if (timeSinceLastLog > LOG_PERIOD_S) {
|
|
45
|
+
lastLog = now;
|
|
46
|
+
logger.warn({
|
|
47
|
+
message: 'Deprecated field in use',
|
|
48
|
+
...payload,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.Deprecated = Deprecated;
|
|
54
|
+
exports.deprecatedDirectiveTypeDefs = `
|
|
55
|
+
directive @deprecated(
|
|
56
|
+
reason: String = "No longer supported"
|
|
57
|
+
) on
|
|
58
|
+
FIELD_DEFINITION
|
|
59
|
+
| INPUT_FIELD_DEFINITION
|
|
60
|
+
| ARGUMENT_DEFINITION
|
|
61
|
+
| FRAGMENT_DEFINITION
|
|
62
|
+
`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GraphQLField } from 'graphql';
|
|
2
|
+
import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
3
|
+
import { GraphQLServiceContext } from '../../typings';
|
|
4
|
+
export declare class Metric extends SchemaDirectiveVisitor {
|
|
5
|
+
visitFieldDefinition(field: GraphQLField<any, GraphQLServiceContext>): void;
|
|
6
|
+
}
|
|
7
|
+
export declare const metricDirectiveTypeDefs = "\ndirective @metric (\n name: String\n) on FIELD_DEFINITION\n";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.metricDirectiveTypeDefs = exports.Metric = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
6
|
+
const __1 = require("../../../../../..");
|
|
7
|
+
class Metric extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
8
|
+
visitFieldDefinition(field) {
|
|
9
|
+
const { resolve = graphql_1.defaultFieldResolver, name: fieldName } = field;
|
|
10
|
+
const { name = `${__1.APP.NAME}-${fieldName}` } = this.args;
|
|
11
|
+
field.resolve = async (root, args, ctx, info) => {
|
|
12
|
+
let failedToResolve = false;
|
|
13
|
+
let result = null;
|
|
14
|
+
let ellapsed = [0, 0];
|
|
15
|
+
try {
|
|
16
|
+
const start = process.hrtime();
|
|
17
|
+
result = await resolve(root, args, ctx, info);
|
|
18
|
+
ellapsed = process.hrtime(start);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
result = error;
|
|
22
|
+
failedToResolve = true;
|
|
23
|
+
}
|
|
24
|
+
ctx.graphql.status = failedToResolve ? 'error' : 'success';
|
|
25
|
+
const payload = {
|
|
26
|
+
[ctx.graphql.status]: 1,
|
|
27
|
+
};
|
|
28
|
+
metrics.batch(`graphql-metric-${name}`, failedToResolve ? undefined : ellapsed, payload);
|
|
29
|
+
if (failedToResolve) {
|
|
30
|
+
throw result;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.Metric = Metric;
|
|
37
|
+
exports.metricDirectiveTypeDefs = `
|
|
38
|
+
directive @metric (
|
|
39
|
+
name: String
|
|
40
|
+
) on FIELD_DEFINITION
|
|
41
|
+
`;
|
package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Sanitize.d.ts
RENAMED
|
@@ -6,3 +6,4 @@ export declare class SanitizeDirective extends SchemaDirectiveVisitor {
|
|
|
6
6
|
visitArgumentDefinition(argument: GraphQLArgument): void;
|
|
7
7
|
wrapType(field: any): void;
|
|
8
8
|
}
|
|
9
|
+
export declare const sanitizeDirectiveTypeDefs = "\ndirective @sanitize(\n allowHTMLTags: Boolean\n stripIgnoreTag: Boolean\n) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION\n";
|