UNPKG

@sap/subaccount-destination-service-provider

Version:

Provide service consumption of SAP subaccount services

118 lines 6.75 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.SubaccountDestinationProviderSystem = void 0; const service_provider_apis_1 = require("@sap/service-provider-apis"); const errorUtils_1 = require("../../common/utils/errorUtils"); class SubaccountDestinationProviderSystem { constructor(name, url, dataType, proxyType, authType, serviceRetriever, product, description, sapClient) { this.logger = service_provider_apis_1.DefaultLogger; this.name = name; this.url = url; this.dataType = dataType; this.proxyType = proxyType; this.authenticationType = authType; this.serviceRetriever = serviceRetriever; this.product = product; this.description = description; this.sapClient = sapClient; } getServices(options) { return __awaiter(this, void 0, void 0, function* () { try { return yield this.getServiceByType(options === null || options === void 0 ? void 0 : options.credentials, options === null || options === void 0 ? void 0 : options.filter); } catch (e) { (0, errorUtils_1.handleProviderError)(e, service_provider_apis_1.messages.ERROR_FAILED_TO_GET_SERVICES, this.logger); } }); } getMetadata(service, encoding, options) { return __awaiter(this, void 0, void 0, function* () { try { const relativeUrlParam = (options === null || options === void 0 ? void 0 : options.relativeUrl) ? options === null || options === void 0 ? void 0 : options.relativeUrl : service.getRelativeUrl(); const metadata = yield this.serviceRetriever.retrieveMetadata(this.name, relativeUrlParam, encoding, options === null || options === void 0 ? void 0 : options.credentials); if ((options === null || options === void 0 ? void 0 : options.annotations) && this.dataType === service_provider_apis_1.DataType.CATALOG) { try { metadata.annotations = yield this.serviceRetriever.retrieveAnnotations(this.name, service.id, options === null || options === void 0 ? void 0 : options.credentials); } catch (e) { this.logger.warn(`Could not retrieve Annotations for: ${service.id}`); metadata.annotations = []; } } return metadata; } catch (e) { (0, errorUtils_1.handleProviderError)(e, service_provider_apis_1.messages.ERROR_FAILED_TO_GET_METADATA, this.logger); } }); } getServiceUiType(service, options) { return __awaiter(this, void 0, void 0, function* () { try { return yield this.serviceRetriever.retrieveServiceUiType(this.name, service, options === null || options === void 0 ? void 0 : options.credentials); } catch (e) { (0, errorUtils_1.handleProviderError)(e, service_provider_apis_1.messages.ERROR_FAILED_TO_GET_SERVICES, this.logger); } }); } getJsonLiveData(service, relativeServiceUrl, entityName, options) { return __awaiter(this, void 0, void 0, function* () { return yield this.getLiveData(service, entityName, service_provider_apis_1.EncodingMode.JSON, options); }); } getAnnotations(service, options) { return __awaiter(this, void 0, void 0, function* () { try { if (this.dataType === service_provider_apis_1.DataType.CATALOG) { return yield this.serviceRetriever.retrieveAnnotations(this.name, service.id, options === null || options === void 0 ? void 0 : options.credentials); } else { const e = new Error(`${service_provider_apis_1.messages.ERROR_FAILED_TO_GET_ANNOTATIONS_FROM_NON_CATALOG}`); throw new service_provider_apis_1.ServiceProviderError(service_provider_apis_1.ServiceProviderErrorCode.RETRIEVE_DATA, e); } } catch (e) { (0, errorUtils_1.handleProviderError)(e, service_provider_apis_1.messages.ERROR_FAILED_TO_GET_ANNOTATIONS, this.logger); } }); } getLiveData(service, entityName, encoding, options) { return __awaiter(this, void 0, void 0, function* () { try { const relativeUrlParam = (options === null || options === void 0 ? void 0 : options.relativeUrl) ? options === null || options === void 0 ? void 0 : options.relativeUrl : service.getRelativeUrl(); return yield this.serviceRetriever.retrieveLiveData(this.name, relativeUrlParam, entityName, encoding, options === null || options === void 0 ? void 0 : options.filter, options === null || options === void 0 ? void 0 : options.credentials); } catch (e) { (0, errorUtils_1.handleProviderError)(e, service_provider_apis_1.messages.ERROR_FAILED_TO_GET_ENTITY_DATA(entityName), this.logger); } }); } getServiceByType(credentials, filter) { return __awaiter(this, void 0, void 0, function* () { switch (this.dataType) { case service_provider_apis_1.DataType.CATALOG: { return yield this.serviceRetriever.retrieveServices(this.name, this.url, credentials, filter); } case service_provider_apis_1.DataType.SERVICE_EP: { return [new service_provider_apis_1.ODataService(this.name, this.url, null)]; } case service_provider_apis_1.DataType.SERVICE_EP_FULL_URL: { return [new service_provider_apis_1.ODataService(this.name, "", null)]; } } }); } } exports.SubaccountDestinationProviderSystem = SubaccountDestinationProviderSystem; //# sourceMappingURL=subaccountDestinationProviderSystem.js.map