UNPKG

@vtex/api

Version:
92 lines (91 loc) 3.58 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LicenseManager = void 0; const HttpClient_1 = require("../../../HttpClient"); const JanusClient_1 = require("../JanusClient"); __exportStar(require("./types"), exports); __exportStar(require("./utils"), exports); const TWO_MINUTES_S = 2 * 60; const BASE_URL = '/api/license-manager'; const routes = { accountData: () => `${BASE_URL}/account`, resourceAccess: (resourceKey) => `${BASE_URL}/resources/${encodeURIComponent(resourceKey)}/access`, topbarData: () => `${BASE_URL}/site/pvt/newtopbar`, listBindings: (tenant) => `${BASE_URL}/binding/site/${encodeURIComponent(tenant)}`, }; class LicenseManager extends JanusClient_1.JanusClient { getAccountData(VtexIdclientAutCookie, tracingConfig) { const metric = 'lm-account-data'; return this.http.get(routes.accountData(), { forceMaxAge: TWO_MINUTES_S, headers: { VtexIdclientAutCookie, }, inflightKey: HttpClient_1.inflightUrlWithQuery, metric, tracing: { requestSpanNameSuffix: metric, ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing, }, }); } getTopbarData(VtexIdclientAutCookie, tracingConfig) { const metric = 'lm-topbar-data'; return this.http.get(routes.topbarData(), { headers: { VtexIdclientAutCookie, }, metric, tracing: { requestSpanNameSuffix: metric, ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing, }, }); } canAccessResource(VtexIdclientAutCookie, resourceKey, tracingConfig) { const metric = 'lm-resource-access'; return this.http .get(routes.resourceAccess(resourceKey), { headers: { VtexIdclientAutCookie, }, metric, tracing: { requestSpanNameSuffix: metric, ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing, }, }) .then(() => true, () => false); } listBindings(tenant, config) { const metric = 'lm-list-bindings'; return this.http.get(routes.listBindings(tenant), { inflightKey: HttpClient_1.inflightUrlWithQuery, memoizeable: true, metric, headers: { VtexIdclientAutCookie: this.context.authToken, }, ...config, tracing: { requestSpanNameSuffix: metric, ...config === null || config === void 0 ? void 0 : config.tracing, }, }); } } exports.LicenseManager = LicenseManager;