@sap/adp-abap
Version:
abap service for all yeoman generators
161 lines • 7.11 kB
JavaScript
;
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const messages_1 = require("../i18n/messages");
class DestinationService {
constructor() {
this.NO_AUTHENTICATION_VALUE = "NoAuthentication";
this.destinationConfigs = [];
this.errorMessage = { message: null };
}
static getInstance() {
if (!DestinationService.instance) {
DestinationService.instance = new DestinationService();
}
return DestinationService.instance;
}
getErrorMessage() {
return this.errorMessage.message;
}
getDestinationNames() {
return __awaiter(this, void 0, void 0, function* () {
this.errorMessage.message = null;
let destinationNames = [];
try {
this.destinationConfigs = yield this.reloadDestinations();
if (this.destinationConfigs) {
destinationNames = Object.keys(this.destinationConfigs)
.map((item) => {
return this.destinationConfigs[item].Name;
})
.sort((a, b) => {
return a.toLowerCase().localeCompare(b.toLowerCase(), "en", { sensitivity: "base" });
});
}
}
catch (err) {
const message = err instanceof Error ? err.message : String(err);
this.errorMessage.message = message;
}
return destinationNames;
});
}
getDestinationHost(destinationName) {
const found = this.destinationConfigs.find((destinationConfig) => {
return destinationConfig.Name === destinationName;
});
if (!found) {
throw new Error(messages_1.Messages.DESTINATION_HOST_NOT_FOUND);
}
return found.Host;
}
getDestinationHostPattern(destinationName) {
const found = this.destinationConfigs.find((destinationConfig) => {
return destinationConfig.Name === destinationName;
});
if (found) {
return `https://${destinationName}.dest`;
}
else {
return messages_1.Messages.DESTINATION_HOST_NOT_FOUND;
}
}
getDestinationRequiresAuthentication(destinationName) {
const found = this.destinationConfigs.find((destinationConfig) => {
return destinationConfig.Name === destinationName;
});
return found.Authentication === this.NO_AUTHENTICATION_VALUE;
}
getDestinationProxyType(destinationName) {
const found = this.destinationConfigs.find((destinationConfig) => {
return destinationConfig.Name === destinationName;
});
return found.ProxyType;
}
reloadDestinations() {
return __awaiter(this, void 0, void 0, function* () {
yield axios_1.default.get(this.getEnvProxy() + "/reload");
const response = yield axios_1.default.get(DestinationService.getH2OEnvParam() + "/api/listDestinations");
if (response && response.data) {
const destinationsResponse = response.data;
return destinationsResponse.filter((destinationConfig) => {
return destinationConfig.WebIDEUsage && destinationConfig.WebIDEUsage.includes("dev_abap");
});
}
return [];
});
}
getDestinationInfoByName(destinationName) {
return __awaiter(this, void 0, void 0, function* () {
return this.destinationConfigs.find((dest) => {
return dest.Name === destinationName;
});
});
}
getDestinationUI5Version(destinationName, defaultUI5Versions) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield axios_1.default.get(`${DestinationService.getH2OEnvParam()}/destinations/${destinationName}/sap/bc/adt/filestore/ui5-bsp/ui5-rt-version`);
if (response && response.data) {
// version comes in the following format 1.81.0.20200727003800
const ui5Version = this.getPublicAvailableUI5Version(response.data);
return [ui5Version];
}
return defaultUI5Versions;
});
}
getPublicAvailableUI5Version(ui5Version) {
// If the system has snapshot version on it
// return the latest public version
const ui5VersionArr = ui5Version.split(".");
if (parseInt(ui5VersionArr[1]) > 84) {
return "1.84.7";
}
else {
return ui5Version;
}
}
// !!! get the list of public available UI5 version using the below url
//const SAP_UI5_VERSION_API = "https://sapui5.hana.ondemand.com/version.json";
getPathToDestination(destinationName) {
return `${DestinationService.getH2OEnvParam()}/destinations/${destinationName}`;
}
static destinations() {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield axios_1.default.get(`${DestinationService.getH2OEnvParam()}/api/listDestinations`);
return ((response === null || response === void 0 ? void 0 : response.data)
.filter((destination) => { var _a; return (_a = destination.WebIDEUsage) === null || _a === void 0 ? void 0 : _a.includes("dev_abap"); })
.map((destination) => ({
name: destination.Name,
authenticated: destination.Authentication !== "NoAuthentication"
}))
.sort((a, b) => {
return a.name.toLowerCase().localeCompare(b.name.toLowerCase(), "en", { sensitivity: "base" });
}) || []);
}
catch (error) {
throw new Error(`Unable to get destinations. ${error === null || error === void 0 ? void 0 : error.message}`);
}
});
}
static getH2OEnvParam() {
return process.env.H2O_URL;
}
getEnvProxy() {
return process.env.http_proxy;
}
}
exports.default = DestinationService;
//# sourceMappingURL=DestinationService.js.map