UNPKG

vtex

Version:

The platform for e-commerce apps

25 lines (24 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupGlobalMetrics = void 0; const api_1 = require("@vtex/api"); /** * `@vtex/api`'s HttpClient middlewares reference a *global* `metrics` accumulator. * `singleFlightMiddleware`, for instance, calls `metrics.addOnFlushMetric` for every * request that sets an `inflightKey` — which includes `Apps.listApps`, used by * `vtex list` / `vtex ls`. * * Up to `@vtex/api` 3.x that global was installed as a side effect of importing the * package: `lib/service/Runtime.js` assigned it at module load. Since v6/v7 it is only * assigned inside `startApp()`, which boots the IO service runtime and therefore never * runs in a CLI. Toolbelt must install it itself, otherwise those requests fail with * `ReferenceError: metrics is not defined`. * * Idempotent: never replaces an accumulator that is already in place. */ const setupGlobalMetrics = () => { if (!global.metrics) { global.metrics = new api_1.MetricsAccumulator(); } }; exports.setupGlobalMetrics = setupGlobalMetrics;