UNPKG

@vtex/api

Version:
40 lines (39 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPubContextMiddleware = exports.createPvtContextMiddleware = void 0; const querystring_1 = require("querystring"); const constants_1 = require("../../../../../constants"); const context_1 = require("../../utils/context"); const createPvtContextMiddleware = (routeId, { smartcache }) => { return async function pvtContext(ctx, next) { const { params, request: { header }, } = ctx; ctx.vtex = { ...(0, context_1.prepareHandlerCtx)(header, ctx.tracing), ...(smartcache && { recorder: ctx.state.recorder }), route: { id: routeId, params, type: 'private', }, }; await next(); }; }; exports.createPvtContextMiddleware = createPvtContextMiddleware; const createPubContextMiddleware = (routeId, { smartcache }) => { return async function pubContext(ctx, next) { const { request: { header }, } = ctx; ctx.vtex = { ...(0, context_1.prepareHandlerCtx)(header, ctx.tracing), ...(smartcache && { recorder: ctx.state.recorder }), route: { declarer: header[constants_1.HeaderKeys.COLOSSUS_ROUTE_DECLARER], id: routeId, params: (0, querystring_1.parse)(header[constants_1.HeaderKeys.COLOSSUS_PARAMS]), type: 'public', }, }; await next(); }; }; exports.createPubContextMiddleware = createPubContextMiddleware;