@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,79 @@
|
|
|
1
|
+
import { BillingOptions } from './utils/billingOptions';
|
|
2
|
+
export interface Policy {
|
|
3
|
+
name: string;
|
|
4
|
+
attrs?: {
|
|
5
|
+
[name: string]: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
interface PublicAppManifest {
|
|
9
|
+
vendor: string;
|
|
10
|
+
name: string;
|
|
11
|
+
version: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
mustUpdateAt?: string;
|
|
15
|
+
builders: {
|
|
16
|
+
[name: string]: string;
|
|
17
|
+
};
|
|
18
|
+
categories?: string[];
|
|
19
|
+
dependencies?: {
|
|
20
|
+
[name: string]: string;
|
|
21
|
+
};
|
|
22
|
+
peerDependencies?: {
|
|
23
|
+
[name: string]: string;
|
|
24
|
+
};
|
|
25
|
+
settingsSchema?: any;
|
|
26
|
+
registries?: string[];
|
|
27
|
+
credentialType?: string;
|
|
28
|
+
policies?: Policy[];
|
|
29
|
+
billingOptions?: BillingOptions;
|
|
30
|
+
}
|
|
31
|
+
export interface AppManifest extends PublicAppManifest {
|
|
32
|
+
[internal: string]: any;
|
|
33
|
+
_resolvedDependencies?: {
|
|
34
|
+
[name: string]: string[];
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface FileListItem {
|
|
38
|
+
path: string;
|
|
39
|
+
hash: string;
|
|
40
|
+
}
|
|
41
|
+
export interface AppFilesList {
|
|
42
|
+
data: FileListItem[];
|
|
43
|
+
}
|
|
44
|
+
export interface BucketMetadata {
|
|
45
|
+
state: string;
|
|
46
|
+
lastModified: string;
|
|
47
|
+
hash: string;
|
|
48
|
+
}
|
|
49
|
+
export interface AppBundleResponse {
|
|
50
|
+
message: string;
|
|
51
|
+
id: string;
|
|
52
|
+
}
|
|
53
|
+
export declare type AppBundlePublished = AppBundleResponse & {
|
|
54
|
+
bundleSize?: number;
|
|
55
|
+
};
|
|
56
|
+
export declare type AppBundleLinked = AppBundleResponse & {
|
|
57
|
+
bundleSize?: number;
|
|
58
|
+
};
|
|
59
|
+
export declare type AppState = 'stable' | 'releaseCandidate';
|
|
60
|
+
export interface HouseKeeperState {
|
|
61
|
+
infra: string[];
|
|
62
|
+
edition: string[];
|
|
63
|
+
runtimes: string[];
|
|
64
|
+
apps: Array<{
|
|
65
|
+
id: string;
|
|
66
|
+
source: string;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
69
|
+
export interface HouseKeeperUpdates extends HouseKeeperState {
|
|
70
|
+
editionApps?: {
|
|
71
|
+
install?: string[];
|
|
72
|
+
uninstall?: string[];
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export interface HousekeeperStatesAndUpdates {
|
|
76
|
+
state: HouseKeeperState;
|
|
77
|
+
updates: HouseKeeperUpdates;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
package/lib/responses.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 cluster_1 = __importDefault(require("cluster"));
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const loaders_1 = require("./loaders");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
const master_1 = require("./master");
|
|
11
|
+
const worker_1 = require("./worker");
|
|
12
|
+
exports.startApp = () => {
|
|
13
|
+
const serviceJSON = loaders_1.getServiceJSON();
|
|
14
|
+
try {
|
|
15
|
+
// if it is a master process then call setting up worker process
|
|
16
|
+
if (cluster_1.default.isMaster) {
|
|
17
|
+
master_1.startMaster(serviceJSON);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// to setup server configurations and share port address for incoming requests
|
|
21
|
+
worker_1.startWorker(serviceJSON).listen(constants_1.HTTP_SERVER_PORT);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
logger_1.logOnceToDevConsole(err.stack || err.message, logger_1.LogLevel.Error);
|
|
26
|
+
process.exit(2);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var loaders_2 = require("./loaders");
|
|
30
|
+
exports.appPath = loaders_2.appPath;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IOClients } from '../clients/IOClients';
|
|
2
|
+
import { Service } from './worker/runtime/Service';
|
|
3
|
+
import { ParamsContext, RecorderState, ServiceJSON } from './worker/runtime/typings';
|
|
4
|
+
export declare const appPath: string;
|
|
5
|
+
export declare const bundlePath: string;
|
|
6
|
+
export declare const serviceJsonPath: string;
|
|
7
|
+
export declare const getServiceJSON: () => ServiceJSON;
|
|
8
|
+
export declare const getService: () => Service<IOClients, RecorderState, ParamsContext>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const os_1 = require("os");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const IOClients_1 = require("../clients/IOClients");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
exports.appPath = path_1.join(process.cwd(), './service/src/node/');
|
|
8
|
+
exports.bundlePath = path_1.join(exports.appPath, 'index');
|
|
9
|
+
exports.serviceJsonPath = path_1.join(process.cwd(), './service/service.json');
|
|
10
|
+
const getWorkers = (workers) => {
|
|
11
|
+
// We need to have only one worker while linking so the debugger
|
|
12
|
+
// works properly
|
|
13
|
+
if (constants_1.LINKED) {
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
// If user didn't set workers property, let's use the cpu count
|
|
17
|
+
const workersFromUser = workers && Number.isInteger(workers) ? workers : os_1.cpus().length;
|
|
18
|
+
// never spawns more than MAX_WORKERS
|
|
19
|
+
return Math.min(workersFromUser, constants_1.MAX_WORKERS);
|
|
20
|
+
};
|
|
21
|
+
exports.getServiceJSON = () => {
|
|
22
|
+
const service = require(exports.serviceJsonPath);
|
|
23
|
+
return {
|
|
24
|
+
...service,
|
|
25
|
+
workers: getWorkers(service.workers),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const defaultClients = {
|
|
29
|
+
options: {
|
|
30
|
+
messages: {
|
|
31
|
+
concurrency: 10,
|
|
32
|
+
retries: 2,
|
|
33
|
+
timeout: 1000,
|
|
34
|
+
},
|
|
35
|
+
messagesGraphQL: {
|
|
36
|
+
concurrency: 10,
|
|
37
|
+
retries: 2,
|
|
38
|
+
timeout: 1000,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
exports.getService = () => {
|
|
43
|
+
var _a;
|
|
44
|
+
const { default: service } = require(exports.bundlePath);
|
|
45
|
+
const { config: { clients } } = service;
|
|
46
|
+
service.config.clients = {
|
|
47
|
+
implementation: (_a = clients === null || clients === void 0 ? void 0 : clients.implementation) !== null && _a !== void 0 ? _a : IOClients_1.IOClients,
|
|
48
|
+
options: {
|
|
49
|
+
...defaultClients.options,
|
|
50
|
+
...clients === null || clients === void 0 ? void 0 : clients.options,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
return service;
|
|
54
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogLevel } from './logger';
|
|
2
|
+
export interface LogMessage {
|
|
3
|
+
cmd: typeof LOG_ONCE;
|
|
4
|
+
message: string;
|
|
5
|
+
level: LogLevel;
|
|
6
|
+
}
|
|
7
|
+
export declare const LOG_ONCE = "logOnce";
|
|
8
|
+
export declare const isLog: (message: any) => message is LogMessage;
|
|
9
|
+
export declare const log: (message: any, level: LogLevel) => void;
|
|
10
|
+
export declare const logOnceToDevConsole: (message: any, level: LogLevel) => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cluster_1 = require("cluster");
|
|
4
|
+
const caches_1 = require("../../caches");
|
|
5
|
+
const history = new caches_1.LRUCache({
|
|
6
|
+
max: 42,
|
|
7
|
+
});
|
|
8
|
+
exports.LOG_ONCE = 'logOnce';
|
|
9
|
+
exports.isLog = (message) => (message === null || message === void 0 ? void 0 : message.cmd) === exports.LOG_ONCE;
|
|
10
|
+
exports.log = (message, level) => {
|
|
11
|
+
const logger = console[level];
|
|
12
|
+
if (typeof logger === 'function') {
|
|
13
|
+
logger(message);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
// Since we are now using clusters, if we simply console.log something,
|
|
17
|
+
// it may overwhelm the programmer's console with lots of repeated info.
|
|
18
|
+
// This function should be used when you want to warn about something
|
|
19
|
+
// only once
|
|
20
|
+
exports.logOnceToDevConsole = (message, level) => {
|
|
21
|
+
const strigified = JSON.stringify(message);
|
|
22
|
+
if (!history.has(strigified)) {
|
|
23
|
+
history.set(strigified, true);
|
|
24
|
+
if (cluster_1.isMaster) {
|
|
25
|
+
exports.log(message, level);
|
|
26
|
+
}
|
|
27
|
+
else if (cluster_1.isWorker && process.send) {
|
|
28
|
+
const logMessage = {
|
|
29
|
+
cmd: exports.LOG_ONCE,
|
|
30
|
+
level,
|
|
31
|
+
message,
|
|
32
|
+
};
|
|
33
|
+
process.send(logMessage);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IUserLandTracer } from '../../tracing';
|
|
2
|
+
import { IOContext } from '../worker/runtime/typings';
|
|
3
|
+
export interface LoggerTracingContext {
|
|
4
|
+
requestTracer: IUserLandTracer;
|
|
5
|
+
}
|
|
6
|
+
export declare enum LogLevel {
|
|
7
|
+
Debug = "debug",
|
|
8
|
+
Info = "info",
|
|
9
|
+
Warn = "warn",
|
|
10
|
+
Error = "error"
|
|
11
|
+
}
|
|
12
|
+
interface LoggerContext extends Pick<IOContext, 'account' | 'workspace' | 'requestId' | 'operationId' | 'production'> {
|
|
13
|
+
tracer?: IOContext['tracer'];
|
|
14
|
+
}
|
|
15
|
+
export declare class Logger {
|
|
16
|
+
private account;
|
|
17
|
+
private workspace;
|
|
18
|
+
private operationId;
|
|
19
|
+
private requestId;
|
|
20
|
+
private production;
|
|
21
|
+
private tracingState?;
|
|
22
|
+
constructor(ctx: LoggerContext);
|
|
23
|
+
debug: (message: any) => void;
|
|
24
|
+
info: (message: any) => void;
|
|
25
|
+
warn: (warning: any) => void;
|
|
26
|
+
error: (error: any) => void;
|
|
27
|
+
log: (message: any, level: LogLevel) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Logs splunk query so the developer can search for the errors in splunk.
|
|
30
|
+
* This function runs only once in the lifetime of the Logger class so we
|
|
31
|
+
* don't mess up with the developer's terminal
|
|
32
|
+
*/
|
|
33
|
+
private logSplunkQuery;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../../constants");
|
|
4
|
+
const error_1 = require("../../utils/error");
|
|
5
|
+
const console_1 = require("./console");
|
|
6
|
+
const linked = !!process.env.VTEX_APP_LINK;
|
|
7
|
+
const app = constants_1.APP.ID;
|
|
8
|
+
const EMPTY_MESSAGE = 'Logger.log was called with null or undefined message';
|
|
9
|
+
var LogLevel;
|
|
10
|
+
(function (LogLevel) {
|
|
11
|
+
LogLevel["Debug"] = "debug";
|
|
12
|
+
LogLevel["Info"] = "info";
|
|
13
|
+
LogLevel["Warn"] = "warn";
|
|
14
|
+
LogLevel["Error"] = "error";
|
|
15
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
16
|
+
class Logger {
|
|
17
|
+
constructor(ctx) {
|
|
18
|
+
this.debug = (message) => this.log(message, LogLevel.Debug);
|
|
19
|
+
this.info = (message) => this.log(message, LogLevel.Info);
|
|
20
|
+
this.warn = (warning) => this.log(warning, LogLevel.Warn);
|
|
21
|
+
this.error = (error) => this.log(error, LogLevel.Error);
|
|
22
|
+
this.log = (message, level) => {
|
|
23
|
+
var _a;
|
|
24
|
+
const data = message ? error_1.cleanError(message) : EMPTY_MESSAGE;
|
|
25
|
+
/* tslint:disable:object-literal-sort-keys */
|
|
26
|
+
const inflatedLog = {
|
|
27
|
+
__VTEX_IO_LOG: true,
|
|
28
|
+
level,
|
|
29
|
+
app,
|
|
30
|
+
account: this.account,
|
|
31
|
+
workspace: this.workspace,
|
|
32
|
+
production: this.production,
|
|
33
|
+
data,
|
|
34
|
+
operationId: this.operationId,
|
|
35
|
+
requestId: this.requestId,
|
|
36
|
+
...(((_a = this.tracingState) === null || _a === void 0 ? void 0 : _a.isTraceSampled) ? { traceId: this.tracingState.traceId } : null),
|
|
37
|
+
};
|
|
38
|
+
// Mark third-party apps logs to send to skidder
|
|
39
|
+
if (constants_1.APP.IS_THIRD_PARTY()) {
|
|
40
|
+
Object.assign(inflatedLog, {
|
|
41
|
+
__SKIDDER_TOPIC_1: `skidder.vendor.${constants_1.APP.VENDOR}`,
|
|
42
|
+
__SKIDDER_TOPIC_2: `skidder.app.${constants_1.APP.VENDOR}.${constants_1.APP.NAME}`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
console.log(JSON.stringify(inflatedLog));
|
|
46
|
+
// Warn the developer how to retrieve the error in splunk
|
|
47
|
+
this.logSplunkQuery();
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Logs splunk query so the developer can search for the errors in splunk.
|
|
51
|
+
* This function runs only once in the lifetime of the Logger class so we
|
|
52
|
+
* don't mess up with the developer's terminal
|
|
53
|
+
*/
|
|
54
|
+
this.logSplunkQuery = () => {
|
|
55
|
+
if (linked) {
|
|
56
|
+
const message = `Try this query at Splunk to retrieve error log: 'index=io_vtex_logs app="${app}" account=${this.account} workspace=${this.workspace} level=error OR level=warn'`;
|
|
57
|
+
console_1.logOnceToDevConsole(message, LogLevel.Info);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this.account = ctx.account;
|
|
61
|
+
this.workspace = ctx.workspace;
|
|
62
|
+
this.requestId = ctx.requestId;
|
|
63
|
+
this.operationId = ctx.operationId;
|
|
64
|
+
this.production = ctx.production;
|
|
65
|
+
if (ctx.tracer) {
|
|
66
|
+
this.tracingState = {
|
|
67
|
+
isTraceSampled: ctx.tracer.isTraceSampled,
|
|
68
|
+
traceId: ctx.tracer.traceId,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
interface ProcessEnv {
|
|
3
|
+
appName: string;
|
|
4
|
+
appVersion: string;
|
|
5
|
+
region: string;
|
|
6
|
+
vendor: string;
|
|
7
|
+
production: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface Key {
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
interface Metric {
|
|
13
|
+
Count: number;
|
|
14
|
+
Data: {
|
|
15
|
+
key: Key;
|
|
16
|
+
processEnv: ProcessEnv;
|
|
17
|
+
summary: NumericSummary | NodeJS.MemoryUsage | NodeJS.CpuUsage;
|
|
18
|
+
};
|
|
19
|
+
Max: number;
|
|
20
|
+
Min: number;
|
|
21
|
+
Name: string;
|
|
22
|
+
Sum: number;
|
|
23
|
+
Timestamp: number;
|
|
24
|
+
Unit: string;
|
|
25
|
+
}
|
|
26
|
+
interface NumericSummary {
|
|
27
|
+
count: number;
|
|
28
|
+
max: number;
|
|
29
|
+
median: number;
|
|
30
|
+
min: number;
|
|
31
|
+
percentile95: number;
|
|
32
|
+
percentile99: number;
|
|
33
|
+
sum: number;
|
|
34
|
+
}
|
|
35
|
+
export declare class MetricsLogger {
|
|
36
|
+
add: (key: Key, value: number) => void;
|
|
37
|
+
getSummaries: () => Metric[];
|
|
38
|
+
constructor();
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
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 fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
|
|
7
|
+
const ramda_1 = require("ramda");
|
|
8
|
+
const stats_lite_1 = require("stats-lite");
|
|
9
|
+
const constants_1 = require("../../constants");
|
|
10
|
+
const diff_1 = require("../worker/runtime/utils/diff");
|
|
11
|
+
const runtimeBaseDefaultMetricNames = ['routeStats'];
|
|
12
|
+
const runtimeNodeDefaultMetricNames = {
|
|
13
|
+
cpuUsage: 'cpuUsage',
|
|
14
|
+
memoryUsage: 'memoryUsage',
|
|
15
|
+
};
|
|
16
|
+
const invalidMetricNames = runtimeBaseDefaultMetricNames.concat(Object.values(runtimeNodeDefaultMetricNames));
|
|
17
|
+
class MetricsLogger {
|
|
18
|
+
constructor() {
|
|
19
|
+
//////////////////////
|
|
20
|
+
// private attributes
|
|
21
|
+
//////////////////////
|
|
22
|
+
let samples = {};
|
|
23
|
+
let lastCpu = diff_1.cpuSnapshot();
|
|
24
|
+
//////////////////////
|
|
25
|
+
// private methods definitions
|
|
26
|
+
//////////////////////
|
|
27
|
+
const summaries = ramda_1.compose(ramda_1.reject(ramda_1.isNil), ramda_1.values, ramda_1.mapObjIndexed(getSummary));
|
|
28
|
+
function getDefaultStoredashProperties() {
|
|
29
|
+
return {
|
|
30
|
+
Count: 1,
|
|
31
|
+
Max: 0,
|
|
32
|
+
Min: 0,
|
|
33
|
+
Name: 'runtime',
|
|
34
|
+
Sum: 0,
|
|
35
|
+
Timestamp: (new Date()).getTime(),
|
|
36
|
+
Unit: '',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getProcessEnv() {
|
|
40
|
+
return {
|
|
41
|
+
appName: process.env.VTEX_APP_NAME || '',
|
|
42
|
+
appVersion: process.env.VTEX_APP_VERSION || '',
|
|
43
|
+
production: constants_1.PRODUCTION,
|
|
44
|
+
region: process.env.VTEX_REGION || '',
|
|
45
|
+
vendor: process.env.VTEX_APP_VENDOR || '',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function getCpuUsage() {
|
|
49
|
+
const cpu = diff_1.cpuSnapshot();
|
|
50
|
+
const cpuDiff = diff_1.snapshotDiff(cpu, lastCpu);
|
|
51
|
+
lastCpu = cpu;
|
|
52
|
+
const metric = {
|
|
53
|
+
Data: {
|
|
54
|
+
key: {
|
|
55
|
+
name: runtimeNodeDefaultMetricNames.cpuUsage,
|
|
56
|
+
},
|
|
57
|
+
processEnv: getProcessEnv(),
|
|
58
|
+
summary: cpuDiff,
|
|
59
|
+
},
|
|
60
|
+
...getDefaultStoredashProperties(),
|
|
61
|
+
};
|
|
62
|
+
return metric;
|
|
63
|
+
}
|
|
64
|
+
function getMemoryUsage() {
|
|
65
|
+
const metric = {
|
|
66
|
+
Data: {
|
|
67
|
+
key: {
|
|
68
|
+
name: runtimeNodeDefaultMetricNames.memoryUsage,
|
|
69
|
+
},
|
|
70
|
+
processEnv: getProcessEnv(),
|
|
71
|
+
summary: process.memoryUsage(),
|
|
72
|
+
},
|
|
73
|
+
...getDefaultStoredashProperties(),
|
|
74
|
+
};
|
|
75
|
+
return metric;
|
|
76
|
+
}
|
|
77
|
+
function getRuntimeSummaries() {
|
|
78
|
+
return [getCpuUsage(), getMemoryUsage()];
|
|
79
|
+
}
|
|
80
|
+
function getSummary(vals, strKey) {
|
|
81
|
+
if (strKey in samples) {
|
|
82
|
+
const summary = getNumericSummary(vals);
|
|
83
|
+
const keyObj = JSON.parse(strKey);
|
|
84
|
+
const metric = {
|
|
85
|
+
Data: {
|
|
86
|
+
key: keyObj,
|
|
87
|
+
processEnv: getProcessEnv(),
|
|
88
|
+
summary,
|
|
89
|
+
},
|
|
90
|
+
...getDefaultStoredashProperties(),
|
|
91
|
+
};
|
|
92
|
+
return metric;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
// TODO: create some kind of alert/log if metric is not valid
|
|
97
|
+
function validKey(key) {
|
|
98
|
+
if (!('name' in key)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (invalidMetricNames.includes(key.name)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
fast_json_stable_stringify_1.default(key);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
function getStrKey(key) {
|
|
113
|
+
return fast_json_stable_stringify_1.default(key);
|
|
114
|
+
}
|
|
115
|
+
function getNumericSummary(vals) {
|
|
116
|
+
return {
|
|
117
|
+
count: vals.length,
|
|
118
|
+
max: Math.max(...vals),
|
|
119
|
+
median: stats_lite_1.median(vals),
|
|
120
|
+
min: Math.min(...vals),
|
|
121
|
+
percentile95: stats_lite_1.percentile(vals, 0.95),
|
|
122
|
+
percentile99: stats_lite_1.percentile(vals, 0.99),
|
|
123
|
+
sum: stats_lite_1.sum(vals),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//////////////////////
|
|
127
|
+
// public methods definitions
|
|
128
|
+
//////////////////////
|
|
129
|
+
this.add = (key, value) => {
|
|
130
|
+
if (validKey(key)) {
|
|
131
|
+
const strKey = getStrKey(key);
|
|
132
|
+
if (!(strKey in samples)) {
|
|
133
|
+
samples[strKey] = [];
|
|
134
|
+
}
|
|
135
|
+
samples[strKey].push(value);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
this.getSummaries = () => {
|
|
139
|
+
const appSummaries = summaries(samples);
|
|
140
|
+
samples = {};
|
|
141
|
+
const runtimeSummaries = getRuntimeSummaries();
|
|
142
|
+
return runtimeSummaries.concat(appSummaries);
|
|
143
|
+
};
|
|
144
|
+
//////////////////////
|
|
145
|
+
// real constructor
|
|
146
|
+
//////////////////////
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.MetricsLogger = MetricsLogger;
|