UNPKG

@sap/subaccount-destination-service-provider

Version:

Provide service consumption of SAP subaccount services

82 lines 3.68 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbapBaseRetriever = exports.DESTINATION_PATH = void 0; const lodash_1 = require("lodash"); const service_provider_apis_1 = require("@sap/service-provider-apis"); const systemUtils_1 = require("../../utils/systemUtils"); const messages_1 = require("../../i18n/messages"); exports.DESTINATION_PATH = "/destinations"; class AbapBaseRetriever { constructor() { this.logger = service_provider_apis_1.DefaultLogger; this.proxy = (0, lodash_1.get)(process, "env.http_proxy"); this.h2oUrl = (0, lodash_1.get)(process, "env.H2O_URL"); } executeRetrieveDestinationsRequest() { return __awaiter(this, void 0, void 0, function* () { const urlPath = systemUtils_1.API_LIST_DESTINATION_PATH; const basCredentialsHeader = yield this.getBasCredentialsHeader(); const responseBody = yield service_provider_apis_1.Connectivity.sendRequest(this.h2oUrl, urlPath, this.proxy, true, basCredentialsHeader); return responseBody; }); } filterDestination(destinationConfiguration, filter) { let passFilter = true; const webIDEEnabled = (0, lodash_1.get)(destinationConfiguration, "WebIDEEnabled", ""); if (webIDEEnabled != "true") { return false; } if (filter) { filter.forEach((filterValues, key) => { const destinationValues = (0, lodash_1.get)(destinationConfiguration, key, "").trim().replace(" ", "").split(","); if ((0, lodash_1.intersection)(filterValues, destinationValues).length == 0) { passFilter = false; return; } }); } return passFilter; } getBasCredentialsHeader(credentials) { return __awaiter(this, void 0, void 0, function* () { const headers = {}; if (credentials) { headers.Authorization = credentials.getEncodedBasicAuthentication(); } yield this.addJwtHeaderForLocalUse(headers); return headers; }); } addJwtHeaderForLocalUse(headers) { return __awaiter(this, void 0, void 0, function* () { const isAppStudio = this.isAppStudio(); if (!isAppStudio) { const h2oJwt = process.env.H2O_JWT; if (h2oJwt) { headers["x-approuter-authorization"] = `Bearer ${h2oJwt}`; } else { throw new Error(messages_1.messages.MISSING_ENV("H2O_JWT")); } } }); } isAppStudio() { const wsBaseUrl = process.env.WS_BASE_URL; if ((0, lodash_1.isUndefined)(wsBaseUrl)) { return false; } return !(0, lodash_1.isEmpty)(wsBaseUrl); } } exports.AbapBaseRetriever = AbapBaseRetriever; //# sourceMappingURL=abapBaseRetriever.js.map