@vtex/api 6.45.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1685 -0
- package/README.md +65 -0
- package/gen/manifest.schema +189 -0
- package/lib/HttpClient/GraphQLClient.d.ts +28 -0
- package/lib/HttpClient/GraphQLClient.js +30 -0
- package/lib/HttpClient/HttpClient.d.ts +29 -0
- package/lib/HttpClient/HttpClient.js +130 -0
- package/lib/HttpClient/agents.d.ts +3 -0
- package/lib/HttpClient/agents.js +24 -0
- package/lib/HttpClient/index.d.ts +6 -0
- package/lib/HttpClient/index.js +14 -0
- package/lib/HttpClient/middlewares/cache.d.ts +35 -0
- package/lib/HttpClient/middlewares/cache.js +173 -0
- package/lib/HttpClient/middlewares/cancellationToken.d.ts +3 -0
- package/lib/HttpClient/middlewares/cancellationToken.js +72 -0
- package/lib/HttpClient/middlewares/inflight.d.ts +5 -0
- package/lib/HttpClient/middlewares/inflight.js +50 -0
- package/lib/HttpClient/middlewares/memoization.d.ts +7 -0
- package/lib/HttpClient/middlewares/memoization.js +40 -0
- package/lib/HttpClient/middlewares/metrics.d.ts +9 -0
- package/lib/HttpClient/middlewares/metrics.js +110 -0
- package/lib/HttpClient/middlewares/notFound.d.ts +7 -0
- package/lib/HttpClient/middlewares/notFound.js +20 -0
- package/lib/HttpClient/middlewares/recorder.d.ts +3 -0
- package/lib/HttpClient/middlewares/recorder.js +21 -0
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +14 -0
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +37 -0
- package/lib/HttpClient/middlewares/request/index.d.ts +18 -0
- package/lib/HttpClient/middlewares/request/index.js +83 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.js +20 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +48 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +7 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +8 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +51 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +4 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +29 -0
- package/lib/HttpClient/middlewares/tracing.d.ts +15 -0
- package/lib/HttpClient/middlewares/tracing.js +54 -0
- package/lib/HttpClient/typings.d.ts +123 -0
- package/lib/HttpClient/typings.js +11 -0
- package/lib/caches/CacheLayer.d.ts +7 -0
- package/lib/caches/CacheLayer.js +2 -0
- package/lib/caches/DiskCache.d.ts +17 -0
- package/lib/caches/DiskCache.js +70 -0
- package/lib/caches/LRUCache.d.ts +16 -0
- package/lib/caches/LRUCache.js +48 -0
- package/lib/caches/LRUDiskCache.d.ts +21 -0
- package/lib/caches/LRUDiskCache.js +132 -0
- package/lib/caches/MultilayeredCache.d.ts +14 -0
- package/lib/caches/MultilayeredCache.js +68 -0
- package/lib/caches/index.d.ts +6 -0
- package/lib/caches/index.js +9 -0
- package/lib/caches/typings.d.ts +48 -0
- package/lib/caches/typings.js +2 -0
- package/lib/clients/IOClient.d.ts +13 -0
- package/lib/clients/IOClient.js +19 -0
- package/lib/clients/IOClients.d.ts +37 -0
- package/lib/clients/IOClients.js +89 -0
- package/lib/clients/IOGraphQLClient.d.ts +13 -0
- package/lib/clients/IOGraphQLClient.js +16 -0
- package/lib/clients/apps/AppClient.d.ts +9 -0
- package/lib/clients/apps/AppClient.js +34 -0
- package/lib/clients/apps/AppGraphQLClient.d.ts +9 -0
- package/lib/clients/apps/AppGraphQLClient.js +34 -0
- package/lib/clients/apps/Billing.d.ts +12 -0
- package/lib/clients/apps/Billing.js +21 -0
- package/lib/clients/apps/Builder.d.ts +45 -0
- package/lib/clients/apps/Builder.js +114 -0
- package/lib/clients/apps/MessagesGraphQL.d.ts +61 -0
- package/lib/clients/apps/MessagesGraphQL.js +121 -0
- package/lib/clients/apps/Settings.d.ts +14 -0
- package/lib/clients/apps/Settings.js +38 -0
- package/lib/clients/apps/catalogGraphQL/brand.d.ts +13 -0
- package/lib/clients/apps/catalogGraphQL/brand.js +18 -0
- package/lib/clients/apps/catalogGraphQL/category.d.ts +11 -0
- package/lib/clients/apps/catalogGraphQL/category.js +16 -0
- package/lib/clients/apps/catalogGraphQL/index.d.ts +22 -0
- package/lib/clients/apps/catalogGraphQL/index.js +88 -0
- package/lib/clients/apps/catalogGraphQL/product.d.ts +25 -0
- package/lib/clients/apps/catalogGraphQL/product.js +30 -0
- package/lib/clients/apps/catalogGraphQL/sku.d.ts +26 -0
- package/lib/clients/apps/catalogGraphQL/sku.js +30 -0
- package/lib/clients/apps/index.d.ts +7 -0
- package/lib/clients/apps/index.js +12 -0
- package/lib/clients/external/ExternalClient.d.ts +9 -0
- package/lib/clients/external/ExternalClient.js +21 -0
- package/lib/clients/external/ID.d.ts +23 -0
- package/lib/clients/external/ID.js +60 -0
- package/lib/clients/external/Masterdata.d.ts +93 -0
- package/lib/clients/external/Masterdata.js +223 -0
- package/lib/clients/external/PaymentProvider.d.ts +31 -0
- package/lib/clients/external/PaymentProvider.js +42 -0
- package/lib/clients/external/index.d.ts +4 -0
- package/lib/clients/external/index.js +9 -0
- package/lib/clients/index.d.ts +9 -0
- package/lib/clients/index.js +17 -0
- package/lib/clients/infra/Apps.d.ts +88 -0
- package/lib/clients/infra/Apps.js +508 -0
- package/lib/clients/infra/Assets.d.ts +34 -0
- package/lib/clients/infra/Assets.js +165 -0
- package/lib/clients/infra/BillingMetrics.d.ts +13 -0
- package/lib/clients/infra/BillingMetrics.js +15 -0
- package/lib/clients/infra/Events.d.ts +12 -0
- package/lib/clients/infra/Events.js +33 -0
- package/lib/clients/infra/Housekeeper.d.ts +10 -0
- package/lib/clients/infra/Housekeeper.js +30 -0
- package/lib/clients/infra/InfraClient.d.ts +9 -0
- package/lib/clients/infra/InfraClient.js +34 -0
- package/lib/clients/infra/Metadata.d.ts +26 -0
- package/lib/clients/infra/Metadata.js +83 -0
- package/lib/clients/infra/Registry.d.ts +59 -0
- package/lib/clients/infra/Registry.js +207 -0
- package/lib/clients/infra/Router.d.ts +34 -0
- package/lib/clients/infra/Router.js +81 -0
- package/lib/clients/infra/Sphinx.d.ts +13 -0
- package/lib/clients/infra/Sphinx.js +29 -0
- package/lib/clients/infra/VBase.d.ts +60 -0
- package/lib/clients/infra/VBase.js +171 -0
- package/lib/clients/infra/Workspaces.d.ts +18 -0
- package/lib/clients/infra/Workspaces.js +65 -0
- package/lib/clients/infra/index.d.ts +12 -0
- package/lib/clients/infra/index.js +17 -0
- package/lib/clients/janus/JanusClient.d.ts +21 -0
- package/lib/clients/janus/JanusClient.js +30 -0
- package/lib/clients/janus/LicenseManager.d.ts +7 -0
- package/lib/clients/janus/LicenseManager.js +58 -0
- package/lib/clients/janus/Segment.d.ts +36 -0
- package/lib/clients/janus/Segment.js +79 -0
- package/lib/clients/janus/Session.d.ts +15 -0
- package/lib/clients/janus/Session.js +75 -0
- package/lib/clients/janus/Tenant.d.ts +29 -0
- package/lib/clients/janus/Tenant.js +28 -0
- package/lib/clients/janus/index.d.ts +5 -0
- package/lib/clients/janus/index.js +10 -0
- package/lib/constants.d.ts +59 -0
- package/lib/constants.js +65 -0
- package/lib/errors/AuthenticationError.d.ts +18 -0
- package/lib/errors/AuthenticationError.js +24 -0
- package/lib/errors/ForbiddenError.d.ts +18 -0
- package/lib/errors/ForbiddenError.js +24 -0
- package/lib/errors/NotFoundError.d.ts +18 -0
- package/lib/errors/NotFoundError.js +24 -0
- package/lib/errors/RequestCancelledError.d.ts +6 -0
- package/lib/errors/RequestCancelledError.js +11 -0
- package/lib/errors/ResolverError.d.ts +29 -0
- package/lib/errors/ResolverError.js +35 -0
- package/lib/errors/ResolverWarning.d.ts +21 -0
- package/lib/errors/ResolverWarning.js +28 -0
- package/lib/errors/TooManyRequestsError.d.ts +4 -0
- package/lib/errors/TooManyRequestsError.js +9 -0
- package/lib/errors/UserInputError.d.ts +18 -0
- package/lib/errors/UserInputError.js +24 -0
- package/lib/errors/customGraphQLError.d.ts +4 -0
- package/lib/errors/customGraphQLError.js +9 -0
- package/lib/errors/index.d.ts +8 -0
- package/lib/errors/index.js +13 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +21 -0
- package/lib/metrics/MetricsAccumulator.d.ts +35 -0
- package/lib/metrics/MetricsAccumulator.js +125 -0
- package/lib/responses.d.ts +79 -0
- package/lib/responses.js +2 -0
- package/lib/service/index.d.ts +2 -0
- package/lib/service/index.js +30 -0
- package/lib/service/loaders.d.ts +8 -0
- package/lib/service/loaders.js +54 -0
- package/lib/service/logger/console.d.ts +10 -0
- package/lib/service/logger/console.js +36 -0
- package/lib/service/logger/index.d.ts +2 -0
- package/lib/service/logger/index.js +7 -0
- package/lib/service/logger/logger.d.ts +35 -0
- package/lib/service/logger/logger.js +73 -0
- package/lib/service/logger/metricsLogger.d.ts +40 -0
- package/lib/service/logger/metricsLogger.js +149 -0
- package/lib/service/master.d.ts +2 -0
- package/lib/service/master.js +91 -0
- package/lib/service/tracing/TracerSingleton.d.ts +7 -0
- package/lib/service/tracing/TracerSingleton.js +54 -0
- package/lib/service/tracing/metrics/MetricNames.d.ts +60 -0
- package/lib/service/tracing/metrics/MetricNames.js +44 -0
- package/lib/service/tracing/metrics/instruments.d.ts +9 -0
- package/lib/service/tracing/metrics/instruments.js +11 -0
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.d.ts +9 -0
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +25 -0
- package/lib/service/tracing/tracingMiddlewares.d.ts +5 -0
- package/lib/service/tracing/tracingMiddlewares.js +119 -0
- package/lib/service/worker/index.d.ts +11 -0
- package/lib/service/worker/index.js +193 -0
- package/lib/service/worker/listeners.d.ts +3 -0
- package/lib/service/worker/listeners.js +43 -0
- package/lib/service/worker/runtime/Service.d.ts +17 -0
- package/lib/service/worker/runtime/Service.js +23 -0
- package/lib/service/worker/runtime/builtIn/handlers.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/handlers.js +27 -0
- package/lib/service/worker/runtime/builtIn/middlewares.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/middlewares.js +40 -0
- package/lib/service/worker/runtime/events/index.d.ts +4 -0
- package/lib/service/worker/runtime/events/index.js +46 -0
- package/lib/service/worker/runtime/events/middlewares/body.d.ts +3 -0
- package/lib/service/worker/runtime/events/middlewares/body.js +22 -0
- package/lib/service/worker/runtime/events/middlewares/context.d.ts +3 -0
- package/lib/service/worker/runtime/events/middlewares/context.js +22 -0
- package/lib/service/worker/runtime/events/router.d.ts +2 -0
- package/lib/service/worker/runtime/events/router.js +27 -0
- package/lib/service/worker/runtime/graphql/index.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/index.js +27 -0
- package/lib/service/worker/runtime/graphql/middlewares/context.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/context.js +16 -0
- package/lib/service/worker/runtime/graphql/middlewares/error.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/error.js +93 -0
- package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/query.js +52 -0
- package/lib/service/worker/runtime/graphql/middlewares/response.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/response.js +38 -0
- package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/run.js +19 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +4 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +28 -0
- package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +4 -0
- package/lib/service/worker/runtime/graphql/middlewares/upload.js +12 -0
- package/lib/service/worker/runtime/graphql/schema/index.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/index.js +31 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +79 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.js +73 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +37 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.d.ts +11 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +61 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +40 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.d.ts +9 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.js +35 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +34 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.js +29 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +39 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +33 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.d.ts +22 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +36 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +12 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.d.ts +3 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.js +16 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.d.ts +10 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.js +39 -0
- package/lib/service/worker/runtime/graphql/typings.d.ts +31 -0
- package/lib/service/worker/runtime/graphql/typings.js +2 -0
- package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/cacheControl.js +32 -0
- package/lib/service/worker/runtime/graphql/utils/error.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/error.js +76 -0
- package/lib/service/worker/runtime/graphql/utils/pathname.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/pathname.js +7 -0
- package/lib/service/worker/runtime/graphql/utils/translations.d.ts +14 -0
- package/lib/service/worker/runtime/graphql/utils/translations.js +38 -0
- package/lib/service/worker/runtime/http/index.d.ts +5 -0
- package/lib/service/worker/runtime/http/index.js +58 -0
- package/lib/service/worker/runtime/http/middlewares/authTokens.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/authTokens.js +12 -0
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.js +18 -0
- package/lib/service/worker/runtime/http/middlewares/clients.d.ts +4 -0
- package/lib/service/worker/runtime/http/middlewares/clients.js +12 -0
- package/lib/service/worker/runtime/http/middlewares/context.d.ts +4 -0
- package/lib/service/worker/runtime/http/middlewares/context.js +36 -0
- package/lib/service/worker/runtime/http/middlewares/error.d.ts +2 -0
- package/lib/service/worker/runtime/http/middlewares/error.js +84 -0
- package/lib/service/worker/runtime/http/middlewares/rateLimit.d.ts +6 -0
- package/lib/service/worker/runtime/http/middlewares/rateLimit.js +42 -0
- package/lib/service/worker/runtime/http/middlewares/requestStats.d.ts +17 -0
- package/lib/service/worker/runtime/http/middlewares/requestStats.js +40 -0
- package/lib/service/worker/runtime/http/middlewares/setCookie.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/setCookie.js +52 -0
- package/lib/service/worker/runtime/http/middlewares/settings.d.ts +9 -0
- package/lib/service/worker/runtime/http/middlewares/settings.js +43 -0
- package/lib/service/worker/runtime/http/middlewares/timings.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/timings.js +45 -0
- package/lib/service/worker/runtime/http/middlewares/vary.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/vary.js +52 -0
- package/lib/service/worker/runtime/http/router.d.ts +2 -0
- package/lib/service/worker/runtime/http/router.js +23 -0
- package/lib/service/worker/runtime/http/routes.d.ts +19 -0
- package/lib/service/worker/runtime/http/routes.js +12 -0
- package/lib/service/worker/runtime/method.d.ts +9 -0
- package/lib/service/worker/runtime/method.js +23 -0
- package/lib/service/worker/runtime/statusTrack.d.ts +14 -0
- package/lib/service/worker/runtime/statusTrack.js +37 -0
- package/lib/service/worker/runtime/typings.d.ts +172 -0
- package/lib/service/worker/runtime/typings.js +2 -0
- package/lib/service/worker/runtime/utils/compose.d.ts +5 -0
- package/lib/service/worker/runtime/utils/compose.js +11 -0
- package/lib/service/worker/runtime/utils/context.d.ts +2 -0
- package/lib/service/worker/runtime/utils/context.js +40 -0
- package/lib/service/worker/runtime/utils/diff.d.ts +12 -0
- package/lib/service/worker/runtime/utils/diff.js +21 -0
- package/lib/service/worker/runtime/utils/recorder.d.ts +8 -0
- package/lib/service/worker/runtime/utils/recorder.js +37 -0
- package/lib/service/worker/runtime/utils/toArray.d.ts +1 -0
- package/lib/service/worker/runtime/utils/toArray.js +3 -0
- package/lib/service/worker/runtime/utils/tokenBucket.d.ts +2 -0
- package/lib/service/worker/runtime/utils/tokenBucket.js +16 -0
- package/lib/tracing/LogEvents.d.ts +31 -0
- package/lib/tracing/LogEvents.js +3 -0
- package/lib/tracing/LogFields.d.ts +61 -0
- package/lib/tracing/LogFields.js +3 -0
- package/lib/tracing/Tags.d.ts +79 -0
- package/lib/tracing/Tags.js +7 -0
- package/lib/tracing/UserLandTracer.d.ts +27 -0
- package/lib/tracing/UserLandTracer.js +55 -0
- package/lib/tracing/errorReporting/ErrorReport.d.ts +31 -0
- package/lib/tracing/errorReporting/ErrorReport.js +61 -0
- package/lib/tracing/index.d.ts +9 -0
- package/lib/tracing/index.js +19 -0
- package/lib/tracing/spanReference/SpanReferenceTypes.d.ts +4 -0
- package/lib/tracing/spanReference/SpanReferenceTypes.js +7 -0
- package/lib/tracing/spanReference/createSpanReference.d.ts +3 -0
- package/lib/tracing/spanReference/createSpanReference.js +8 -0
- package/lib/tracing/utils.d.ts +13 -0
- package/lib/tracing/utils.js +40 -0
- package/lib/utils/MineWinsConflictsResolver.d.ts +28 -0
- package/lib/utils/MineWinsConflictsResolver.js +130 -0
- package/lib/utils/app.d.ts +23 -0
- package/lib/utils/app.js +48 -0
- package/lib/utils/appsStaleIfError.d.ts +11 -0
- package/lib/utils/appsStaleIfError.js +63 -0
- package/lib/utils/billingOptions.d.ts +36 -0
- package/lib/utils/billingOptions.js +9 -0
- package/lib/utils/binding.d.ts +13 -0
- package/lib/utils/binding.js +38 -0
- package/lib/utils/cancel.d.ts +3 -0
- package/lib/utils/cancel.js +12 -0
- package/lib/utils/domain.d.ts +1 -0
- package/lib/utils/domain.js +5 -0
- package/lib/utils/error.d.ts +8 -0
- package/lib/utils/error.js +94 -0
- package/lib/utils/index.d.ts +9 -0
- package/lib/utils/index.js +14 -0
- package/lib/utils/message.d.ts +25 -0
- package/lib/utils/message.js +23 -0
- package/lib/utils/renameBy.d.ts +1 -0
- package/lib/utils/renameBy.js +4 -0
- package/lib/utils/retry.d.ts +4 -0
- package/lib/utils/retry.js +32 -0
- package/lib/utils/status.d.ts +1 -0
- package/lib/utils/status.js +11 -0
- package/lib/utils/tenant.d.ts +5 -0
- package/lib/utils/tenant.js +6 -0
- package/lib/utils/throwOnGraphQLErrors.d.ts +2 -0
- package/lib/utils/throwOnGraphQLErrors.js +15 -0
- package/lib/utils/time.d.ts +31 -0
- package/lib/utils/time.js +118 -0
- package/package.json +127 -0
|
@@ -0,0 +1,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,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dataloader_1 = __importDefault(require("dataloader"));
|
|
7
|
+
const ramda_1 = require("ramda");
|
|
8
|
+
const sortByContentAndFrom = (indexedMessages) => ramda_1.sortBy(([_, { content, from }]) => `__from:${from}__content:${content}`, indexedMessages);
|
|
9
|
+
// O(n) counting sort implementation
|
|
10
|
+
const sortByIndex = (indexedTranslations) => indexedTranslations.reduce((acc, [index, data]) => {
|
|
11
|
+
acc[index] = data;
|
|
12
|
+
return acc;
|
|
13
|
+
}, []);
|
|
14
|
+
const indexMessagesByFrom = (messages) => messages.reduce((acc, { from, context, content, behavior }) => {
|
|
15
|
+
const lastIndexed = acc.length && acc[acc.length - 1];
|
|
16
|
+
const formatted = {
|
|
17
|
+
behavior,
|
|
18
|
+
content,
|
|
19
|
+
context,
|
|
20
|
+
};
|
|
21
|
+
if (lastIndexed && lastIndexed.from === from) {
|
|
22
|
+
lastIndexed.messages.push(formatted);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
acc.push({
|
|
26
|
+
from,
|
|
27
|
+
messages: [formatted],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
}, []);
|
|
32
|
+
const toPairs = (x) => x.map((xx, it) => [it, xx]);
|
|
33
|
+
const splitIndex = (indexed) => indexed.reduce((acc, [index, data]) => {
|
|
34
|
+
acc[0].push(index);
|
|
35
|
+
acc[1].push(data);
|
|
36
|
+
return acc;
|
|
37
|
+
}, [[], []]);
|
|
38
|
+
const filterFromEqualsTo = (indexedMessages, to) => indexedMessages.reduce((acc, indexed) => {
|
|
39
|
+
const [index, { content, from }] = indexed;
|
|
40
|
+
if (to === from.toLowerCase() || !content) {
|
|
41
|
+
acc.original.push([index, content]);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
acc.toTranslate.push(indexed);
|
|
45
|
+
}
|
|
46
|
+
return acc;
|
|
47
|
+
}, {
|
|
48
|
+
original: [],
|
|
49
|
+
toTranslate: [],
|
|
50
|
+
});
|
|
51
|
+
const messageToKey = ({ content, context, from }) => `:content:${content}:context:${context}:from:${from}`;
|
|
52
|
+
exports.createMessagesLoader = ({ messagesGraphQL, assets }, to, dependencies) => {
|
|
53
|
+
const loweredTo = to.toLowerCase();
|
|
54
|
+
const messagesDeps = dependencies && assets.getFilteredDependencies('vtex.messages@1.x', dependencies);
|
|
55
|
+
const depTree = messagesDeps && JSON.stringify(messagesDeps);
|
|
56
|
+
return new dataloader_1.default(async (messages) => {
|
|
57
|
+
const indexedMessages = toPairs(messages);
|
|
58
|
+
const { toTranslate, original } = filterFromEqualsTo(indexedMessages, loweredTo);
|
|
59
|
+
// In case we have nothing to translate
|
|
60
|
+
if (toTranslate.length === 0) {
|
|
61
|
+
return messages.map(({ content }) => content);
|
|
62
|
+
}
|
|
63
|
+
const sortedIndexedMessages = sortByContentAndFrom(toTranslate);
|
|
64
|
+
const [originalIndexes, sortedMessages] = splitIndex(sortedIndexedMessages);
|
|
65
|
+
const indexedByFrom = indexMessagesByFrom(sortedMessages);
|
|
66
|
+
const args = { indexedByFrom, to };
|
|
67
|
+
const translations = depTree
|
|
68
|
+
? await messagesGraphQL.translateWithDependencies({ ...args, depTree })
|
|
69
|
+
: await messagesGraphQL.translate(args);
|
|
70
|
+
const indexedTranslations = ramda_1.zip(originalIndexes, translations);
|
|
71
|
+
const allIndexedTranslations = [...indexedTranslations, ...original];
|
|
72
|
+
return sortByIndex(allIndexedTranslations);
|
|
73
|
+
}, {
|
|
74
|
+
batch: true,
|
|
75
|
+
cache: true,
|
|
76
|
+
cacheKeyFn: messageToKey,
|
|
77
|
+
maxBatchSize: 200,
|
|
78
|
+
});
|
|
79
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GraphQLField } from 'graphql';
|
|
2
|
+
import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
3
|
+
export declare class Auth extends SchemaDirectiveVisitor {
|
|
4
|
+
visitFieldDefinition(field: GraphQLField<any, any>): void;
|
|
5
|
+
}
|
|
6
|
+
export declare const authDirectiveTypeDefs = "\ndirective @auth(\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const apollo_server_errors_1 = require("apollo-server-errors");
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const graphql_1 = require("graphql");
|
|
9
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
10
|
+
async function getUserEmail(authToken, vtexIdToken) {
|
|
11
|
+
const url = `vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=${vtexIdToken}`;
|
|
12
|
+
const req = await axios_1.default.request({
|
|
13
|
+
headers: {
|
|
14
|
+
'Accept': 'application/json',
|
|
15
|
+
'Proxy-Authorization': authToken,
|
|
16
|
+
'X-VTEX-Proxy-To': `https://${url}`,
|
|
17
|
+
},
|
|
18
|
+
method: 'get',
|
|
19
|
+
url: `http://${url}`,
|
|
20
|
+
});
|
|
21
|
+
if (!req.data) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return req.data.user;
|
|
25
|
+
}
|
|
26
|
+
async function getUserCanAccessResource(authToken, account, userEmail, productCode, resourceCode) {
|
|
27
|
+
const url = `http://${account}.vtexcommercestable.com.br/api/license-manager/pvt/accounts/${account}/products/${productCode}/logins/${userEmail}/resources/${resourceCode}/granted`;
|
|
28
|
+
const req = await axios_1.default.request({
|
|
29
|
+
headers: {
|
|
30
|
+
'Authorization': authToken,
|
|
31
|
+
},
|
|
32
|
+
method: 'get',
|
|
33
|
+
url,
|
|
34
|
+
});
|
|
35
|
+
return req.data;
|
|
36
|
+
}
|
|
37
|
+
async function auth(ctx, authArgs) {
|
|
38
|
+
const vtexIdToken = ctx.cookies.get('VtexIdclientAutCookie') || ctx.get('VtexIdclientAutCookie');
|
|
39
|
+
if (!vtexIdToken) {
|
|
40
|
+
throw new apollo_server_errors_1.ForbiddenError('VtexIdclientAutCookie not found.');
|
|
41
|
+
}
|
|
42
|
+
const userEmail = await getUserEmail(ctx.vtex.authToken, vtexIdToken);
|
|
43
|
+
if (!userEmail) {
|
|
44
|
+
throw new apollo_server_errors_1.ForbiddenError('Could not find user specified by VtexIdclientAutCookie.');
|
|
45
|
+
}
|
|
46
|
+
const userCanAccessResource = await getUserCanAccessResource(ctx.vtex.authToken, ctx.vtex.account, userEmail, authArgs.productCode, authArgs.resourceCode);
|
|
47
|
+
if (!userCanAccessResource) {
|
|
48
|
+
throw new apollo_server_errors_1.ForbiddenError('User indicated by VtexIdclientAutCookie is not authorized to access the indicated resource.');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function parseArgs(authArgs) {
|
|
52
|
+
if (!authArgs.productCode || !authArgs.resourceCode) {
|
|
53
|
+
throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(productCode: String, resourceCode: String).');
|
|
54
|
+
}
|
|
55
|
+
return authArgs;
|
|
56
|
+
}
|
|
57
|
+
class Auth extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
58
|
+
visitFieldDefinition(field) {
|
|
59
|
+
const { resolve = graphql_1.defaultFieldResolver } = field;
|
|
60
|
+
field.resolve = async (root, args, ctx, info) => {
|
|
61
|
+
const authArgs = parseArgs(this.args);
|
|
62
|
+
await auth(ctx, authArgs);
|
|
63
|
+
return resolve(root, args, ctx, info);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Auth = Auth;
|
|
68
|
+
exports.authDirectiveTypeDefs = `
|
|
69
|
+
directive @auth(
|
|
70
|
+
productCode: String
|
|
71
|
+
resourceCode: String
|
|
72
|
+
) on FIELD_DEFINITION
|
|
73
|
+
`;
|
|
@@ -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,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
5
|
+
class CacheControl extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
6
|
+
visitFieldDefinition(field) {
|
|
7
|
+
const { resolve = graphql_1.defaultFieldResolver } = field;
|
|
8
|
+
const { maxAge: directiveMaxAge, scope: directiveScope, } = this.args;
|
|
9
|
+
field.resolve = (root, args, ctx, info) => {
|
|
10
|
+
const { maxAge, scope, } = ctx.graphql.cacheControl;
|
|
11
|
+
if (Number.isInteger(directiveMaxAge) && directiveMaxAge < maxAge) {
|
|
12
|
+
ctx.graphql.cacheControl.maxAge = directiveMaxAge;
|
|
13
|
+
}
|
|
14
|
+
if (directiveScope === 'PRIVATE') {
|
|
15
|
+
ctx.graphql.cacheControl.scope = 'private';
|
|
16
|
+
}
|
|
17
|
+
else if (directiveScope === 'SEGMENT' && scope === 'public') {
|
|
18
|
+
ctx.graphql.cacheControl.scope = 'segment';
|
|
19
|
+
}
|
|
20
|
+
return resolve(root, args, ctx, info);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.CacheControl = CacheControl;
|
|
25
|
+
exports.cacheControlDirectiveTypeDefs = `
|
|
26
|
+
|
|
27
|
+
enum IOCacheControlScope {
|
|
28
|
+
SEGMENT
|
|
29
|
+
PUBLIC
|
|
30
|
+
PRIVATE
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
directive @cacheControl(
|
|
34
|
+
maxAge: Int
|
|
35
|
+
scope: IOCacheControlScope
|
|
36
|
+
) on FIELD_DEFINITION
|
|
37
|
+
`;
|
|
@@ -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,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
5
|
+
const listeners_1 = require("../../../../listeners");
|
|
6
|
+
let lastLog = process.hrtime();
|
|
7
|
+
const LOG_PERIOD_S = 60;
|
|
8
|
+
const hrtimeToS = (time) => time[0] + (time[1] / 1e9);
|
|
9
|
+
class Deprecated extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
10
|
+
visitArgumentDefinition(argument) {
|
|
11
|
+
this.maybeLogToSplunk({
|
|
12
|
+
description: argument.description,
|
|
13
|
+
name: argument.name,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
visitInputFieldDefinition(field) {
|
|
17
|
+
this.maybeLogToSplunk({
|
|
18
|
+
description: field.description,
|
|
19
|
+
name: field.name,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
visitFieldDefinition(field) {
|
|
23
|
+
const { resolve = graphql_1.defaultFieldResolver, name, type } = field;
|
|
24
|
+
const { reason } = this.args;
|
|
25
|
+
field.resolve = (root, args, ctx, info) => {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
this.maybeLogToSplunk({
|
|
28
|
+
headers: ctx.request.headers,
|
|
29
|
+
name,
|
|
30
|
+
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),
|
|
31
|
+
reason,
|
|
32
|
+
variables: (_c = ctx.graphql.query) === null || _c === void 0 ? void 0 : _c.variables,
|
|
33
|
+
}, ctx.vtex.logger);
|
|
34
|
+
return resolve(root, args, ctx, info);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
maybeLogToSplunk(payload, logger = listeners_1.logger) {
|
|
38
|
+
const now = process.hrtime();
|
|
39
|
+
const timeSinceLastLog = hrtimeToS([
|
|
40
|
+
now[0] - lastLog[0],
|
|
41
|
+
now[1] - lastLog[1],
|
|
42
|
+
]);
|
|
43
|
+
if (timeSinceLastLog > LOG_PERIOD_S) {
|
|
44
|
+
lastLog = now;
|
|
45
|
+
logger.warn({
|
|
46
|
+
message: 'Deprecated field in use',
|
|
47
|
+
...payload,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.Deprecated = Deprecated;
|
|
53
|
+
exports.deprecatedDirectiveTypeDefs = `
|
|
54
|
+
directive @deprecated(
|
|
55
|
+
reason: String = "No longer supported"
|
|
56
|
+
) on
|
|
57
|
+
FIELD_DEFINITION
|
|
58
|
+
| INPUT_FIELD_DEFINITION
|
|
59
|
+
| ARGUMENT_DEFINITION
|
|
60
|
+
| FRAGMENT_DEFINITION
|
|
61
|
+
`;
|
|
@@ -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,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
5
|
+
const __1 = require("../../../../../..");
|
|
6
|
+
class Metric extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
7
|
+
visitFieldDefinition(field) {
|
|
8
|
+
const { resolve = graphql_1.defaultFieldResolver, name: fieldName } = field;
|
|
9
|
+
const { name = `${__1.APP.NAME}-${fieldName}` } = this.args;
|
|
10
|
+
field.resolve = async (root, args, ctx, info) => {
|
|
11
|
+
let failedToResolve = false;
|
|
12
|
+
let result = null;
|
|
13
|
+
let ellapsed = [0, 0];
|
|
14
|
+
try {
|
|
15
|
+
const start = process.hrtime();
|
|
16
|
+
result = await resolve(root, args, ctx, info);
|
|
17
|
+
ellapsed = process.hrtime(start);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
result = error;
|
|
21
|
+
failedToResolve = true;
|
|
22
|
+
}
|
|
23
|
+
ctx.graphql.status = failedToResolve ? 'error' : 'success';
|
|
24
|
+
const payload = {
|
|
25
|
+
[ctx.graphql.status]: 1,
|
|
26
|
+
};
|
|
27
|
+
metrics.batch(`graphql-metric-${name}`, failedToResolve ? undefined : ellapsed, payload);
|
|
28
|
+
if (failedToResolve) {
|
|
29
|
+
throw result;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Metric = Metric;
|
|
36
|
+
exports.metricDirectiveTypeDefs = `
|
|
37
|
+
directive @metric (
|
|
38
|
+
name: String
|
|
39
|
+
) on FIELD_DEFINITION
|
|
40
|
+
`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GraphQLArgument, GraphQLField, GraphQLInputField } from 'graphql';
|
|
2
|
+
import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
3
|
+
export declare class SanitizeDirective extends SchemaDirectiveVisitor {
|
|
4
|
+
visitFieldDefinition(field: GraphQLField<any, any>): void;
|
|
5
|
+
visitInputFieldDefinition(field: GraphQLInputField): void;
|
|
6
|
+
visitArgumentDefinition(argument: GraphQLArgument): void;
|
|
7
|
+
wrapType(field: any): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const sanitizeDirectiveTypeDefs = "\ndirective @sanitize(\n allowHTMLTags: Boolean\n stripIgnoreTag: Boolean\n) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION\n";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
5
|
+
const sanitizedString_1 = require("../typeDefs/sanitizedString");
|
|
6
|
+
class SanitizeDirective extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
7
|
+
visitFieldDefinition(field) {
|
|
8
|
+
this.wrapType(field);
|
|
9
|
+
}
|
|
10
|
+
visitInputFieldDefinition(field) {
|
|
11
|
+
this.wrapType(field);
|
|
12
|
+
}
|
|
13
|
+
visitArgumentDefinition(argument) {
|
|
14
|
+
this.wrapType(argument);
|
|
15
|
+
}
|
|
16
|
+
wrapType(field) {
|
|
17
|
+
const options = this.args;
|
|
18
|
+
if (field.type instanceof graphql_1.GraphQLNonNull && field.type.ofType instanceof graphql_1.GraphQLScalarType) {
|
|
19
|
+
field.type = new graphql_1.GraphQLNonNull(new sanitizedString_1.IOSanitizedStringType(options));
|
|
20
|
+
}
|
|
21
|
+
else if (field.type instanceof graphql_1.GraphQLScalarType) {
|
|
22
|
+
field.type = new sanitizedString_1.IOSanitizedStringType(options);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error('Can not apply @sanitize directive to non-scalar GraphQL type');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.SanitizeDirective = SanitizeDirective;
|
|
30
|
+
exports.sanitizeDirectiveTypeDefs = `
|
|
31
|
+
directive @sanitize(
|
|
32
|
+
allowHTMLTags: Boolean
|
|
33
|
+
stripIgnoreTag: Boolean
|
|
34
|
+
) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION
|
|
35
|
+
`;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GraphQLField } from 'graphql';
|
|
2
|
+
import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
3
|
+
export declare class SettingsDirective extends SchemaDirectiveVisitor {
|
|
4
|
+
visitFieldDefinition(field: GraphQLField<any, any>): void;
|
|
5
|
+
}
|
|
6
|
+
export declare const settingsDirectiveTypeDefs = "\ndirective @settings(\n settingsType: String\n) on FIELD_DEFINITION\n";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
5
|
+
const settings_1 = require("../../../http/middlewares/settings");
|
|
6
|
+
const addSettings = async (settings, ctx) => {
|
|
7
|
+
if (settings === 'pure') {
|
|
8
|
+
return ctx;
|
|
9
|
+
}
|
|
10
|
+
const { clients: { apps, assets } } = ctx;
|
|
11
|
+
const dependenciesSettings = await settings_1.getDependenciesSettings(apps, assets);
|
|
12
|
+
if (!ctx.vtex) {
|
|
13
|
+
ctx.vtex = {};
|
|
14
|
+
}
|
|
15
|
+
ctx.vtex.settings = { ...ctx.vtex.settings, dependenciesSettings };
|
|
16
|
+
};
|
|
17
|
+
class SettingsDirective extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
18
|
+
visitFieldDefinition(field) {
|
|
19
|
+
const { resolve = graphql_1.defaultFieldResolver } = field;
|
|
20
|
+
const { settingsType } = this.args;
|
|
21
|
+
field.resolve = async (root, args, ctx, info) => {
|
|
22
|
+
if (settingsType) {
|
|
23
|
+
await addSettings(settingsType, ctx);
|
|
24
|
+
}
|
|
25
|
+
return resolve(root, args, ctx, info);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.SettingsDirective = SettingsDirective;
|
|
30
|
+
exports.settingsDirectiveTypeDefs = `
|
|
31
|
+
directive @settings(
|
|
32
|
+
settingsType: String
|
|
33
|
+
) on FIELD_DEFINITION
|
|
34
|
+
`;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GraphQLField } from 'graphql';
|
|
2
|
+
import { SchemaDirectiveVisitor } from 'graphql-tools';
|
|
3
|
+
export declare class SmartCacheDirective extends SchemaDirectiveVisitor {
|
|
4
|
+
visitFieldDefinition(field: GraphQLField<any, any>): void;
|
|
5
|
+
}
|
|
6
|
+
export declare const smartCacheDirectiveTypeDefs = "\ndirective @smartcache(\n maxAge: String\n) on FIELD_DEFINITION\n";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
5
|
+
const constants_1 = require("../../../../../../constants");
|
|
6
|
+
const ETAG_CONTROL_HEADER = 'x-vtex-etag-control';
|
|
7
|
+
const DEFAULT_ARGS = {
|
|
8
|
+
maxAge: undefined,
|
|
9
|
+
};
|
|
10
|
+
class SmartCacheDirective extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
11
|
+
visitFieldDefinition(field) {
|
|
12
|
+
const { resolve = graphql_1.defaultFieldResolver } = field;
|
|
13
|
+
const { maxAge } = this.args || DEFAULT_ARGS;
|
|
14
|
+
const maxAgeS = maxAge && constants_1.MAX_AGE[maxAge];
|
|
15
|
+
field.resolve = (root, args, context, info) => {
|
|
16
|
+
if (maxAgeS) {
|
|
17
|
+
context.set(ETAG_CONTROL_HEADER, `public, max-age=${maxAgeS}`);
|
|
18
|
+
}
|
|
19
|
+
context.vtex.recorder = context.state.recorder;
|
|
20
|
+
return resolve(root, args, context, info);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.SmartCacheDirective = SmartCacheDirective;
|
|
25
|
+
exports.smartCacheDirectiveTypeDefs = `
|
|
26
|
+
directive @smartcache(
|
|
27
|
+
maxAge: String
|
|
28
|
+
) on FIELD_DEFINITION
|
|
29
|
+
`;
|