abap-adt-api
Version:
Interface to Abap Developer Tools webservice
623 lines (622 loc) • 25 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ADTClient = void 0;
exports.createSSLConfig = createSSLConfig;
const AdtException_1 = require("./AdtException");
const AdtHTTP_1 = require("./AdtHTTP");
const api_1 = require("./api");
const utilities_1 = require("./utilities");
const https_1 = __importDefault(require("https"));
function createSSLConfig(allowUnauthorized, ca) {
const httpsAgent = new https_1.default.Agent({
keepAlive: true,
ca,
rejectUnauthorized: !allowUnauthorized // disable CA checks?
});
return { httpsAgent };
}
class ADTClient {
get httpClient() {
return this.h;
}
static mainInclude(object, withDefault = true) {
// packages don't really have any include
if ((0, api_1.isPackageType)(object.metaData["adtcore:type"]))
return object.objectUrl;
if ((0, api_1.isClassStructure)(object)) {
const mainInclude = object.includes.find(x => x["class:includeType"] === "main");
const mainLink = mainInclude &&
(mainInclude.links.find(x => x.type === "text/plain") ||
mainInclude.links.find(x => !x.type)); // CDS have no type for the plain text link...
if (mainLink)
return (0, utilities_1.followUrl)(object.objectUrl, mainLink.href);
}
else {
const source = object.metaData["abapsource:sourceUri"];
if (source)
return (0, utilities_1.followUrl)(object.objectUrl, source);
const mainLink = object.links.find(x => x.type === "text/plain");
if (mainLink)
return (0, utilities_1.followUrl)(object.objectUrl, mainLink.href);
}
return withDefault
? (0, utilities_1.followUrl)(object.objectUrl, "/source/main")
: object.objectUrl;
}
static classIncludes(clas) {
const includes = new Map();
for (const i of clas.includes) {
const mainLink = i.links.find(x => x.type === "text/plain");
includes.set(i["class:includeType"], (0, utilities_1.followUrl)(clas.objectUrl, mainLink.href));
}
return includes;
}
get id() {
return this.h.id;
}
/**
* Create an ADT client
*
* @argument baseUrlOrClient Base url, i.e. http://vhcalnplci.local:8000
* @argument username SAP logon user
* @argument password Password
* @argument client Login client (optional)
* @argument language Language key (optional)
*/
constructor(baseUrlOrClient, username, password, client = "", language = "", options = {}) {
this.wrapFetcher = fetcher => {
let fetchBearer;
if (this.fetcher)
return this.fetcher;
this.fetcher = () => {
fetchBearer = fetchBearer || fetcher();
return fetchBearer;
};
return this.fetcher;
};
this.hasTransportConfig = async () => {
const collection = await this.findCollectionByUrl("/sap/bc/adt/cts/transportrequests/searchconfiguration/configurations");
return !!collection;
};
this.isProposalMessage = api_1.isProposalMessage;
if (!(baseUrlOrClient && username && (password || !(0, utilities_1.isString)(baseUrlOrClient))))
throw (0, AdtException_1.adtException)("Invalid ADTClient configuration: url, login and password are required");
if (typeof password !== "string")
password = this.wrapFetcher(password);
this.options = {
baseUrlOrClient: baseUrlOrClient,
username,
password,
client,
language,
options
};
this.h = this.createHttp();
}
createHttp() {
const o = this.options;
return new AdtHTTP_1.AdtHTTP(o.baseUrlOrClient, o.username, o.password, o.client, o.language, o.options);
}
get pIsClone() {
return this.h.isClone;
}
set pIsClone(isClone) {
this.h.isClone = isClone;
}
get statelessClone() {
if (this.pIsClone)
return this;
if (!this.pClone) {
const pw = this.fetcher || this.password;
if (!pw)
throw (0, AdtException_1.adtException)("Not logged in");
this.pClone = new ADTClient(this.baseUrl, this.username, pw, this.client, this.language, this.options.options);
this.pClone.pIsClone = true;
}
return this.pClone;
}
get stateful() {
return this.h.stateful;
}
set stateful(stateful) {
if (this.pIsClone)
throw (0, AdtException_1.adtException)("Stateful sessions not allowed in stateless clones");
this.h.stateful = stateful;
}
get loggedin() {
return this.h.loggedin;
}
get isStateful() {
return this.h.isStateful;
}
get csrfToken() {
return this.h.csrfToken;
}
get baseUrl() {
return this.h.baseURL;
}
get client() {
return this.h.client;
}
get language() {
return this.h.language;
}
get username() {
return this.h.username;
}
get password() {
return this.h.password;
}
/**
* Logs on an ADT server. parameters provided on creation
*/
login() {
// if loggedoff create a new client
if (!this.h.username)
this.h = this.createHttp();
return this.h.login();
}
/**
* Logs out current user, clearing cookies
* NOTE: you won't be able to login again with this client
*
* @memberof ADTClient
*/
logout() {
return this.h.logout();
}
dropSession() {
return this.h.dropSession();
}
get sessionID() {
const cookies = this.h.ascookies() || "";
const sc = cookies.split(";").find(c => !!c.match(/SAP_SESSIONID/));
return sc ? sc.split("=") : "";
}
nodeContents(
// tslint:disable: variable-name
parent_type, parent_name, user_name, parent_tech_name, rebuild_tree, parentnodes) {
return (0, api_1.nodeContents)(this.h, parent_type, parent_name, user_name, parent_tech_name, rebuild_tree, parentnodes);
}
async reentranceTicket() {
const response = await this.h.request("/sap/bc/adt/security/reentranceticket");
return "" + response.body || "";
}
transportInfo(objSourceUrl, devClass, operation = "I") {
return (0, api_1.transportInfo)(this.h, objSourceUrl, devClass, operation);
}
createTransport(objSourceUrl, REQUEST_TEXT, DEVCLASS, transportLayer) {
return (0, api_1.createTransport)(this.h, objSourceUrl, REQUEST_TEXT, DEVCLASS, "I", transportLayer);
}
objectStructure(objectUrl, version) {
return (0, api_1.objectStructure)(this.h, objectUrl, version);
}
activate(objectNameOrObjects, objectUrlOrPreauditReq = true, mainInclude, preauditRequested = true) {
if ((0, utilities_1.isString)(objectNameOrObjects))
return (0, api_1.activate)(this.h, objectNameOrObjects, objectUrlOrPreauditReq, // validated downstream
mainInclude, preauditRequested);
else
return (0, api_1.activate)(this.h, objectNameOrObjects, objectUrlOrPreauditReq // validated downstream
);
}
inactiveObjects() {
return (0, api_1.inactiveObjects)(this.h);
}
mainPrograms(includeUrl) {
return (0, api_1.mainPrograms)(this.h, includeUrl);
}
lock(objectUrl, accessMode = "MODIFY") {
return (0, api_1.lock)(this.h, objectUrl, accessMode);
}
unLock(objectUrl, lockHandle) {
return (0, api_1.unLock)(this.h, objectUrl, lockHandle);
}
/**
* Retrieves a resource content (i.e. a program's source code)
*
* @param objectSourceUrl Resource URL
* @param gitUser Username, only used for abapGit objects
* @param gitPassword password, only used for abapGit objects
*/
getObjectSource(objectSourceUrl, options) {
return (0, api_1.getObjectSource)(this.h, objectSourceUrl, options);
}
setObjectSource(objectSourceUrl, source, lockHandle, transport) {
return (0, api_1.setObjectSource)(this.h, objectSourceUrl, source, lockHandle, transport);
}
/**
* Search object by name pattern
*
* @param {string} query case sensitive in older systems, no wildcard added
* @param {string} [objType] if passed, only the first part is used i.e. PROG rather than PROG/P
* @param {number} [max=100] max number of results
* @returns
* @memberof ADTClient
*/
searchObject(query, objType, max = 100) {
return (0, api_1.searchObject)(this.h, query, objType, max);
}
findObjectPath(objectUrl) {
return (0, api_1.findObjectPath)(this.h, objectUrl);
}
validateNewObject(options) {
return (0, api_1.validateNewObject)(this.h, options);
}
createObject(optionsOrType, name, parentName, description, parentPath, responsible = "", transport = "") {
if ((0, api_1.isCreatableTypeId)(optionsOrType)) {
if (!name || !parentName || !parentPath || !description)
throw (0, AdtException_1.adtException)("");
return (0, api_1.createObject)(this.h, {
description,
name,
objtype: optionsOrType,
parentName,
parentPath,
responsible,
transport
});
}
else
return (0, api_1.createObject)(this.h, optionsOrType);
}
async featureDetails(title) {
if (!this.discovery)
this.discovery = await this.adtDiscovery();
return this.discovery.find(d => d.title === title);
}
async collectionFeatureDetails(url) {
if (!this.discovery)
this.discovery = await this.adtDiscovery();
return this.discovery.find(f => f.collection.find(c => c.templateLinks.find(l => l.template === url)));
}
async findCollectionByUrl(url) {
if (!this.discovery)
this.discovery = await this.adtDiscovery();
for (const discoveryResult of this.discovery) {
const collection = discoveryResult.collection.find(c => c.href === url);
if (collection)
return { discoveryResult, collection };
}
}
createTestInclude(clas, lockHandle, transport = "") {
return (0, api_1.createTestInclude)(this.h, clas, lockHandle, transport);
}
objectRegistrationInfo(objectUrl) {
return (0, api_1.objectRegistrationInfo)(this.h, objectUrl);
}
deleteObject(objectUrl, lockHandle, transport) {
return (0, api_1.deleteObject)(this.h, objectUrl, lockHandle, transport);
}
loadTypes() {
return (0, api_1.loadTypes)(this.h);
}
adtDiscovery() {
return (0, api_1.adtDiscovery)(this.h);
}
adtCoreDiscovery() {
return (0, api_1.adtCoreDiscovery)(this.h);
}
adtCompatibiliyGraph() {
return (0, api_1.adtCompatibilityGraph)(this.h);
}
syntaxCheckTypes() {
return (0, api_1.syntaxCheckTypes)(this.h);
}
syntaxCheck(url, mainUrl, content, mainProgram = "", version = "active") {
if (url.match(/^\/sap\/bc\/adt\/((ddic\/ddlx?)|(acm\/dcl))\/sources\//))
return (0, api_1.syntaxCheckCDS)(this.h, url, mainUrl, content);
else {
if (!mainUrl || !content)
throw (0, AdtException_1.adtException)("mainUrl and content are required for syntax check");
return (0, api_1.syntaxCheck)(this.h, url, mainUrl, content, mainProgram, version);
}
}
codeCompletion(sourceUrl, source, line, column) {
return (0, api_1.codeCompletion)(this.h, sourceUrl, source, line, column);
}
codeCompletionFull(sourceUrl, source, line, column, patternKey) {
return (0, api_1.codeCompletionFull)(this.h, sourceUrl, source, line, column, patternKey);
}
async runClass(className) {
const response = await this.h.request("/sap/bc/adt/oo/classrun/" + className.toUpperCase(), {
method: "POST"
});
return "" + response.body;
}
/**
* Read code completion elements
* Will fail on older systems where this returns HTML fragments rather than XML
*
* @param {string} sourceUrl
* @param {string} source
* @param {number} line
* @param {number} column
* @returns
* @memberof ADTClient
*/
codeCompletionElement(sourceUrl, source, line, column) {
return (0, api_1.codeCompletionElement)(this.h, sourceUrl, source, line, column);
}
findDefinition(url, source, line, startCol, endCol, implementation = false, mainProgram = "") {
return (0, api_1.findDefinition)(this.h, url, source, line, startCol, endCol, implementation, mainProgram);
}
usageReferences(url, line, column) {
return (0, api_1.usageReferences)(this.h, url, line, column);
}
usageReferenceSnippets(references) {
return (0, api_1.usageReferenceSnippets)(this.h, references);
}
fixProposals(url, source, line, column) {
return (0, api_1.fixProposals)(this.h, url, source, line, column);
}
fixEdits(proposal, source) {
return (0, api_1.fixEdits)(this.h, proposal, source);
}
unitTestRun(url, flags = api_1.DefaultUnitTestRunFlags) {
return (0, api_1.runUnitTest)(this.h, url, flags);
}
unitTestEvaluation(clas, flags = api_1.DefaultUnitTestRunFlags) {
return (0, api_1.unitTestEvaluation)(this.h, clas, flags);
}
unitTestOccurrenceMarkers(url, source) {
return (0, api_1.unitTestOccurrenceMarkers)(this.h, url, source);
}
classComponents(url) {
return (0, api_1.classComponents)(this.h, url);
}
fragmentMappings(url, type, name) {
return (0, api_1.fragmentMappings)(this.h, url, type, name);
}
objectTypes() {
return (0, api_1.objectTypes)(this.h);
}
prettyPrinterSetting() {
return (0, api_1.prettyPrinterSetting)(this.h);
}
setPrettyPrinterSetting(indent, style) {
return (0, api_1.setPrettyPrinterSetting)(this.h, indent, style);
}
prettyPrinter(source) {
return (0, api_1.prettyPrinter)(this.h, source);
}
typeHierarchy(url, body, line, offset, superTypes = false) {
return (0, api_1.typeHierarchy)(this.h, url, body, line, offset, superTypes);
}
transportConfigurations() {
return (0, api_1.transportConfigurations)(this.h);
}
getTransportConfiguration(url) {
return (0, api_1.getTransportConfiguration)(this.h, url);
}
setTransportsConfig(uri, etag, config) {
return (0, api_1.setTransportsConfig)(this.h, uri, etag, config);
}
createTransportsConfig() {
return (0, api_1.createTransportsConfig)(this.h);
}
userTransports(user, targets = true) {
return (0, api_1.userTransports)(this.h, user, targets);
}
transportsByConfig(configUri, targets = true) {
return (0, api_1.transportsByConfig)(this.h, configUri, targets);
}
transportDelete(transportNumber) {
return (0, api_1.transportDelete)(this.h, transportNumber);
}
transportRelease(transportNumber, ignoreLocks = false, IgnoreATC = false) {
return (0, api_1.transportRelease)(this.h, transportNumber, ignoreLocks, IgnoreATC);
}
transportSetOwner(transportNumber, targetuser) {
return (0, api_1.transportSetOwner)(this.h, transportNumber, targetuser);
}
transportAddUser(transportNumber, user) {
return (0, api_1.transportAddUser)(this.h, transportNumber, user);
}
systemUsers() {
return (0, api_1.systemUsers)(this.h);
}
transportReference(pgmid, obj_wbtype, obj_name, tr_number = "") {
return (0, api_1.transportReference)(this.h, pgmid, obj_wbtype, obj_name, tr_number);
}
revisions(objectUrl, clsInclude) {
return (0, api_1.revisions)(this.h, objectUrl, clsInclude);
}
abapDocumentation(objectUri, body, line, column, language = "EN") {
return (0, api_1.abapDocumentation)(this.h, objectUri, body, line, column, language);
}
packageSearchHelp(type, name = "*") {
return (0, api_1.packageSearchHelp)(this.h, type, name);
}
gitRepos() {
return (0, api_1.gitRepos)(this.h);
}
gitExternalRepoInfo(repourl, user = "", password = "") {
return (0, api_1.externalRepoInfo)(this.h, repourl, user, password);
}
gitCreateRepo(packageName, repourl, branch = "refs/heads/master", transport = "", user = "", password = "") {
return (0, api_1.createRepo)(this.h, packageName, repourl, branch, transport, user, password);
}
gitPullRepo(repoId, branch = "refs/heads/master", transport = "", user = "", password = "") {
return (0, api_1.pullRepo)(this.h, repoId, branch, transport, user, password);
}
gitUnlinkRepo(repoId) {
return (0, api_1.unlinkRepo)(this.h, repoId);
}
stageRepo(repo, user = "", password = "") {
return (0, api_1.stageRepo)(this.h, repo, user, password);
}
pushRepo(repo, staging, user = "", password = "") {
return (0, api_1.pushRepo)(this.h, repo, staging, user, password);
}
checkRepo(repo, user = "", password = "") {
return (0, api_1.checkRepo)(this.h, repo, user, password);
}
/**
* @deprecated since 1.2.1, duplicate of gitExternalRepoInfo
*/
remoteRepoInfo(repo, user = "", password = "") {
return (0, api_1.remoteRepoInfo)(this.h, repo, user, password);
}
switchRepoBranch(repo, branch, create = false, user = "", password = "") {
return (0, api_1.switchRepoBranch)(this.h, repo, branch, create, user, password);
}
annotationDefinitions() {
return (0, api_1.annotationDefinitions)(this.h);
}
ddicElement(path, getTargetForAssociation = false, getExtensionViews = true, getSecondaryObjects = true) {
return (0, api_1.ddicElement)(this.h, path, getTargetForAssociation, getExtensionViews, getSecondaryObjects);
}
ddicRepositoryAccess(path) {
return (0, api_1.ddicRepositoryAccess)(this.h, path);
}
publishServiceBinding(name, version) {
return (0, api_1.publishServiceBinding)(this.h, name, version);
}
unPublishServiceBinding(name, version) {
return (0, api_1.unpublishServiceBinding)(this.h, name, version);
}
/** Reads table data - usually returns one line more than requested */
tableContents(ddicEntityName, rowNumber = 100, decode = true, sqlQuery = "") {
return (0, api_1.tableContents)(this.h, ddicEntityName, rowNumber, decode, sqlQuery);
}
/** Runs a given SQL query on the target */
runQuery(sqlQuery, rowNumber = 100, decode = true) {
return (0, api_1.runQuery)(this.h, sqlQuery, rowNumber, decode);
}
bindingDetails(binding, index = 0) {
return (0, api_1.bindingDetails)(this.h, binding, index);
}
feeds() {
return (0, api_1.feeds)(this.h);
}
dumps(query) {
return (0, api_1.dumps)(this.h, query);
}
debuggerListeners(debuggingMode, terminalId, ideId, user, checkConflict = true) {
return (0, api_1.debuggerListeners)(this.h, debuggingMode, terminalId, ideId, user, checkConflict);
}
debuggerListen(debuggingMode, terminalId, ideId, user, checkConflict = true, isNotifiedOnConflict = true) {
return (0, api_1.debuggerListen)(this.h, debuggingMode, terminalId, ideId, user, checkConflict, isNotifiedOnConflict);
}
debuggerDeleteListener(debuggingMode, terminalId, ideId, user) {
return (0, api_1.debuggerDeleteListener)(this.h, debuggingMode, terminalId, ideId, user);
}
debuggerSetBreakpoints(debuggingMode, terminalId, ideId, clientId, breakpoints, user, scope = "external", systemDebugging = false, deactivated = false, syncScupeUrl = "") {
return (0, api_1.debuggerSetBreakpoints)(this.h, debuggingMode, terminalId, ideId, clientId, breakpoints, user, scope, systemDebugging, deactivated, syncScupeUrl);
}
debuggerDeleteBreakpoints(breakpoint, debuggingMode, terminalId, ideId, requestUser, scope = "external") {
return (0, api_1.debuggerDeleteBreakpoints)(this.h, breakpoint, debuggingMode, terminalId, ideId, requestUser, scope);
}
debuggerAttach(debuggingMode, debuggeeId, user, dynproDebugging = false) {
return (0, api_1.debuggerAttach)(this.h, debuggingMode, debuggeeId, user, dynproDebugging);
}
debuggerSaveSettings(settings) {
return (0, api_1.debuggerSaveSettings)(this.h, settings);
}
async debuggerStackTrace(semanticURIs = true) {
const stack = await this.collectionFeatureDetails("/sap/bc/adt/debugger/stack");
if (stack)
return (0, api_1.debuggerStack)(this.h, semanticURIs);
else
return (0, api_1.simpleDebuggerStack)(this.h, semanticURIs);
}
debuggerVariables(parents) {
return (0, api_1.debuggerVariables)(this.h, parents);
}
debuggerChildVariables(parent = ["@DATAAGING", "@ROOT"]) {
return (0, api_1.debuggerChildVariables)(this.h, parent);
}
debuggerStep(steptype, url) {
return (0, api_1.debuggerStep)(this.h, steptype, url);
}
/**
* Go to stack entry
*
* @param urlOrPosition The stack entry stackUri in newer systems, the stack id in older ones that return a DebugStackSimple
*/
debuggerGoToStack(urlOrPosition) {
if ((0, utilities_1.isString)(urlOrPosition))
return (0, api_1.debuggerGoToStack)(this.h, urlOrPosition);
else
return (0, api_1.debuggerGoToStackOld)(this.h, urlOrPosition);
}
debuggerSetVariableValue(variableName, value) {
return (0, api_1.debuggerSetVariableValue)(this.h, variableName, value);
}
renameEvaluate(uri, line, startColumn, endColumn) {
return (0, api_1.renameEvaluate)(this.h, uri, line, startColumn, endColumn);
}
renamePreview(renameRefactoring, transport = "") {
return (0, api_1.renamePreview)(this.h, renameRefactoring, transport);
}
renameExecute(refactoring) {
return (0, api_1.renameExecute)(this.h, refactoring);
}
atcCustomizing() {
return (0, api_1.atcCustomizing)(this.h);
}
atcCheckVariant(variant) {
return (0, api_1.atcCheckVariant)(this.h, variant);
}
createAtcRun(variant, mainUrl, maxResults = 100) {
return (0, api_1.createAtcRun)(this.h, variant, mainUrl, maxResults);
}
atcWorklists(runResultId, timestamp, usedObjectSet, includeExempted = false) {
return (0, api_1.atcWorklists)(this.h, runResultId, timestamp, usedObjectSet, includeExempted);
}
atcUsers() {
return (0, api_1.atcUsers)(this.h);
}
atcExemptProposal(markerId) {
return (0, api_1.atcExemptProposal)(this.h, markerId);
}
atcRequestExemption(proposal) {
return (0, api_1.atcRequestExemption)(this.h, proposal);
}
atcContactUri(findingUri) {
return (0, api_1.atcContactUri)(this.h, findingUri);
}
atcChangeContact(itemUri, userId) {
return (0, api_1.atcChangeContact)(this.h, itemUri, userId);
}
tracesList(user) {
return (0, api_1.tracesList)(this.h, user || this.username);
}
tracesListRequests(user) {
return (0, api_1.tracesListRequests)(this.h, user || this.username);
}
tracesHitList(id, withSystemEvents = false) {
return (0, api_1.tracesHitList)(this.h, id, withSystemEvents);
}
tracesDbAccess(id, withSystemEvents = false) {
return (0, api_1.tracesDbAccess)(this.h, id, withSystemEvents);
}
tracesStatements(id, options = {}) {
return (0, api_1.tracesStatements)(this.h, id, options);
}
tracesSetParameters(parameters) {
return (0, api_1.tracesSetParameters)(this.h, parameters);
}
tracesCreateConfiguration(config) {
return (0, api_1.tracesCreateConfiguration)(this.h, config);
}
tracesDeleteConfiguration(id) {
return (0, api_1.tracesDeleteConfiguration)(this.h, id);
}
tracesDelete(id) {
return (0, api_1.tracesDelete)(this.h, id);
}
extractMethodEvaluate(uri, range) {
return (0, api_1.extractMethodEvaluate)(this.h, uri, range);
}
extractMethodPreview(proposal) {
return (0, api_1.extractMethodPreview)(this.h, proposal);
}
extractMethodExecute(refactoring) {
return (0, api_1.extractMethodExecute)(this.h, refactoring);
}
}
exports.ADTClient = ADTClient;