@rayutek/abap-adt-api 6.2.1-pkg-1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/.abapgit.xml +27 -0
  2. package/LICENSE +21 -0
  3. package/README.md +23 -0
  4. package/build/AdtClient.d.ts +292 -0
  5. package/build/AdtClient.d.ts.map +1 -0
  6. package/build/AdtClient.js +628 -0
  7. package/build/AdtException.d.ts +62 -0
  8. package/build/AdtException.d.ts.map +1 -0
  9. package/build/AdtException.js +185 -0
  10. package/build/AdtHTTP.d.ts +113 -0
  11. package/build/AdtHTTP.d.ts.map +1 -0
  12. package/build/AdtHTTP.js +285 -0
  13. package/build/api/abapgit.d.ts +86 -0
  14. package/build/api/abapgit.d.ts.map +1 -0
  15. package/build/api/abapgit.js +300 -0
  16. package/build/api/activate.d.ts +39 -0
  17. package/build/api/activate.d.ts.map +1 -0
  18. package/build/api/activate.js +105 -0
  19. package/build/api/atc.d.ts +163 -0
  20. package/build/api/atc.d.ts.map +1 -0
  21. package/build/api/atc.js +440 -0
  22. package/build/api/cds.d.ts +52 -0
  23. package/build/api/cds.d.ts.map +1 -0
  24. package/build/api/cds.js +147 -0
  25. package/build/api/debugger.d.ts +238 -0
  26. package/build/api/debugger.d.ts.map +1 -0
  27. package/build/api/debugger.js +299 -0
  28. package/build/api/delete.d.ts +20 -0
  29. package/build/api/delete.d.ts.map +1 -0
  30. package/build/api/delete.js +29 -0
  31. package/build/api/discovery.d.ts +44 -0
  32. package/build/api/discovery.d.ts.map +1 -0
  33. package/build/api/discovery.js +78 -0
  34. package/build/api/feeds.d.ts +63 -0
  35. package/build/api/feeds.d.ts.map +1 -0
  36. package/build/api/feeds.js +65 -0
  37. package/build/api/index.d.ts +22 -0
  38. package/build/api/index.d.ts.map +1 -0
  39. package/build/api/index.js +37 -0
  40. package/build/api/nodeContents.d.ts +41 -0
  41. package/build/api/nodeContents.d.ts.map +1 -0
  42. package/build/api/nodeContents.js +78 -0
  43. package/build/api/objectcontents.d.ts +21 -0
  44. package/build/api/objectcontents.d.ts.map +1 -0
  45. package/build/api/objectcontents.js +68 -0
  46. package/build/api/objectcreator.d.ts +103 -0
  47. package/build/api/objectcreator.d.ts.map +1 -0
  48. package/build/api/objectcreator.js +372 -0
  49. package/build/api/objectstructure.d.ts +71 -0
  50. package/build/api/objectstructure.d.ts.map +1 -0
  51. package/build/api/objectstructure.js +37 -0
  52. package/build/api/refactor.d.ts +122 -0
  53. package/build/api/refactor.d.ts.map +1 -0
  54. package/build/api/refactor.js +470 -0
  55. package/build/api/revisions.d.ts +12 -0
  56. package/build/api/revisions.d.ts.map +1 -0
  57. package/build/api/revisions.js +61 -0
  58. package/build/api/search.d.ts +25 -0
  59. package/build/api/search.d.ts.map +1 -0
  60. package/build/api/search.js +67 -0
  61. package/build/api/syntax.d.ts +133 -0
  62. package/build/api/syntax.d.ts.map +1 -0
  63. package/build/api/syntax.js +327 -0
  64. package/build/api/tablecontents.d.ts +141 -0
  65. package/build/api/tablecontents.d.ts.map +1 -0
  66. package/build/api/tablecontents.js +186 -0
  67. package/build/api/trace.test.d.ts +2 -0
  68. package/build/api/trace.test.d.ts.map +1 -0
  69. package/build/api/trace.test.js +39 -0
  70. package/build/api/traces.d.ts +13 -0
  71. package/build/api/traces.d.ts.map +1 -0
  72. package/build/api/traces.js +97 -0
  73. package/build/api/tracetypes.d.ts +276 -0
  74. package/build/api/tracetypes.d.ts.map +1 -0
  75. package/build/api/tracetypes.js +474 -0
  76. package/build/api/transports.d.ts +158 -0
  77. package/build/api/transports.d.ts.map +1 -0
  78. package/build/api/transports.js +292 -0
  79. package/build/api/unittest.d.ts +81 -0
  80. package/build/api/unittest.d.ts.map +1 -0
  81. package/build/api/unittest.js +164 -0
  82. package/build/api/urlparser.d.ts +34 -0
  83. package/build/api/urlparser.d.ts.map +1 -0
  84. package/build/api/urlparser.js +86 -0
  85. package/build/index.d.ts +10 -0
  86. package/build/index.d.ts.map +1 -0
  87. package/build/index.js +49 -0
  88. package/build/requestLogger.d.ts +30 -0
  89. package/build/requestLogger.d.ts.map +1 -0
  90. package/build/requestLogger.js +100 -0
  91. package/build/utilities.d.ts +42 -0
  92. package/build/utilities.d.ts.map +1 -0
  93. package/build/utilities.js +221 -0
  94. package/jest.config.js +32 -0
  95. package/package.json +45 -0
  96. package/setenv_sample.js +27 -0
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isErrorMessageType = exports.validateParseResult = exports.ValidateStateful = exports.ValidateObjectUrl = exports.adtException = exports.fromException = exports.fromError = exports.fromResponse = exports.isLoginError = exports.isAdtException = exports.isHttpError = exports.isCsrfError = exports.isAdtError = exports.AdtErrorException = exports.SAPRC = void 0;
7
+ const utilities_1 = require("./utilities");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const These_1 = require("fp-ts/lib/These");
10
+ const io_ts_reporters_1 = __importDefault(require("io-ts-reporters"));
11
+ const ADTEXTYPEID = Symbol.for("ADT EXCEPTION");
12
+ const CSRFEXTYPEID = Symbol.for("BAD CSRF");
13
+ const HTTPEXTYPEID = Symbol.for("HTTP EXCEPTION");
14
+ var SAPRC;
15
+ (function (SAPRC) {
16
+ SAPRC["Success"] = "S";
17
+ SAPRC["Info"] = "I";
18
+ SAPRC["Warning"] = "W";
19
+ SAPRC["Error"] = "E";
20
+ SAPRC["CriticalError"] = "A";
21
+ SAPRC["Exception"] = "X";
22
+ })(SAPRC = exports.SAPRC || (exports.SAPRC = {}));
23
+ const isResponse = (r) => (0, utilities_1.isObject)(r) && !!(r === null || r === void 0 ? void 0 : r.status) && (0, utilities_1.isString)(r === null || r === void 0 ? void 0 : r.statusText);
24
+ class AdtErrorException extends Error {
25
+ get typeID() {
26
+ return ADTEXTYPEID;
27
+ }
28
+ static create(errOrResponse, properties, type, message, parent, namespace, localizedMessage, response) {
29
+ if (!(0, utilities_1.isNumber)(errOrResponse)) {
30
+ return this.create(errOrResponse.status, properties, "", errOrResponse.statusText || "Unknown error in adt client", undefined, undefined, undefined, errOrResponse);
31
+ }
32
+ else {
33
+ return new AdtErrorException(errOrResponse, properties, type, message, parent, namespace, localizedMessage, response);
34
+ }
35
+ }
36
+ constructor(err, properties, type, message, parent, namespace, localizedMessage, response) {
37
+ super();
38
+ this.err = err;
39
+ this.properties = properties;
40
+ this.type = type;
41
+ this.message = message;
42
+ this.parent = parent;
43
+ this.namespace = namespace;
44
+ this.localizedMessage = localizedMessage;
45
+ this.response = response;
46
+ }
47
+ }
48
+ exports.AdtErrorException = AdtErrorException;
49
+ // tslint:disable-next-line:max-classes-per-file
50
+ class AdtCsrfException extends Error {
51
+ get typeID() {
52
+ return CSRFEXTYPEID;
53
+ }
54
+ constructor(message, parent) {
55
+ super();
56
+ this.message = message;
57
+ this.parent = parent;
58
+ }
59
+ }
60
+ // tslint:disable-next-line:max-classes-per-file
61
+ class AdtHttpException extends Error {
62
+ get typeID() {
63
+ return HTTPEXTYPEID;
64
+ }
65
+ get code() {
66
+ const p = this.parent;
67
+ return (p.response && p.response.status) || 0;
68
+ }
69
+ get message() {
70
+ return this.parent.message;
71
+ }
72
+ get name() {
73
+ return this.parent.name;
74
+ }
75
+ constructor(parent) {
76
+ super();
77
+ this.parent = parent;
78
+ }
79
+ }
80
+ function isAdtError(e) {
81
+ return (e === null || e === void 0 ? void 0 : e.typeID) === ADTEXTYPEID;
82
+ }
83
+ exports.isAdtError = isAdtError;
84
+ function isCsrfError(e) {
85
+ return (e === null || e === void 0 ? void 0 : e.typeID) === CSRFEXTYPEID;
86
+ }
87
+ exports.isCsrfError = isCsrfError;
88
+ function isHttpError(e) {
89
+ return (e === null || e === void 0 ? void 0 : e.typeID) === HTTPEXTYPEID;
90
+ }
91
+ exports.isHttpError = isHttpError;
92
+ function isAdtException(e) {
93
+ return isAdtError(e) || isCsrfError(e) || isHttpError(e);
94
+ }
95
+ exports.isAdtException = isAdtException;
96
+ const isLoginError = (adtErr) => (isHttpError(adtErr) && adtErr.code === 401) || isCsrfError(adtErr);
97
+ exports.isLoginError = isLoginError;
98
+ const simpleError = (response) => adtException(`Error ${response.status}:${response.statusText}`, response.status);
99
+ const isCsrfException = (r) => (r.status === 403 && r.headers["x-csrf-token"] === "Required") ||
100
+ (r.status === 400 && r.statusText === "Session timed out"); // hack to get login refresh to work on expired sessions
101
+ const fromResponse = (data, response) => {
102
+ if (!data)
103
+ return simpleError(response);
104
+ if (data.match(/CSRF/))
105
+ return new AdtCsrfException(data);
106
+ const raw = (0, utilities_1.fullParse)(data);
107
+ const root = raw["exc:exception"];
108
+ if (!root && response.status === 401)
109
+ return simpleError(response);
110
+ const getf = (base, idx) => (base ? base[idx] : "");
111
+ const properties = {};
112
+ (0, utilities_1.xmlArray)(root, "properties", "entry").forEach((p) => {
113
+ properties[p["@_key"]] = `${p["#text"]}`
114
+ .replace(/^\s+/, "")
115
+ .replace(/\s+$/, "");
116
+ });
117
+ return new AdtErrorException(response.status, properties, root.type["@_id"], root.message["#text"], undefined, getf(root.namespace, "@_id"), getf(root.localizedMessage, "#text"));
118
+ };
119
+ exports.fromResponse = fromResponse;
120
+ const axiosErrorBody = (e) => { var _a; return ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data) ? `${e.response.data}` : ""; };
121
+ const fromError = (error) => {
122
+ try {
123
+ if (isAdtError(error))
124
+ return error;
125
+ if (axios_1.default.isAxiosError(error) && error.response) {
126
+ if (error.status === 401)
127
+ return new AdtHttpException(error);
128
+ return (0, exports.fromResponse)(axiosErrorBody(error), error.response);
129
+ }
130
+ if ((0, utilities_1.isObject)(error) && "message" in error && (0, utilities_1.isString)(error === null || error === void 0 ? void 0 : error.message))
131
+ return new AdtErrorException(500, {}, "", error.message);
132
+ }
133
+ catch (error) { }
134
+ return AdtErrorException.create(500, {}, "Unknown error", `${error}`); // hopefully will never happen
135
+ };
136
+ exports.fromError = fromError;
137
+ function fromExceptionOrResponse_int(errOrResp, config) {
138
+ try {
139
+ if (isResponse(errOrResp))
140
+ return (0, exports.fromResponse)(errOrResp.body, errOrResp);
141
+ else
142
+ return (0, exports.fromError)(errOrResp);
143
+ }
144
+ catch (e) {
145
+ return isResponse(errOrResp)
146
+ ? AdtErrorException.create(errOrResp, {})
147
+ : (0, exports.fromError)(e);
148
+ }
149
+ }
150
+ function fromException(errOrResp, config) {
151
+ if (isAdtException(errOrResp))
152
+ return errOrResp;
153
+ if (!isResponse(errOrResp) &&
154
+ (!(0, utilities_1.isNativeError)(errOrResp) ||
155
+ ((0, utilities_1.isNativeError)(errOrResp) && !axios_1.default.isAxiosError(errOrResp))))
156
+ return AdtErrorException.create(500, {}, "Unknown error", `${errOrResp}`); // hopefully will never happen
157
+ return fromExceptionOrResponse_int(errOrResp, config);
158
+ }
159
+ exports.fromException = fromException;
160
+ function adtException(message, number = 0) {
161
+ return new AdtErrorException(number, {}, "", message);
162
+ }
163
+ exports.adtException = adtException;
164
+ function ValidateObjectUrl(url) {
165
+ if (url.match(/^\/sap\/bc\/adt\/[a-z]+\/[a-zA-Z%\$]?[\w%]+/))
166
+ return; // valid
167
+ throw new AdtErrorException(0, {}, "BADOBJECTURL", "Invalid Object URL:" + url);
168
+ }
169
+ exports.ValidateObjectUrl = ValidateObjectUrl;
170
+ function ValidateStateful(h) {
171
+ if (h.isStateful)
172
+ return;
173
+ throw new AdtErrorException(0, {}, "STATELESS", "This operation can only be performed in stateful mode");
174
+ }
175
+ exports.ValidateStateful = ValidateStateful;
176
+ const validateParseResult = (parseResult) => {
177
+ if ((0, These_1.isLeft)(parseResult)) {
178
+ const messages = io_ts_reporters_1.default.report(parseResult);
179
+ throw adtException(messages.slice(0, 3).join("\n"));
180
+ }
181
+ return parseResult.right;
182
+ };
183
+ exports.validateParseResult = validateParseResult;
184
+ const isErrorMessageType = (x) => !!`${x}`.match(/^[EAX]$/i);
185
+ exports.isErrorMessageType = isErrorMessageType;
@@ -0,0 +1,113 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { AxiosBasicCredentials, Method, AxiosResponseHeaders } from "axios";
4
+ import https from "https";
5
+ import { LogCallback } from ".";
6
+ export declare enum session_types {
7
+ stateful = "stateful",
8
+ stateless = "stateless",
9
+ keep = ""
10
+ }
11
+ export interface HttpResponse {
12
+ body: string;
13
+ }
14
+ export interface ClientOptions {
15
+ headers?: Record<string, string>;
16
+ httpsAgent?: https.Agent;
17
+ baseURL?: string;
18
+ debugCallback?: LogCallback;
19
+ timeout?: number;
20
+ auth?: AxiosBasicCredentials;
21
+ keepAlive?: boolean;
22
+ }
23
+ export interface RequestOptions extends ClientOptions {
24
+ method?: Method;
25
+ headers?: Record<string, string>;
26
+ httpsAgent?: https.Agent;
27
+ qs?: Record<string, any>;
28
+ baseURL?: string;
29
+ timeout?: number;
30
+ auth?: AxiosBasicCredentials;
31
+ body?: string;
32
+ url?: string;
33
+ }
34
+ export type BearerFetcher = () => Promise<string>;
35
+ export interface HttpClientResponse {
36
+ body: string;
37
+ status: number;
38
+ statusText: string;
39
+ headers: AxiosResponseHeaders;
40
+ request?: any;
41
+ }
42
+ interface RequestMetadata {
43
+ adtRequestNumber?: number;
44
+ adtStartTime?: Date;
45
+ }
46
+ export interface HttpClientOptions extends RequestOptions, RequestMetadata {
47
+ url: string;
48
+ }
49
+ /**
50
+ * Abstract HTTP client
51
+ * cookies, authentication and CSRF tokens usually handled by higher level intercacve
52
+ */
53
+ export interface HttpClient {
54
+ /**
55
+ * HTTP request
56
+ * @param options url, headers,...
57
+ * @returns the result of the HTTP call
58
+ *
59
+ * expected to throw only AdtException errors
60
+ */
61
+ request: (options: HttpClientOptions) => Promise<HttpClientResponse>;
62
+ }
63
+ export declare class AxiosHttpClient implements HttpClient {
64
+ private baseURL;
65
+ private axios;
66
+ constructor(baseURL: string, config?: ClientOptions);
67
+ request(options: HttpClientOptions): Promise<HttpClientResponse>;
68
+ }
69
+ export declare class AdtHTTP {
70
+ readonly username: string;
71
+ readonly client: string;
72
+ readonly language: string;
73
+ readonly baseURL: string;
74
+ readonly id: number;
75
+ readonly password?: string;
76
+ isClone: boolean;
77
+ private currentSession;
78
+ private _stateful;
79
+ private needKeepalive;
80
+ readonly keepAlive?: NodeJS.Timer;
81
+ private commonHeaders;
82
+ private bearer?;
83
+ private getToken?;
84
+ private auth?;
85
+ private httpclient;
86
+ private debugCallback?;
87
+ private loginPromise?;
88
+ get isStateful(): boolean;
89
+ get stateful(): session_types;
90
+ set stateful(value: session_types);
91
+ get csrfToken(): string;
92
+ set csrfToken(token: string);
93
+ get loggedin(): boolean;
94
+ constructor(baseURLOrClient: string | HttpClient, username: string, password: string | BearerFetcher, client: string, language: string, config?: ClientOptions);
95
+ login(): Promise<any>;
96
+ private cookie;
97
+ ascookies(): string;
98
+ logout(): Promise<void>;
99
+ dropSession(): Promise<void>;
100
+ request(url: string, config?: RequestOptions): Promise<HttpClientResponse>;
101
+ private keep_session;
102
+ private updateCookies;
103
+ private logResponse;
104
+ /**
105
+ * HTTP request without automated login / retry
106
+ *
107
+ * @param url URL suffix
108
+ * @param options request options
109
+ */
110
+ private _request;
111
+ }
112
+ export {};
113
+ //# sourceMappingURL=AdtHTTP.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdtHTTP.d.ts","sourceRoot":"","sources":["../src/AdtHTTP.ts"],"names":[],"mappings":";;AAAA,OAAc,EAGZ,qBAAqB,EACrB,MAAM,EACN,oBAAoB,EAGrB,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAOL,WAAW,EACZ,MAAM,GAAG,CAAA;AAYV,oBAAY,aAAa;IACvB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,IAAI,KAAK;CACV;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,E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I,QAAQ,IAAI,OAAO,CAEtB;gBAEC,eAAe,EAAE,MAAM,GAAG,UAAU,EAC3B,QAAQ,EAAE,MAAM,EACzB,QAAQ,EAAE,MAAM,GAAG,aAAa,EACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EACzB,MAAM,CAAC,EAAE,aAAa;IA0BlB,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC;IAwB3B,OAAO,CAAC,MAAM,CAA4B;IAC1C,SAAS,IAAI,MAAM;IAGb,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAWvB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,OAAO,CACX,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,kBAAkB,CAAC;IAuB9B,OAAO,CAAC,YAAY,CAInB;IACD,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,WAAW;IAUnB;;;;;OAKG;YACW,QAAQ;CAwCvB"}
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AdtHTTP = exports.AxiosHttpClient = exports.session_types = void 0;
27
+ const axios_1 = __importStar(require("axios"));
28
+ const AdtException_1 = require("./AdtException");
29
+ const _1 = require(".");
30
+ const requestLogger_1 = require("./requestLogger");
31
+ const utilities_1 = require("./utilities");
32
+ const FETCH_CSRF_TOKEN = "fetch";
33
+ const CSRF_TOKEN_HEADER = "x-csrf-token";
34
+ const SESSION_HEADER = "X-sap-adt-sessiontype";
35
+ const runningInNode = typeof process !== "undefined" &&
36
+ process.versions != null &&
37
+ process.versions.node != null;
38
+ let lastClientId = 0;
39
+ var session_types;
40
+ (function (session_types) {
41
+ session_types["stateful"] = "stateful";
42
+ session_types["stateless"] = "stateless";
43
+ session_types["keep"] = "";
44
+ })(session_types = exports.session_types || (exports.session_types = {}));
45
+ const toAxiosConfig = (options) => {
46
+ const config = {
47
+ method: options.method || "GET",
48
+ url: options.url,
49
+ headers: options.headers || {},
50
+ params: options.qs,
51
+ httpsAgent: options.httpsAgent,
52
+ timeout: options.timeout,
53
+ auth: options.auth,
54
+ data: options.body,
55
+ adtRequestNumber: options.adtRequestNumber,
56
+ adtStartTime: options.adtStartTime
57
+ };
58
+ return config;
59
+ };
60
+ let adtRequestNumber = 0;
61
+ const convertheaders = (raw) => {
62
+ if (raw instanceof axios_1.AxiosHeaders)
63
+ return raw;
64
+ const headers = new axios_1.AxiosHeaders();
65
+ for (const k in Object.keys(raw))
66
+ headers.set(k, raw[k]);
67
+ return headers;
68
+ };
69
+ class AxiosHttpClient {
70
+ constructor(baseURL, config) {
71
+ this.baseURL = baseURL;
72
+ const conf = toAxiosConfig({ ...config });
73
+ this.axios = axios_1.default.create({ ...conf, baseURL });
74
+ }
75
+ async request(options) {
76
+ try {
77
+ const config = toAxiosConfig(options);
78
+ const { data, headers, ...rest } = await this.axios.request(config);
79
+ const body = data ? ((0, utilities_1.isString)(data) ? data : `${data}`) : "";
80
+ return { body, headers: convertheaders(headers), ...rest };
81
+ }
82
+ catch (error) {
83
+ throw (0, _1.fromError)(error);
84
+ }
85
+ }
86
+ }
87
+ exports.AxiosHttpClient = AxiosHttpClient;
88
+ class AdtHTTP {
89
+ get isStateful() {
90
+ return (this.stateful === session_types.stateful ||
91
+ (this.stateful === session_types.keep &&
92
+ this.currentSession === session_types.stateful));
93
+ }
94
+ get stateful() {
95
+ return this._stateful;
96
+ }
97
+ set stateful(value) {
98
+ this._stateful = value;
99
+ if (value !== session_types.keep)
100
+ this.currentSession = value;
101
+ }
102
+ get csrfToken() {
103
+ return this.commonHeaders[CSRF_TOKEN_HEADER] || FETCH_CSRF_TOKEN;
104
+ }
105
+ set csrfToken(token) {
106
+ this.commonHeaders[CSRF_TOKEN_HEADER] = token;
107
+ }
108
+ get loggedin() {
109
+ return this.csrfToken !== FETCH_CSRF_TOKEN;
110
+ }
111
+ constructor(baseURLOrClient, username, password, client, language, config) {
112
+ this.username = username;
113
+ this.client = client;
114
+ this.language = language;
115
+ this.isClone = false;
116
+ this.currentSession = session_types.stateless;
117
+ this._stateful = session_types.stateless;
118
+ this.needKeepalive = false;
119
+ this.cookie = new Map();
120
+ this.keep_session = async () => {
121
+ if (this.needKeepalive && this.loggedin)
122
+ await this._request("/sap/bc/adt/compatibility/graph", {}).catch(() => { });
123
+ this.needKeepalive = true;
124
+ };
125
+ if (!(baseURLOrClient && username && (password || !(0, utilities_1.isString)(baseURLOrClient))))
126
+ throw (0, _1.adtException)("Invalid ADTClient configuration: url, login and password are required");
127
+ this.baseURL = (0, utilities_1.isString)(baseURLOrClient) ? baseURLOrClient : "";
128
+ this.id = lastClientId++;
129
+ if ((0, utilities_1.isString)(password))
130
+ this.password = password;
131
+ else
132
+ this.getToken = password;
133
+ this.commonHeaders = {
134
+ ...config === null || config === void 0 ? void 0 : config.headers,
135
+ Accept: "*/*",
136
+ "Cache-Control": "no-cache",
137
+ [CSRF_TOKEN_HEADER]: FETCH_CSRF_TOKEN
138
+ };
139
+ this.httpclient = (0, utilities_1.isString)(baseURLOrClient)
140
+ ? new AxiosHttpClient(baseURLOrClient, config)
141
+ : baseURLOrClient;
142
+ this.debugCallback = config === null || config === void 0 ? void 0 : config.debugCallback;
143
+ if (config === null || config === void 0 ? void 0 : config.keepAlive)
144
+ this.keepAlive = setInterval(() => this.keep_session(), 120000);
145
+ }
146
+ async login() {
147
+ if (this.loginPromise)
148
+ return this.loginPromise;
149
+ this.cookie.clear();
150
+ // oauth
151
+ if (this.getToken && !this.bearer) {
152
+ await this.getToken().then(bearer => (this.bearer = bearer));
153
+ }
154
+ else
155
+ this.auth = {
156
+ username: this.username || "",
157
+ password: this.password || ""
158
+ };
159
+ const qs = {};
160
+ if (this.client)
161
+ qs["sap-client"] = this.client;
162
+ if (this.language)
163
+ qs["sap-language"] = this.language;
164
+ this.csrfToken = FETCH_CSRF_TOKEN;
165
+ try {
166
+ this.loginPromise = this._request("/sap/bc/adt/compatibility/graph", {
167
+ qs
168
+ });
169
+ await this.loginPromise;
170
+ }
171
+ finally {
172
+ this.loginPromise = undefined;
173
+ }
174
+ }
175
+ ascookies() {
176
+ return [...this.cookie.values()].join("; ");
177
+ }
178
+ async logout() {
179
+ this.stateful = session_types.stateless;
180
+ await this._request("/sap/public/bc/icf/logoff", {});
181
+ // prevent autologin
182
+ this.auth = undefined;
183
+ this.bearer = undefined;
184
+ // new cookie jar
185
+ this.cookie.clear();
186
+ // clear token
187
+ this.csrfToken = FETCH_CSRF_TOKEN;
188
+ }
189
+ async dropSession() {
190
+ this.stateful = session_types.stateless;
191
+ await this._request("/sap/bc/adt/compatibility/graph", {});
192
+ }
193
+ async request(url, config) {
194
+ let autologin = false;
195
+ try {
196
+ if (!this.loggedin) {
197
+ autologin = true;
198
+ await this.login();
199
+ }
200
+ return await this._request(url, config || {});
201
+ }
202
+ catch (e) {
203
+ const adtErr = (0, AdtException_1.fromException)(e, config);
204
+ // if the logon ticket expired try to logon again, unless in stateful mode
205
+ // or already tried a login
206
+ if ((0, _1.isLoginError)(adtErr) && !autologin && !this.isStateful) {
207
+ try {
208
+ this.csrfToken = FETCH_CSRF_TOKEN;
209
+ await this.login();
210
+ return await this._request(url, config || {});
211
+ }
212
+ catch (e2) {
213
+ throw (0, AdtException_1.fromException)(e2, config);
214
+ }
215
+ }
216
+ else
217
+ throw adtErr;
218
+ }
219
+ }
220
+ updateCookies(response) {
221
+ if (runningInNode) {
222
+ const cookies = response.headers["set-cookie"] || [];
223
+ cookies.forEach(cookie => {
224
+ const cleaned = cookie
225
+ .replace(/path=\/,/g, "")
226
+ .replace(/path=\//g, "")
227
+ .split(";")[0];
228
+ const [key] = cookie.split("=", 1);
229
+ this.cookie.set(key, cleaned);
230
+ });
231
+ }
232
+ }
233
+ logResponse(exceptionOrResponse, options) {
234
+ if (!this.debugCallback)
235
+ return;
236
+ if ((0, _1.isAdtException)(exceptionOrResponse))
237
+ (0, requestLogger_1.logError)(this.id, exceptionOrResponse, this.debugCallback, options);
238
+ else
239
+ (0, requestLogger_1.logResponse)(this.id, exceptionOrResponse, options, this.debugCallback);
240
+ }
241
+ /**
242
+ * HTTP request without automated login / retry
243
+ *
244
+ * @param url URL suffix
245
+ * @param options request options
246
+ */
247
+ async _request(url, options) {
248
+ this.needKeepalive = false;
249
+ const headers = { ...this.commonHeaders, ...options.headers };
250
+ headers[SESSION_HEADER] = this.stateful;
251
+ if (!headers["Cookie"] && runningInNode)
252
+ headers["Cookie"] = this.ascookies();
253
+ adtRequestNumber++;
254
+ const adtStartTime = new Date();
255
+ const config = {
256
+ ...options,
257
+ auth: this.auth,
258
+ headers,
259
+ adtStartTime,
260
+ adtRequestNumber,
261
+ url
262
+ };
263
+ try {
264
+ if (this.getToken && !this.bearer)
265
+ this.bearer = await this.getToken();
266
+ if (this.bearer)
267
+ headers.Authorization = `bearer ${this.bearer}`;
268
+ const response = await this.httpclient.request(config);
269
+ this.updateCookies(response);
270
+ if (response.status >= 400)
271
+ throw (0, AdtException_1.fromException)(response, config);
272
+ if (this.csrfToken === FETCH_CSRF_TOKEN &&
273
+ (0, utilities_1.isString)(response.headers[CSRF_TOKEN_HEADER]))
274
+ this.csrfToken = response.headers[CSRF_TOKEN_HEADER];
275
+ this.logResponse(response, config);
276
+ return response;
277
+ }
278
+ catch (error) {
279
+ const exc = (0, AdtException_1.fromException)(error, config);
280
+ this.logResponse(exc, config);
281
+ throw exc;
282
+ }
283
+ }
284
+ }
285
+ exports.AdtHTTP = AdtHTTP;
@@ -0,0 +1,86 @@
1
+ import { AdtHTTP } from "../AdtHTTP";
2
+ export interface GitLink {
3
+ href: string;
4
+ rel: string;
5
+ type?: "pull_link" | "stage_link" | "push_link" | "check_link" | "status_link" | "log_link" | string;
6
+ }
7
+ export interface GitRepo {
8
+ key: string;
9
+ sapPackage: string;
10
+ url: string;
11
+ branch_name: string;
12
+ created_by: string;
13
+ created_at: Date;
14
+ created_email?: string;
15
+ deserialized_by?: string;
16
+ deserialized_email?: string;
17
+ deserialized_at?: Date;
18
+ status?: string;
19
+ status_text?: string;
20
+ links: GitLink[];
21
+ }
22
+ export interface GitBranch {
23
+ sha1: string;
24
+ name: string;
25
+ type: string;
26
+ is_head: boolean;
27
+ display_name: string;
28
+ }
29
+ export interface GitExternalInfo {
30
+ access_mode: "PUBLIC" | "PRIVATE";
31
+ branches: GitBranch[];
32
+ }
33
+ export interface GitObject {
34
+ obj_type: string;
35
+ obj_name: string;
36
+ package: string;
37
+ obj_status: string;
38
+ msg_type: string;
39
+ msg_text: string;
40
+ }
41
+ export interface GitStagingFile {
42
+ name: string;
43
+ path: string;
44
+ localState: string;
45
+ links: GitLink[];
46
+ }
47
+ export interface GitStagingObject {
48
+ wbkey: string;
49
+ uri: string;
50
+ type: string;
51
+ name: string;
52
+ abapGitFiles: GitStagingFile[];
53
+ }
54
+ export interface GitUser {
55
+ name: string;
56
+ email: string;
57
+ }
58
+ export interface GitStaging {
59
+ staged: GitStagingObject[];
60
+ unstaged: GitStagingObject[];
61
+ ignored: GitStagingObject[];
62
+ comment: string;
63
+ author: GitUser;
64
+ committer: GitUser;
65
+ }
66
+ /**
67
+ * @deprecated since 1.2.1, duplicate of GitExternalInfo
68
+ */
69
+ export interface GitRemoteInfo {
70
+ access_mode: string;
71
+ branches: GitBranch[];
72
+ }
73
+ export declare function gitRepos(h: AdtHTTP): Promise<GitRepo[]>;
74
+ export declare function externalRepoInfo(h: AdtHTTP, repourl: string, user?: string, password?: string): Promise<GitExternalInfo>;
75
+ export declare function createRepo(h: AdtHTTP, packageName: string, repourl: string, branch?: string, transport?: string, user?: string, password?: string): Promise<void[]>;
76
+ export declare function pullRepo(h: AdtHTTP, repoId: string, branch?: string, transport?: string, user?: string, password?: string): Promise<void[]>;
77
+ export declare function unlinkRepo(h: AdtHTTP, repoId: string): Promise<void>;
78
+ export declare function checkRepo(h: AdtHTTP, repo: GitRepo, user?: string, password?: string): Promise<void>;
79
+ export declare function pushRepo(h: AdtHTTP, repo: GitRepo, staging: GitStaging, user?: string, password?: string): Promise<void>;
80
+ export declare function stageRepo(h: AdtHTTP, repo: GitRepo, user?: string, password?: string): Promise<GitStaging>;
81
+ /**
82
+ * @deprecated since 1.2.1, duplicate of externalRepoInfo
83
+ */
84
+ export declare function remoteRepoInfo(h: AdtHTTP, repo: GitRepo, user?: string, password?: string): Promise<GitRemoteInfo>;
85
+ export declare function switchRepoBranch(h: AdtHTTP, repo: GitRepo, branch: string, create?: boolean, user?: string, password?: string): Promise<void>;
86
+ //# sourceMappingURL=abapgit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abapgit.d.ts","sourceRoot":"","sources":["../../src/api/abapgit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAkBpC,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EACH,WAAW,GACX,YAAY,GACZ,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