UNPKG

@sap/subaccount-destination-service-provider

Version:

Provide service consumption of SAP subaccount services

124 lines 5.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBasHeader = exports.buildServiceCommonResponse = exports.getProxyType = exports.getSystemType = exports.SubaccountProviderUtils = exports.SubaccountAbapCatalogServiceUrl = exports.APPLICATION_XML_HEADER = exports.ANNOTATIONS_SUFFIX = exports.V4_RECOMMENDED_SERVICES_PATH = exports.V4_SERVICES_PATH = exports.ODATA_V4_CATALOG_SERVICES = exports.V2_RECOMMENDED_SERVICES_PATH = exports.V2_SERVICES_PATH = exports.ODATA_V2_CATALOG_SERVICES = exports.API_LIST_DESTINATION_PATH = void 0; const lodash_1 = require("lodash"); const vkbeautify = require("vkbeautify"); const service_provider_apis_1 = require("@sap/service-provider-apis"); const messages_1 = require("../i18n/messages"); const bas_sdk_1 = require("@sap/bas-sdk"); exports.API_LIST_DESTINATION_PATH = "/api/listDestinations"; exports.ODATA_V2_CATALOG_SERVICES = "/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/"; exports.V2_SERVICES_PATH = "ServiceCollection"; exports.V2_RECOMMENDED_SERVICES_PATH = "RecommendedServiceCollection"; exports.ODATA_V4_CATALOG_SERVICES = "/sap/opu/odata4/iwfnd/config/default/iwfnd/catalog/0002/"; exports.V4_SERVICES_PATH = "ServiceGroups?$expand=DefaultSystem($expand=Services)"; exports.V4_RECOMMENDED_SERVICES_PATH = "ServiceGroups?$expand=DefaultSystem($expand=RecommendedServices)"; exports.ANNOTATIONS_SUFFIX = "/Annotations"; exports.APPLICATION_XML_HEADER = "application/xml"; const CATALOG_USAGE = "odata_abap"; const SERVICE_USAGE = "odata_gen"; const FULL_URL = "full_url"; exports.SubaccountAbapCatalogServiceUrl = { v2New: `${exports.ODATA_V2_CATALOG_SERVICES}${exports.V2_RECOMMENDED_SERVICES_PATH}`, v2Old: `${exports.ODATA_V2_CATALOG_SERVICES}${exports.V2_SERVICES_PATH}`, v4New: `${exports.ODATA_V4_CATALOG_SERVICES}${exports.V4_RECOMMENDED_SERVICES_PATH}`, v4Old: `${exports.ODATA_V4_CATALOG_SERVICES}${exports.V4_SERVICES_PATH}`, getV2AnnotationUrl(serviceId) { return `${exports.SubaccountAbapCatalogServiceUrl.v2Old}('${serviceId}')${exports.ANNOTATIONS_SUFFIX}`; }, }; exports.SubaccountProviderUtils = { filterSystem(destinationList, dataType, WebIdeBasEnabled = true, proxyType) { if (dataType !== service_provider_apis_1.DataType.CATALOG && dataType !== service_provider_apis_1.DataType.SERVICE_EP && dataType !== service_provider_apis_1.DataType.SERVICE_EP_FULL_URL) { throw new service_provider_apis_1.ServiceProviderError(service_provider_apis_1.ServiceProviderErrorCode.RETRIEVE_DATA, messages_1.messages.ERROR_FAILED_UNSUPPORTED_SYSTEM_TYPE()); } const filteredDestinationList = []; destinationList.forEach((destinationValue) => { if (filterEvaluation(destinationValue, dataType, WebIdeBasEnabled, proxyType)) { filteredDestinationList.push(destinationValue); } }); return filteredDestinationList; }, }; function filterEvaluation(destinationItem, dataType, WebIdeBasEnabled = true, proxyType) { if (WebIdeBasEnabled) { const destWebIDEEnabled = (0, lodash_1.get)(destinationItem, "WebIDEEnabled", ""); if (!destWebIDEEnabled || destWebIDEEnabled !== "true") { return false; } } const destSystemType = getSystemType(destinationItem); if (destSystemType !== dataType) { return false; } if (proxyType) { const destProxyType = (0, lodash_1.get)(destinationItem, "ProxyType", ""); if (getProxyType(destProxyType) !== proxyType) { return false; } } return true; } function getSystemType(destinationConfiguration) { let dataType = service_provider_apis_1.DataType.UNKNOWN; const webIDEUsages = (0, lodash_1.get)(destinationConfiguration, "WebIDEUsage", ""); const webIDEAdditionalData = (0, lodash_1.get)(destinationConfiguration, "WebIDEAdditionalData", ""); if (webIDEUsages.includes(CATALOG_USAGE)) { dataType = service_provider_apis_1.DataType.CATALOG; } else { if (webIDEUsages.includes(SERVICE_USAGE) && webIDEAdditionalData.includes(FULL_URL)) { dataType = service_provider_apis_1.DataType.SERVICE_EP_FULL_URL; } else { if (webIDEUsages.includes(SERVICE_USAGE) && !webIDEAdditionalData.includes(FULL_URL)) { dataType = service_provider_apis_1.DataType.SERVICE_EP; } } } return dataType; } exports.getSystemType = getSystemType; function getProxyType(destinationProxyType) { let proxyType = service_provider_apis_1.ProxyType.UNKNOWN; switch (destinationProxyType) { case "Internet": { proxyType = service_provider_apis_1.ProxyType.INTERNET; break; } case "OnPremise": { proxyType = service_provider_apis_1.ProxyType.ONPREMISE; break; } } return proxyType; } exports.getProxyType = getProxyType; function buildServiceCommonResponse(encoding, responseBody) { switch (encoding) { case service_provider_apis_1.EncodingMode.XML: return { data: vkbeautify.xml(responseBody), encoding: encoding, }; case service_provider_apis_1.EncodingMode.JSON: return { data: vkbeautify.json(responseBody), encoding: encoding, }; } } exports.buildServiceCommonResponse = buildServiceCommonResponse; function createBasHeader(credentials) { let headers = {}; if (credentials) { headers.Authorization = credentials.getEncodedBasicAuthentication(); } headers = bas_sdk_1.core.addJwtHeader(headers); return headers; } exports.createBasHeader = createBasHeader; //# sourceMappingURL=systemUtils.js.map