UNPKG

@sap/subaccount-destination-service-provider

Version:

Provide service consumption of SAP subaccount services

72 lines 4.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DestinationToProviderSystem = DestinationToProviderSystem; exports.DestinationToProviderSystemBusiness = DestinationToProviderSystemBusiness; exports.ServiceResponseToService = ServiceResponseToService; exports.AnnotationResponseToAnnotations = AnnotationResponseToAnnotations; exports.BusinessResponseToObject = BusinessResponseToObject; const service_provider_apis_1 = require("@sap/service-provider-apis"); const subaccountDestinationProviderSystem_1 = require("../providers/subaccountDestinationProviderSystem"); const systemUtils_1 = require("../../utils/systemUtils"); const subaccountDestinationProviderSystemBusiness_1 = require("../providers/subaccountDestinationProviderSystemBusiness"); const logger = service_provider_apis_1.DefaultLogger; function DestinationToProviderSystem(responseDestination, retriever) { return new subaccountDestinationProviderSystem_1.SubaccountDestinationProviderSystem(responseDestination.name, responseDestination.host, (0, systemUtils_1.getSystemType)(responseDestination), (0, systemUtils_1.getProxyType)(responseDestination.proxyType), responseDestination.credentials.authentication, retriever, responseDestination["product.name"] || responseDestination.productName, responseDestination.description, responseDestination.sapClient); } function DestinationToProviderSystemBusiness(responseDestination, retriever) { return new subaccountDestinationProviderSystemBusiness_1.SubaccountDestinationProviderSystemBusiness(responseDestination.name, responseDestination.host, (0, systemUtils_1.getSystemType)(responseDestination), (0, systemUtils_1.getProxyType)(responseDestination.proxyType), responseDestination.credentials.authentication, responseDestination["product.name"] || responseDestination.productName, responseDestination.description, retriever, responseDestination.sapClient); } function ServiceResponseToService(responseService, protocol) { var _a, _b, _c; if (protocol == "odatav2") { return [ new service_provider_apis_1.ODataService(responseService.TechnicalServiceName, responseService.ServiceUrl, responseService.ID, protocol, responseService.ServiceType, responseService.Description, responseService.TechnicalServiceVersion), ]; } if (protocol == "odatav4") { const services = []; const responseServices = ((_a = responseService === null || responseService === void 0 ? void 0 : responseService.DefaultSystem) === null || _a === void 0 ? void 0 : _a.Services) ? (_b = responseService === null || responseService === void 0 ? void 0 : responseService.DefaultSystem) === null || _b === void 0 ? void 0 : _b.Services : (_c = responseService === null || responseService === void 0 ? void 0 : responseService.DefaultSystem) === null || _c === void 0 ? void 0 : _c.RecommendedServices; if (!responseServices) { logger.error(`ServiceResponseToService: Response service did not include known service field`); return services; } const groupId = responseService.GroupId; for (const service of responseServices) { if (service) { services.push(new service_provider_apis_1.ODataService(service.ServiceAlias, service.ServiceUrl, service.ServiceId, protocol, service.ServiceType, service.Description, service.ServiceVersion, groupId)); } } return services; } } function AnnotationResponseToAnnotations(rawAnnotations) { const annotations = []; const entries = rawAnnotations.d.results; if (entries) { entries.forEach((annotationEntry) => { annotations.push({ src: extractAnnotationsSrc(annotationEntry.__metadata.media_src), technicalName: annotationEntry.TechnicalName, version: annotationEntry.Version, mediaType: annotationEntry.MediaType, }); }); } return annotations; } function extractAnnotationsSrc(mediaSrc) { const extractedSegment = mediaSrc.split(systemUtils_1.ODATA_V2_CATALOG_SERVICES)[1]; return extractedSegment; } function BusinessResponseToObject(businessResponse) { const { id, title, type, description } = businessResponse; return { title, type, description, id, }; } //# sourceMappingURL=serviceProviderAdapter.js.map