UNPKG

@sap/adp-abap

Version:

abap service for all yeoman generators

145 lines 7.14 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.AbapService = exports.ABAP_PACKAGE_SEARCH_MAX_RESULTS = void 0; const axios_extension_1 = require("@sap-ux/axios-extension"); exports.ABAP_PACKAGE_SEARCH_MAX_RESULTS = 50; /** * Client for managing all consumed requests to an ABAP system. */ class AbapService { /** * Constructs an instance of ConfigClient. * * @param {AbapProvider} abapProvider - The ABAP Provider handling the connection with the system. * @param {boolean} isCustomerBase - whether layer is CUSTOMER_BASE */ constructor(abapProvider, isCustomerBase) { this.abapProvider = abapProvider; this.isCustomerBase = isCustomerBase; } /** * Function that connects provider to Abap system. * * @param {string} system - Abap system. * @param {string} client - Abap system client. * @param {string} username - username for authentication with Abap system. * @param {string} password - password for authentication with Abap system. */ connectToSystem(system, client, username, password) { return __awaiter(this, void 0, void 0, function* () { if (!this.abapProvider.isConnected() || (this.abapProvider.getSystem() && this.abapProvider.getSystem() !== system)) { yield this.abapProvider.setProvider(system, client, username, password); } }); } /** * Fetches system UI5 Version from UI5RtVersionService. * * @returns {string | undefined} system UI5 version */ getSystemUI5Version() { return __awaiter(this, void 0, void 0, function* () { const provider = this.abapProvider.getProvider(); const service = yield provider.getAdtService(axios_extension_1.UI5RtVersionService); const version = yield (service === null || service === void 0 ? void 0 : service.getUI5Version()); return version; }); } /** * Determines if the ABAP environment is an ABAP Cloud environment. * * This method checks the Automatic Tenant Onboarding (ATO) settings retrieved from the ABAP provider * to verify if the tenant type is `Customer` and the operations type is `'C'` (Cloud). * * @returns {Promise<boolean>} A promise that resolves to `true` if the environment is ABAP Cloud, otherwise `false`. */ isAbapCloud() { return __awaiter(this, void 0, void 0, function* () { const provider = this.abapProvider.getProvider(); const isAbapCloud = yield provider.isAbapCloud(); return isAbapCloud; }); } /** * Fetches system information from the provider's layered repository. * * @param {string} language - language for translations * @param {string} packageName - package name * @returns {SystemInfo} system into containing system supported adaptation project types and translations. */ getSystemInfo(language, packageName) { return __awaiter(this, void 0, void 0, function* () { const provider = this.abapProvider.getProvider(); const lrep = provider.getLayeredRepository(); return lrep.getSystemInfo(language, packageName); }); } /** * Fetches system supports Flex UI features. * * @returns {Promise<FlexUISupportedSystem | undefined>} settings indicating support for onPremise and UI Flex capabilities. */ getFlexUISupportedSystem() { return __awaiter(this, void 0, void 0, function* () { if (!this.isCustomerBase) { return { isOnPremise: true, isUIFlex: true }; } const FILTER = { "scheme": "http://www.sap.com/adt/categories/ui_flex", "term": "dta_folder" }; const acceptHeaders = { headers: { Accept: "application/*" } }; const provider = this.abapProvider.getProvider(); const response = yield provider.get(axios_extension_1.AdtCatalogService.ADT_DISCOVERY_SERVICE_PATH, acceptHeaders); return { isOnPremise: response.data.includes(FILTER.term), isUIFlex: response.data.includes(FILTER.scheme) }; }); } /** * Queries an ABAP system for a list of packages based on a search phrase. * * @param {string} phrase - The search phrase used to filter the packages. * @returns {Promise<string[]>} A promise that resolves to an array of package names, or an empty array if none found or on error. */ listPackages(phrase) { return __awaiter(this, void 0, void 0, function* () { const provider = this.abapProvider.getProvider(); const packageService = yield provider.getAdtService(axios_extension_1.ListPackageService); const packages = yield (packageService === null || packageService === void 0 ? void 0 : packageService.listPackages({ maxResults: exports.ABAP_PACKAGE_SEARCH_MAX_RESULTS, phrase })); return packages !== null && packages !== void 0 ? packages : []; }); } /** * Fetches a list of transport requests for a given package and repository using a specified ABAP service provider. * * @param {string} packageName - The name of the package for which transport requests are being fetched. * @param {string} repository - The repository associated with the package. * @returns {Promise<string[]>} A promise that resolves to an array of transport request numbers. */ listTransports(packageName, repository) { var _a; return __awaiter(this, void 0, void 0, function* () { const provider = this.abapProvider.getProvider(); const transportCheckService = yield provider.getAdtService(axios_extension_1.TransportChecksService); const transportRequests = yield (transportCheckService === null || transportCheckService === void 0 ? void 0 : transportCheckService.getTransportRequests(packageName, repository)); return (_a = transportRequests === null || transportRequests === void 0 ? void 0 : transportRequests.map((transport) => transport.transportNumber)) !== null && _a !== void 0 ? _a : []; }); } } exports.AbapService = AbapService; //# sourceMappingURL=AbapService.js.map