UNPKG

trm-core

Version:

TRM (Transport Request Manager) Core

502 lines (501 loc) 19.6 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); 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 }); exports.RFCClient = void 0; const commons_1 = require("../commons"); const logger_1 = require("../logger"); const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const nodeRfcLib = 'node-rfc'; class RFCClient { constructor(_rfcClientArgs, _cLangu, traceDir) { this._rfcClientArgs = _rfcClientArgs; this._cLangu = _cLangu; this._aliveCheck = false; try { process.env["RFC_TRACE_DIR"] = traceDir || process.cwd(); } catch (e) { logger_1.Logger.warning(`Couldn't set RFC trace!`, true); logger_1.Logger.error(e.toString(), true); } logger_1.Logger.log(`RFC_TRACE_DIR: ${process.env["RFC_TRACE_DIR"]}`, true); } getRfcClient() { return __awaiter(this, void 0, void 0, function* () { if (!this._rfcClient) { const globalPath = yield (0, commons_1.getNpmGlobalPath)(); const libPath = path_1.default.join(globalPath, nodeRfcLib); logger_1.Logger.log(`Node RFC lib path: ${libPath}`, true); if (!(0, fs_1.existsSync)(libPath)) { throw new Error(`${nodeRfcLib} not found. Run command "npm install ${nodeRfcLib} -g" to continue.`); } this._rfcClient = new (yield Promise.resolve(`${libPath}`).then(s => __importStar(require(s)))).Client(this._rfcClientArgs); } return this._rfcClient; }); } open() { return __awaiter(this, void 0, void 0, function* () { logger_1.Logger.loading(`Opening RFC connection`, true); yield (yield this.getRfcClient()).open(); logger_1.Logger.success(`RFC open`, true); }); } checkConnection() { return __awaiter(this, void 0, void 0, function* () { if (!this._aliveCheck) { if ((yield this.getRfcClient()).alive) { logger_1.Logger.success(`RFC open`, true); } else { logger_1.Logger.warning(`RFC closed`, true); } this._aliveCheck = true; } return (yield this.getRfcClient()).alive; }); } _call(fm, arg, timeout, noErrorParsing) { return __awaiter(this, void 0, void 0, function* () { var argNormalized; if (arg) { var emptyKeys = []; argNormalized = (0, commons_1.normalize)(arg, 'upper'); Object.keys(argNormalized).forEach(key => { if (argNormalized[key] === undefined || argNormalized === null) { emptyKeys.push(key); } }); emptyKeys.forEach(key => { delete argNormalized[key]; }); } else { argNormalized = {}; } var callOptions = undefined; if (timeout) { callOptions = { timeout }; } try { logger_1.Logger.loading(`Executing RFC, FM ${fm}, args ${JSON.stringify(argNormalized)}, opts ${JSON.stringify(callOptions)}`, true); const response = yield (yield this.getRfcClient()).call(fm, argNormalized, callOptions); const responseNormalized = (0, commons_1.normalize)(response); logger_1.Logger.success(`RFC resonse: ${JSON.stringify(responseNormalized)}`, true); return responseNormalized; } catch (e) { if (noErrorParsing) { throw e; } else { var message; var messageError; try { message = yield this._getMessage(true, { no: `${e.abapMsgNumber}`, class: e.abapMsgClass, v1: e.abapMsgV1, v2: e.abapMsgV2, v3: e.abapMsgV3, v4: e.abapMsgV4 }); } catch (k) { messageError = k; message = `Couldn't read error message ${e.abapMsgClass} ${e.abapMsgNumber} ${e.abapMsgV1} ${e.abapMsgV2} ${e.abapMsgV3} ${e.abapMsgV4}`; } var rfcClientError = new Error(message.trim()); rfcClientError.name = 'TrmRFCClient'; rfcClientError.rfcError = e; if (messageError) { rfcClientError.messageError = messageError; } logger_1.Logger.error(rfcClientError.toString(), true); throw rfcClientError; } } }); } _getMessage(noErrorParsing, data) { return __awaiter(this, void 0, void 0, function* () { var msgnr = data.no; while (msgnr.length < 3) { msgnr = `0${msgnr}`; } const aT100 = yield this._readTable(noErrorParsing, 'T100', [{ fieldName: 'SPRSL' }, { fieldName: 'ARBGB' }, { fieldName: 'MSGNR' }, { fieldName: 'TEXT' }], `SPRSL EQ '${this._cLangu}' AND ARBGB EQ '${data.class}' AND MSGNR EQ '${msgnr}'`); if (aT100.length === 1 && aT100[0].text) { var msg = aT100[0].text; msg = msg.replace("&1", data.v1 || ''); msg = msg.replace("&2", data.v2 || ''); msg = msg.replace("&3", data.v3 || ''); msg = msg.replace("&4", data.v4 || ''); return msg.trim(); } else { throw new Error(`Message ${msgnr}, class ${data.class}, lang ${this._cLangu} not found.`); } }); } getMessage(data) { return __awaiter(this, void 0, void 0, function* () { return this._getMessage(false, data); }); } _readTable(noErrorParsing, tableName, fields, options) { return __awaiter(this, void 0, void 0, function* () { var sqlOutput = []; const delimiter = '|'; var aOptions = []; if (options) { const aSplit = options.split(/\s+AND\s+/); if (aSplit.length > 1) { aSplit.forEach((s, i) => { var sText = s.trim(); if (i !== 0) { sText = `AND ${sText}`; } aOptions.push({ text: sText }); }); } else { aOptions = aSplit.map(s => { return { text: s }; }); } } const result = yield this._call("RFC_READ_TABLE", { query_table: tableName.toUpperCase(), delimiter, options: aOptions, fields: fields }, undefined, noErrorParsing); const data = result['data']; data.forEach(tab512 => { var sqlLine = {}; const waSplit = tab512.wa.split(delimiter); fields.forEach((field, index) => { sqlLine[field['FIELDNAME']] = waSplit[index].trim(); }); sqlOutput.push(sqlLine); }); return (0, commons_1.normalize)(sqlOutput); }); } readTable(tableName, fields, options) { return __awaiter(this, void 0, void 0, function* () { return this._readTable(false, tableName, fields, options); }); } getFileSystem() { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_GET_FILE_SYS", {}); return result['evFileSys']; }); } getDirTrans() { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_GET_DIR_TRANS", {}); return result['evDirTrans']; }); } getBinaryFile(filePath) { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_GET_BINARY_FILE", { iv_file_path: filePath }); return result['evFile']; }); } writeBinaryFile(filePath, binary) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_WRITE_BINARY_FILE", { iv_file_path: filePath, iv_file: binary }); }); } createTocTransport(text, target) { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_CREATE_TOC", { iv_text: text, iv_target: target.trim().toUpperCase() }); return result['evTrkorr']; }); } createWbTransport(text, target) { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_CREATE_IMPORT_TR", { iv_text: text, iv_target: target.trim().toUpperCase() }); return result['evTrkorr']; }); } setTransportDoc(trkorr, doc) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_SET_TRANSPORT_DOC", { iv_trkorr: trkorr.trim().toUpperCase(), it_doc: doc }); }); } getDevclassObjects(devclass) { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_GET_DEVCLASS_OBJS", { iv_devclass: devclass.trim().toUpperCase() }); return result['etTadir']; }); } addToTransportRequest(trkorr, content, lock) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_ADD_OBJS_TR", { iv_lock: lock ? 'X' : ' ', iv_trkorr: trkorr.trim().toUpperCase(), it_e071: content.map(o => { return { PGMID: o.pgmid, OBJECT: o.object, OBJ_NAME: o.objName }; }) }); }); } repositoryEnvironment(objectType, objectName) { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("REPOSITORY_ENVIRONMENT_RFC", { obj_type: objectType.trim().toUpperCase(), object_name: objectName.trim().toUpperCase() }); return result['environmentTab']; }); } deleteTrkorr(trkorr) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_DELETE_TRANSPORT", { iv_trkorr: trkorr.trim().toUpperCase() }); }); } releaseTrkorr(trkorr, lock, timeout) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_RELEASE_TR", { iv_trkorr: trkorr.trim().toUpperCase(), iv_lock: lock ? 'X' : ' ' }, timeout); }); } addSkipTrkorr(trkorr) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_ADD_SKIP_TRKORR", { iv_trkorr: trkorr.trim().toUpperCase() }); }); } addSrcTrkorr(trkorr) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_ADD_SRC_TRKORR", { iv_trkorr: trkorr.trim().toUpperCase() }); }); } readTmsQueue(target) { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_READ_TMS_QUEUE", { iv_target: target }); return result['etRequests']; }); } createPackage(scompkdtln) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_CREATE_PACKAGE", { is_data: scompkdtln }); }); } tdevcInterface(devclass, parentcl, rmParentCl, devlayer) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_TDEVC_INTERFACE", { iv_devclass: devclass.trim().toUpperCase(), iv_parentcl: parentcl ? parentcl.trim().toUpperCase() : '', iv_rm_parentcl: rmParentCl ? 'X' : ' ', iv_devlayer: devlayer ? devlayer.trim().toUpperCase() : '' }); }); } getDefaultTransportLayer() { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_GET_TRANSPORT_LAYER"); return result['evLayer']; }); } tadirInterface(tadir) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_TADIR_INTERFACE", { iv_pgmid: tadir.pgmid, iv_object: tadir.object, iv_obj_name: tadir.objName, iv_devclass: tadir.devclass, iv_set_genflag: tadir.genflag ? 'X' : ' ', iv_srcsystem: tadir.srcsystem }); }); } dequeueTransport(trkorr) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_DEQUEUE_TR", { iv_trkorr: trkorr.trim().toUpperCase() }); }); } forwardTransport(trkorr_1, target_1, source_1) { return __awaiter(this, arguments, void 0, function* (trkorr, target, source, importAgain = true) { yield this._call("ZTRM_FORWARD_TR", { iv_trkorr: trkorr.trim().toUpperCase(), iv_target: target.trim().toUpperCase(), iv_source: source.trim().toUpperCase(), iv_import_again: importAgain ? 'X' : ' ' }); }); } importTransport(trkorr, system) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_IMPORT_TR", { iv_system: system.trim().toUpperCase(), iv_trkorr: trkorr.trim().toUpperCase() }); }); } setInstallDevc(installDevc) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_SET_INSTALL_DEVC", { it_installdevc: installDevc }); }); } getObjectsList() { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_LIST_OBJECT_TYPES"); return result['etObjectText']; }); } getTrmServerVersion() { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_VERSION"); return result['evVersion']; }); } getTrmRestVersion() { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_VERSION"); return result['evRest']; }); } trmServerPing() { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_PING"); return result['evReturn']; }); } renameTransportRequest(trkorr, as4text) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_RENAME_TRANSPORT_REQUEST", { iv_trkorr: trkorr.trim().toUpperCase(), iv_as4text: as4text }); }); } setPackageIntegrity(integrity) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_SET_INTEGRITY", { is_integrity: integrity }); }); } addTranslationToTr(trkorr, devclassFilter) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_ADD_LANG_TR", { iv_trkorr: trkorr, it_devclass: devclassFilter }); }); } trCopy(from_1, to_1) { return __awaiter(this, arguments, void 0, function* (from, to, doc = false) { yield this._call("ZTRM_TR_COPY", { iv_from: from, iv_to: to, iv_doc: doc ? 'X' : ' ' }); }); } addNamespace(namespace, replicense, texts) { return __awaiter(this, void 0, void 0, function* () { yield this._call("ZTRM_ADD_NAMESPACE", { iv_namespace: namespace, iv_replicense: replicense, it_texts: texts }); }); } getR3transInfo() { return __awaiter(this, void 0, void 0, function* () { const result = yield this._call("ZTRM_GET_R3TRANS_INFO"); return result['evLog']; }); } } exports.RFCClient = RFCClient;