@sap/subaccount-destination-service-provider
Version:
Provide service consumption of SAP subaccount services
76 lines • 4.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BusinessResponseToObject = exports.AnnotationResponseToAnnotations = exports.ServiceResponseToService = exports.DestinationToProviderSystemBusiness = exports.DestinationToProviderSystem = void 0;
const lodash_1 = require("lodash");
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.Authentication, retriever, responseDestination["product.name"], responseDestination.Description);
}
exports.DestinationToProviderSystem = DestinationToProviderSystem;
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.Authentication, responseDestination["product.name"], responseDestination.Description, retriever);
}
exports.DestinationToProviderSystemBusiness = DestinationToProviderSystemBusiness;
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),
];
}
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;
}
for (const service of responseServices) {
if (service) {
services.push(new service_provider_apis_1.ODataService(service.ServiceAlias, service.ServiceUrl, service.ServiceId, protocol, service.ServiceType));
}
}
return services;
}
}
exports.ServiceResponseToService = ServiceResponseToService;
function AnnotationResponseToAnnotations(parsedAnnotations) {
const annotations = [];
let entry = (0, lodash_1.get)(parsedAnnotations, ["feed", "entry"], null);
if (entry && !Array.isArray(entry)) {
entry = [entry];
}
if (entry) {
entry.forEach((annotationEntry) => {
var _a;
const properties = annotationEntry["m:properties"];
if (properties) {
annotations.push({
src: (_a = annotationEntry.content) === null || _a === void 0 ? void 0 : _a.src,
technicalName: properties["d:TechnicalName"],
version: properties["d:Version"],
mediaType: properties["d:MediaType"],
});
}
});
}
return annotations;
}
exports.AnnotationResponseToAnnotations = AnnotationResponseToAnnotations;
function BusinessResponseToObject(businessResponse) {
const { id, title, type, description } = businessResponse;
return {
title,
type,
description,
id,
};
}
exports.BusinessResponseToObject = BusinessResponseToObject;
//# sourceMappingURL=serviceProviderAdapter.js.map