@mcp-abap-adt/connection 4.0.0 → 6.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.
- package/CHANGELOG.md +407 -1
- package/README.md +239 -53
- package/dist/auth/providers.d.ts +124 -0
- package/dist/auth/providers.d.ts.map +1 -0
- package/dist/auth/providers.js +183 -0
- package/dist/connection/AbstractAbapConnection.d.ts +209 -57
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +459 -457
- package/dist/connection/AdtCloudConnector.d.ts +34 -0
- package/dist/connection/AdtCloudConnector.d.ts.map +1 -0
- package/dist/connection/AdtCloudConnector.js +27 -0
- package/dist/connection/AdtOnPremConnector.d.ts +43 -0
- package/dist/connection/AdtOnPremConnector.d.ts.map +1 -0
- package/dist/connection/AdtOnPremConnector.js +28 -0
- package/dist/connection/CloudHttpTransport.d.ts +37 -0
- package/dist/connection/CloudHttpTransport.d.ts.map +1 -0
- package/dist/connection/CloudHttpTransport.js +145 -0
- package/dist/connection/CredentialAbapConnection.d.ts +55 -0
- package/dist/connection/CredentialAbapConnection.d.ts.map +1 -0
- package/dist/connection/CredentialAbapConnection.js +128 -0
- package/dist/connection/HttpTransport.d.ts +178 -0
- package/dist/connection/HttpTransport.d.ts.map +1 -0
- package/dist/connection/HttpTransport.js +402 -0
- package/dist/connection/IAdtTransport.d.ts +232 -0
- package/dist/connection/IAdtTransport.d.ts.map +1 -0
- package/dist/connection/IAdtTransport.js +28 -0
- package/dist/connection/LegacyOnPremHttpTransport.d.ts +40 -0
- package/dist/connection/LegacyOnPremHttpTransport.d.ts.map +1 -0
- package/dist/connection/LegacyOnPremHttpTransport.js +57 -0
- package/dist/connection/OnPremHttpTransport.d.ts +45 -0
- package/dist/connection/OnPremHttpTransport.d.ts.map +1 -0
- package/dist/connection/OnPremHttpTransport.js +91 -0
- package/dist/connection/RfcTransport.d.ts +89 -0
- package/dist/connection/RfcTransport.d.ts.map +1 -0
- package/dist/connection/RfcTransport.js +256 -0
- package/dist/connection/rfcConversation.d.ts +44 -0
- package/dist/connection/rfcConversation.d.ts.map +1 -0
- package/dist/connection/rfcConversation.js +71 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -18
- package/dist/session/SessionLifecycle.d.ts +17 -2
- package/dist/session/SessionLifecycle.d.ts.map +1 -1
- package/dist/session/SessionLifecycle.js +17 -2
- package/dist/utils/cookies.d.ts +12 -0
- package/dist/utils/cookies.d.ts.map +1 -0
- package/dist/utils/cookies.js +24 -0
- package/dist/utils/timeouts.d.ts +6 -3
- package/dist/utils/timeouts.d.ts.map +1 -1
- package/dist/utils/timeouts.js +6 -3
- package/docs/INDEX.md +5 -2
- package/docs/INSTALLATION.md +28 -6
- package/docs/JWT_AUTH_TOOLS.md +20 -4
- package/docs/MIGRATION-2.0.md +1 -1
- package/docs/MIGRATION-5.0.md +116 -0
- package/docs/MIGRATION-6.0.md +359 -0
- package/docs/SCOPE.md +1 -1
- package/docs/STATEFUL_SESSION_GUIDE.md +155 -20
- package/docs/USAGE.md +322 -111
- package/examples/basic-connection.js +15 -3
- package/examples/jwt-with-token-refresh.js +15 -7
- package/examples/saml-connection.js +15 -2
- package/package.json +12 -10
- package/dist/__tests__/helpers/session.d.ts +0 -15
- package/dist/__tests__/helpers/session.d.ts.map +0 -1
- package/dist/__tests__/helpers/session.js +0 -19
- package/dist/connection/BaseAbapConnection.d.ts +0 -23
- package/dist/connection/BaseAbapConnection.d.ts.map +0 -1
- package/dist/connection/BaseAbapConnection.js +0 -75
- package/dist/connection/CertificateAbapConnection.d.ts +0 -25
- package/dist/connection/CertificateAbapConnection.d.ts.map +0 -1
- package/dist/connection/CertificateAbapConnection.js +0 -79
- package/dist/connection/JwtAbapConnection.d.ts +0 -115
- package/dist/connection/JwtAbapConnection.d.ts.map +0 -1
- package/dist/connection/JwtAbapConnection.js +0 -358
- package/dist/connection/KerberosAbapConnection.d.ts +0 -24
- package/dist/connection/KerberosAbapConnection.d.ts.map +0 -1
- package/dist/connection/KerberosAbapConnection.js +0 -120
- package/dist/connection/RfcAbapConnection.d.ts +0 -49
- package/dist/connection/RfcAbapConnection.d.ts.map +0 -1
- package/dist/connection/RfcAbapConnection.js +0 -331
- package/dist/connection/SamlAbapConnection.d.ts +0 -25
- package/dist/connection/SamlAbapConnection.d.ts.map +0 -1
- package/dist/connection/SamlAbapConnection.js +0 -75
- package/dist/connection/connectionFactory.d.ts +0 -9
- package/dist/connection/connectionFactory.d.ts.map +0 -1
- package/dist/connection/connectionFactory.js +0 -32
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RfcAbapConnection = void 0;
|
|
4
|
-
const node_crypto_1 = require("node:crypto");
|
|
5
|
-
function rfcErrorMessage(e) {
|
|
6
|
-
if (e instanceof Error)
|
|
7
|
-
return e.message;
|
|
8
|
-
if (e && typeof e === 'object')
|
|
9
|
-
return JSON.stringify(e);
|
|
10
|
-
return String(e);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Derive RFC connection parameters from ISapConfig.
|
|
14
|
-
* Parses hostname from config.url, system number from port (80XX → XX).
|
|
15
|
-
*
|
|
16
|
-
* Examples:
|
|
17
|
-
* http://saphost:8000 → ashost=saphost, sysnr=00
|
|
18
|
-
* http://saphost:8001 → ashost=saphost, sysnr=01
|
|
19
|
-
* http://saphost:8042 → ashost=saphost, sysnr=42
|
|
20
|
-
*/
|
|
21
|
-
function buildRfcParams(config) {
|
|
22
|
-
const parsed = new URL(config.url);
|
|
23
|
-
const port = Number.parseInt(parsed.port || '8000', 10);
|
|
24
|
-
// SAP HTTP port convention: 80XX where XX = system number.
|
|
25
|
-
// SAP_SYSNR env var overrides derivation for non-standard ports (e.g. 50400).
|
|
26
|
-
const derivedSysnr = String(port - 8000).padStart(2, '0');
|
|
27
|
-
const sysnr = process.env.SAP_SYSNR?.trim() || derivedSysnr;
|
|
28
|
-
return {
|
|
29
|
-
ashost: parsed.hostname,
|
|
30
|
-
sysnr,
|
|
31
|
-
client: config.client || '000',
|
|
32
|
-
user: config.username || '',
|
|
33
|
-
passwd: config.password || '',
|
|
34
|
-
lang: 'EN',
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Map ADT exception type names to HTTP status codes.
|
|
39
|
-
* These are standard ADT exception types returned in `<exc:exception>` XML.
|
|
40
|
-
*/
|
|
41
|
-
const EXCEPTION_STATUS_MAP = {
|
|
42
|
-
ExceptionResourceNotFound: { code: 404, text: 'Not Found' },
|
|
43
|
-
ExceptionResourceNoAuthorization: { code: 403, text: 'Forbidden' },
|
|
44
|
-
ExceptionResourceAlreadyExists: { code: 409, text: 'Conflict' },
|
|
45
|
-
ExceptionResourceLocked: { code: 423, text: 'Locked' },
|
|
46
|
-
ExceptionBadRequest: { code: 400, text: 'Bad Request' },
|
|
47
|
-
ExceptionNotSupported: { code: 501, text: 'Not Implemented' },
|
|
48
|
-
ExceptionConflict: { code: 409, text: 'Conflict' },
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Detect HTTP status from ADT exception XML in response body.
|
|
52
|
-
* On some legacy systems, SADT_REST_RFC_ENDPOINT returns errors as XML
|
|
53
|
-
* exceptions without setting proper HTTP status codes in STATUS_LINE.
|
|
54
|
-
*/
|
|
55
|
-
function detectExceptionStatus(body) {
|
|
56
|
-
// Extract exception type: <exc:exception ... xmlns:exc="..."><exc:type>ExceptionName</exc:type>
|
|
57
|
-
const typeMatch = body.match(/<exc:type[^>]*>([^<]+)<\/exc:type>/);
|
|
58
|
-
if (typeMatch) {
|
|
59
|
-
const exType = typeMatch[1].trim();
|
|
60
|
-
const mapped = EXCEPTION_STATUS_MAP[exType];
|
|
61
|
-
if (mapped) {
|
|
62
|
-
return { statusCode: mapped.code, statusText: mapped.text };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Unknown exception type — return 500 as generic server error
|
|
66
|
-
return { statusCode: 500, statusText: 'Internal Server Error' };
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* RFC-based connection for on-premise SAP systems.
|
|
70
|
-
*
|
|
71
|
-
* Uses @mcp-abap-adt/sap-rfc-lite to call SADT_REST_RFC_ENDPOINT — the same standard SAP FM
|
|
72
|
-
* that Eclipse ADT uses for all on-premise ADT operations via JCo.
|
|
73
|
-
*
|
|
74
|
-
* RFC connections are inherently stateful: one ABAP session persists for the
|
|
75
|
-
* entire connection lifetime. This solves the HTTP 423 "invalid lock handle"
|
|
76
|
-
* problem on legacy systems (BASIS < 7.50) where HTTP stateful sessions
|
|
77
|
-
* are not supported.
|
|
78
|
-
*
|
|
79
|
-
* Connection parameters are derived from the standard ISapConfig.url field:
|
|
80
|
-
* http://saphost:8000 → ashost=saphost, sysnr=00
|
|
81
|
-
*
|
|
82
|
-
* Prerequisites:
|
|
83
|
-
* - SAP NW RFC SDK installed on the machine
|
|
84
|
-
* - @mcp-abap-adt/sap-rfc-lite package installed: npm install @mcp-abap-adt/sap-rfc-lite
|
|
85
|
-
*/
|
|
86
|
-
class RfcAbapConnection {
|
|
87
|
-
config;
|
|
88
|
-
logger;
|
|
89
|
-
rfcClient = null;
|
|
90
|
-
sessionId;
|
|
91
|
-
baseUrl;
|
|
92
|
-
rfcParams;
|
|
93
|
-
sessionType = 'stateless';
|
|
94
|
-
sessionCookie = null;
|
|
95
|
-
constructor(config, logger = null) {
|
|
96
|
-
this.config = config;
|
|
97
|
-
this.logger = logger;
|
|
98
|
-
RfcAbapConnection.validateConfig(config);
|
|
99
|
-
this.sessionId = (0, node_crypto_1.randomUUID)();
|
|
100
|
-
this.baseUrl = config.url;
|
|
101
|
-
this.rfcParams = buildRfcParams(config);
|
|
102
|
-
this.logger?.debug(`RfcAbapConnection created for ${this.rfcParams.ashost}:${this.rfcParams.sysnr}, client ${this.rfcParams.client}`);
|
|
103
|
-
}
|
|
104
|
-
async connect() {
|
|
105
|
-
let Client;
|
|
106
|
-
try {
|
|
107
|
-
// Dynamic require — @mcp-abap-adt/sap-rfc-lite is NOT a declared dependency.
|
|
108
|
-
// Users who need RFC connections must install it manually:
|
|
109
|
-
// npm install @mcp-abap-adt/sap-rfc-lite (+ SAP NW RFC SDK on the machine)
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
111
|
-
const noderfc = require('@mcp-abap-adt/sap-rfc-lite');
|
|
112
|
-
Client = noderfc.Client;
|
|
113
|
-
}
|
|
114
|
-
catch (e) {
|
|
115
|
-
throw new Error('@mcp-abap-adt/sap-rfc-lite is not available. To use RFC connections, install SAP NW RFC SDK ' +
|
|
116
|
-
'and run: npm install @mcp-abap-adt/sap-rfc-lite. ' +
|
|
117
|
-
`Details: ${rfcErrorMessage(e)}`);
|
|
118
|
-
}
|
|
119
|
-
this.rfcClient = new Client(this.rfcParams);
|
|
120
|
-
try {
|
|
121
|
-
await this.rfcClient.open();
|
|
122
|
-
this.logger?.debug('RFC connection opened (stateful session)');
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
this.rfcClient = null;
|
|
126
|
-
const msg = rfcErrorMessage(e);
|
|
127
|
-
this.logger?.error(`RFC connection failed: ${msg}`);
|
|
128
|
-
throw new Error(`Failed to open RFC connection: ${msg}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
async getBaseUrl() {
|
|
132
|
-
return this.baseUrl;
|
|
133
|
-
}
|
|
134
|
-
getSessionId() {
|
|
135
|
-
return this.sessionId;
|
|
136
|
-
}
|
|
137
|
-
setSessionType(type) {
|
|
138
|
-
this.sessionType = type;
|
|
139
|
-
if (type === 'stateless') {
|
|
140
|
-
this.sessionCookie = null;
|
|
141
|
-
this.logger?.debug('RFC session type: stateless (cookie cleared)');
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
this.logger?.debug('RFC session type: stateful (will capture cookies)');
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
async makeAdtRequest(options) {
|
|
148
|
-
if (!this.rfcClient?.alive) {
|
|
149
|
-
throw new Error('RFC connection is not open. Call connect() first.');
|
|
150
|
-
}
|
|
151
|
-
const method = options.method.toUpperCase();
|
|
152
|
-
// Encode query params into URI (axios does this automatically for HTTP,
|
|
153
|
-
// but RFC needs it done manually)
|
|
154
|
-
let uri = options.url;
|
|
155
|
-
if (options.params && typeof options.params === 'object') {
|
|
156
|
-
const entries = Object.entries(options.params).filter(([, v]) => v !== undefined && v !== null);
|
|
157
|
-
if (entries.length > 0) {
|
|
158
|
-
const qs = new URLSearchParams(entries.map(([k, v]) => [k, String(v)]));
|
|
159
|
-
uri += (uri.includes('?') ? '&' : '?') + qs.toString();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// Note: sap-client is NOT added to URI for RFC connections.
|
|
163
|
-
// The RFC session is already logged into the correct client
|
|
164
|
-
// (via the 'client' param in RFC connection). Adding sap-client
|
|
165
|
-
// to the URI can cause "object not found" on some systems.
|
|
166
|
-
// Build header fields
|
|
167
|
-
const headerFields = [];
|
|
168
|
-
if (options.headers) {
|
|
169
|
-
for (const [name, value] of Object.entries(options.headers)) {
|
|
170
|
-
headerFields.push({ NAME: name, VALUE: value });
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// Inject session type header so SAP creates/maintains an ICM session
|
|
174
|
-
if (this.sessionType === 'stateful') {
|
|
175
|
-
headerFields.push({ NAME: 'x-sap-adt-sessiontype', VALUE: 'stateful' });
|
|
176
|
-
}
|
|
177
|
-
// Replay session cookie for stateful operations (cookie captured from LOCK response)
|
|
178
|
-
if (this.sessionCookie) {
|
|
179
|
-
const existingCookie = headerFields.find((h) => h.NAME.toLowerCase() === 'cookie');
|
|
180
|
-
if (!existingCookie) {
|
|
181
|
-
headerFields.push({ NAME: 'Cookie', VALUE: this.sessionCookie });
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Ensure Content-Type for body
|
|
185
|
-
const body = options.data !== undefined && options.data !== null
|
|
186
|
-
? String(options.data)
|
|
187
|
-
: '';
|
|
188
|
-
if (body &&
|
|
189
|
-
!headerFields.some((h) => h.NAME.toLowerCase() === 'content-type')) {
|
|
190
|
-
headerFields.push({
|
|
191
|
-
NAME: 'Content-Type',
|
|
192
|
-
VALUE: 'text/plain; charset=utf-8',
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
this.logger?.debug(`RFC → ${method} ${uri}`);
|
|
196
|
-
this.logger?.debug(`RFC → headers: ${JSON.stringify(headerFields)}`);
|
|
197
|
-
if (body)
|
|
198
|
-
this.logger?.debug(`RFC → body: ${body}`);
|
|
199
|
-
try {
|
|
200
|
-
const result = await this.rfcClient.call('SADT_REST_RFC_ENDPOINT', {
|
|
201
|
-
REQUEST: {
|
|
202
|
-
REQUEST_LINE: {
|
|
203
|
-
METHOD: method,
|
|
204
|
-
URI: uri,
|
|
205
|
-
VERSION: 'HTTP/1.1',
|
|
206
|
-
},
|
|
207
|
-
HEADER_FIELDS: headerFields,
|
|
208
|
-
MESSAGE_BODY: body ? Buffer.from(body, 'utf-8') : Buffer.alloc(0),
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
const resp = result.RESPONSE || result;
|
|
212
|
-
// Log raw RFC response structure for debugging
|
|
213
|
-
this.logger?.debug(`RFC raw response keys: ${Object.keys(resp).join(', ')}`);
|
|
214
|
-
if (resp.STATUS_LINE) {
|
|
215
|
-
this.logger?.debug(`RFC STATUS_LINE: ${JSON.stringify(resp.STATUS_LINE)}`);
|
|
216
|
-
}
|
|
217
|
-
// Parse status — RFC returns status in STATUS_LINE structure
|
|
218
|
-
// Field names: STATUS_CODE (not CODE), REASON_PHRASE (not REASON)
|
|
219
|
-
const rawCode = resp.STATUS_LINE?.STATUS_CODE || resp.STATUS_LINE?.CODE || 0;
|
|
220
|
-
let statusCode = typeof rawCode === 'string' ? Number.parseInt(rawCode, 10) : rawCode;
|
|
221
|
-
let statusText = resp.STATUS_LINE?.REASON_PHRASE || resp.STATUS_LINE?.REASON || '';
|
|
222
|
-
// Parse response body
|
|
223
|
-
const respBody = resp.MESSAGE_BODY
|
|
224
|
-
? Buffer.isBuffer(resp.MESSAGE_BODY)
|
|
225
|
-
? resp.MESSAGE_BODY.toString('utf-8')
|
|
226
|
-
: String(resp.MESSAGE_BODY)
|
|
227
|
-
: '';
|
|
228
|
-
// Parse response headers
|
|
229
|
-
const respHeaders = {};
|
|
230
|
-
const respHeaderFields = resp.HEADER_FIELDS || [];
|
|
231
|
-
for (const field of respHeaderFields) {
|
|
232
|
-
if (field.NAME && field.VALUE !== undefined) {
|
|
233
|
-
respHeaders[field.NAME.toLowerCase()] = field.VALUE;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
// Capture session cookie from LOCK/stateful responses for cookie replay
|
|
237
|
-
if (this.sessionType === 'stateful' && respHeaders['set-cookie']) {
|
|
238
|
-
const setCookieHeader = respHeaders['set-cookie'];
|
|
239
|
-
// Extract cookie name=value pairs (strip attributes like Path, Secure, etc.)
|
|
240
|
-
const cookies = Array.isArray(setCookieHeader)
|
|
241
|
-
? setCookieHeader
|
|
242
|
-
: [setCookieHeader];
|
|
243
|
-
const cookieValues = cookies
|
|
244
|
-
.map((c) => c.split(';')[0].trim())
|
|
245
|
-
.filter(Boolean);
|
|
246
|
-
if (cookieValues.length > 0) {
|
|
247
|
-
this.sessionCookie = cookieValues.join('; ');
|
|
248
|
-
this.logger?.debug(`RFC: captured session cookie: ${this.sessionCookie}`);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
// On some systems (e.g. BASIS < 7.50), SADT_REST_RFC_ENDPOINT does not
|
|
252
|
-
// populate STATUS_LINE, returning status 0. Detect errors from the
|
|
253
|
-
// response body: ADT exception XML indicates a failed request.
|
|
254
|
-
if (!statusCode && respBody.includes('<exc:exception')) {
|
|
255
|
-
const detected = detectExceptionStatus(respBody);
|
|
256
|
-
statusCode = detected.statusCode;
|
|
257
|
-
statusText = detected.statusText;
|
|
258
|
-
this.logger?.debug(`RFC: STATUS_LINE empty, detected ${statusCode} from exception XML`);
|
|
259
|
-
}
|
|
260
|
-
// Default to 200 OK only when no error was detected
|
|
261
|
-
if (!statusCode) {
|
|
262
|
-
statusCode = 200;
|
|
263
|
-
statusText = statusText || 'OK';
|
|
264
|
-
}
|
|
265
|
-
this.logger?.debug(`RFC ← ${statusCode} ${statusText} (${respBody.length} bytes)`);
|
|
266
|
-
this.logger?.debug(`RFC ← headers: ${JSON.stringify(respHeaders)}`);
|
|
267
|
-
if (respBody)
|
|
268
|
-
this.logger?.debug(`RFC ← body: ${respBody}`);
|
|
269
|
-
const response = {
|
|
270
|
-
data: respBody,
|
|
271
|
-
status: statusCode,
|
|
272
|
-
statusText,
|
|
273
|
-
headers: respHeaders,
|
|
274
|
-
};
|
|
275
|
-
// Throw for error status codes (matching HTTP/axios behavior)
|
|
276
|
-
if (statusCode >= 400) {
|
|
277
|
-
const error = new Error(`Request failed with status ${statusCode}: ${method} ${uri}`);
|
|
278
|
-
error.response = response;
|
|
279
|
-
throw error;
|
|
280
|
-
}
|
|
281
|
-
return response;
|
|
282
|
-
}
|
|
283
|
-
catch (e) {
|
|
284
|
-
// Re-throw our own errors (status >= 400)
|
|
285
|
-
if (e?.response) {
|
|
286
|
-
throw e;
|
|
287
|
-
}
|
|
288
|
-
// RFC-level error
|
|
289
|
-
const msg = rfcErrorMessage(e);
|
|
290
|
-
this.logger?.error(`RFC call failed: ${msg}`);
|
|
291
|
-
throw new Error(`RFC call to SADT_REST_RFC_ENDPOINT failed: ${msg}`);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Reset the connection — for RFC this closes the session.
|
|
296
|
-
* Provides interface compatibility with HTTP connections.
|
|
297
|
-
*/
|
|
298
|
-
reset() {
|
|
299
|
-
this.close();
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Close the RFC connection and release the ABAP session.
|
|
303
|
-
*/
|
|
304
|
-
async close() {
|
|
305
|
-
if (this.rfcClient) {
|
|
306
|
-
try {
|
|
307
|
-
await this.rfcClient.close();
|
|
308
|
-
this.logger?.debug('RFC connection closed');
|
|
309
|
-
}
|
|
310
|
-
catch (e) {
|
|
311
|
-
this.logger?.debug(`RFC close error: ${rfcErrorMessage(e)}`);
|
|
312
|
-
}
|
|
313
|
-
this.rfcClient = null;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
static validateConfig(config) {
|
|
317
|
-
if (config.connectionType !== 'rfc') {
|
|
318
|
-
throw new Error(`RFC connection expects connectionType "rfc", got "${config.connectionType}"`);
|
|
319
|
-
}
|
|
320
|
-
if (!config.url) {
|
|
321
|
-
throw new Error('RFC connection requires url (hostname is parsed from it)');
|
|
322
|
-
}
|
|
323
|
-
if (!config.username || !config.password) {
|
|
324
|
-
throw new Error('RFC connection requires both username and password');
|
|
325
|
-
}
|
|
326
|
-
if (!config.client) {
|
|
327
|
-
throw new Error('RFC connection requires SAP client');
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
exports.RfcAbapConnection = RfcAbapConnection;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { SapConfig } from '../config/sapConfig.js';
|
|
2
|
-
import type { ILogger } from '../logger.js';
|
|
3
|
-
import { AbstractAbapConnection } from './AbstractAbapConnection.js';
|
|
4
|
-
/**
|
|
5
|
-
* SAML session cookie authentication for SAP systems
|
|
6
|
-
*/
|
|
7
|
-
export declare class SamlAbapConnection extends AbstractAbapConnection {
|
|
8
|
-
private sessionCookies;
|
|
9
|
-
constructor(config: SapConfig, logger?: ILogger | null, sessionId?: string, options?: {
|
|
10
|
-
skipSessionType?: boolean;
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* Connect to SAP system using existing session cookies
|
|
14
|
-
* Fetches CSRF token to establish session context
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Establishes the session for this auth type. Called by
|
|
18
|
-
* AbstractAbapConnection.connect(), which owns the lifecycle around it.
|
|
19
|
-
*/
|
|
20
|
-
protected establishSession(): Promise<void>;
|
|
21
|
-
protected buildAuthorizationHeader(): string;
|
|
22
|
-
getAuthHeaders(): Promise<Record<string, string>>;
|
|
23
|
-
private static validateConfig;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=SamlAbapConnection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SamlAbapConnection.d.ts","sourceRoot":"","sources":["../../src/connection/SamlAbapConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,sBAAsB;IAC5D,OAAO,CAAC,cAAc,CAAS;gBAG7B,MAAM,EAAE,SAAS,EACjB,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,EACvB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,OAAO,CAAA;KAAE;IAUzC;;;OAGG;IACH;;;OAGG;cACa,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAwCjD,SAAS,CAAC,wBAAwB,IAAI,MAAM;IAItC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAQvD,OAAO,CAAC,MAAM,CAAC,cAAc;CAW9B"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SamlAbapConnection = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
|
-
const AbstractAbapConnection_js_1 = require("./AbstractAbapConnection.js");
|
|
6
|
-
/**
|
|
7
|
-
* SAML session cookie authentication for SAP systems
|
|
8
|
-
*/
|
|
9
|
-
class SamlAbapConnection extends AbstractAbapConnection_js_1.AbstractAbapConnection {
|
|
10
|
-
sessionCookies;
|
|
11
|
-
constructor(config, logger, sessionId, options) {
|
|
12
|
-
SamlAbapConnection.validateConfig(config);
|
|
13
|
-
super(config, logger || null, sessionId, options);
|
|
14
|
-
this.sessionCookies = config.sessionCookies || '';
|
|
15
|
-
if (this.sessionCookies) {
|
|
16
|
-
this.setInitialCookies(this.sessionCookies);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Connect to SAP system using existing session cookies
|
|
21
|
-
* Fetches CSRF token to establish session context
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* Establishes the session for this auth type. Called by
|
|
25
|
-
* AbstractAbapConnection.connect(), which owns the lifecycle around it.
|
|
26
|
-
*/
|
|
27
|
-
async establishSession() {
|
|
28
|
-
const baseUrl = await this.getBaseUrl();
|
|
29
|
-
const discoveryUrl = `${baseUrl}/sap/bc/adt/discovery`;
|
|
30
|
-
this.logger?.debug(`[DEBUG] SamlAbapConnection - Connecting to SAP system: ${discoveryUrl}`);
|
|
31
|
-
try {
|
|
32
|
-
const token = await this.fetchCsrfToken(discoveryUrl);
|
|
33
|
-
this.setCsrfToken(token);
|
|
34
|
-
this.logger?.debug('Successfully connected to SAP system', {
|
|
35
|
-
hasCsrfToken: !!this.getCsrfToken(),
|
|
36
|
-
hasCookies: !!this.getCookies(),
|
|
37
|
-
cookieLength: this.getCookies()?.length || 0,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
42
|
-
this.logger?.warn(`[WARN] SamlAbapConnection - Could not connect to SAP system upfront: ${errorMsg}. Will retry on first request.`);
|
|
43
|
-
if (error instanceof axios_1.AxiosError && error.response?.headers) {
|
|
44
|
-
if (this.getCookies()) {
|
|
45
|
-
this.logger?.debug(`[DEBUG] SamlAbapConnection - Cookies extracted from error response during connect (first 100 chars): ${this.getCookies()?.substring(0, 100)}...`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// Rethrow: a resolved connect() must mean a usable session exists. This
|
|
49
|
-
// used to swallow and resolve anyway, deferring establishment to the
|
|
50
|
-
// first request — coherent only while that lazy path existed. Without it,
|
|
51
|
-
// swallowing would leave a connection that reports success, holds
|
|
52
|
-
// nothing, and refuses every request.
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
buildAuthorizationHeader() {
|
|
57
|
-
return '';
|
|
58
|
-
}
|
|
59
|
-
async getAuthHeaders() {
|
|
60
|
-
const headers = await super.getAuthHeaders();
|
|
61
|
-
if (this.sessionCookies) {
|
|
62
|
-
headers.Cookie = this.sessionCookies;
|
|
63
|
-
}
|
|
64
|
-
return headers;
|
|
65
|
-
}
|
|
66
|
-
static validateConfig(config) {
|
|
67
|
-
if (config.authType !== 'saml') {
|
|
68
|
-
throw new Error(`SAML connection expects authType "saml", got "${config.authType}"`);
|
|
69
|
-
}
|
|
70
|
-
if (!config.sessionCookies) {
|
|
71
|
-
throw new Error('SAML authentication requires sessionCookies');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.SamlAbapConnection = SamlAbapConnection;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ICertificateMaterialLoader, ITokenRefresher } from '@mcp-abap-adt/interfaces';
|
|
2
|
-
import type { SapConfig } from '../config/sapConfig.js';
|
|
3
|
-
import type { ILogger } from '../logger.js';
|
|
4
|
-
import type { AbapConnection } from './AbapConnection.js';
|
|
5
|
-
export declare function createAbapConnection(config: SapConfig, logger?: ILogger | null, sessionId?: string, tokenRefresher?: ITokenRefresher, options?: {
|
|
6
|
-
skipSessionType?: boolean;
|
|
7
|
-
certLoader?: ICertificateMaterialLoader;
|
|
8
|
-
}): AbapConnection;
|
|
9
|
-
//# sourceMappingURL=connectionFactory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connectionFactory.d.ts","sourceRoot":"","sources":["../../src/connection/connectionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQ1D,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,EACvB,SAAS,CAAC,EAAE,MAAM,EAClB,cAAc,CAAC,EAAE,eAAe,EAChC,OAAO,CAAC,EAAE;IACR,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,0BAA0B,CAAC;CACzC,GACA,cAAc,CAgChB"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAbapConnection = createAbapConnection;
|
|
4
|
-
const BaseAbapConnection_js_1 = require("./BaseAbapConnection.js");
|
|
5
|
-
const CertificateAbapConnection_js_1 = require("./CertificateAbapConnection.js");
|
|
6
|
-
const JwtAbapConnection_js_1 = require("./JwtAbapConnection.js");
|
|
7
|
-
const KerberosAbapConnection_js_1 = require("./KerberosAbapConnection.js");
|
|
8
|
-
const RfcAbapConnection_js_1 = require("./RfcAbapConnection.js");
|
|
9
|
-
const SamlAbapConnection_js_1 = require("./SamlAbapConnection.js");
|
|
10
|
-
function createAbapConnection(config, logger, sessionId, tokenRefresher, options) {
|
|
11
|
-
// RFC connection type takes priority over auth type
|
|
12
|
-
if (config.connectionType === 'rfc') {
|
|
13
|
-
if (config.authType === 'certificate' || config.authType === 'kerberos') {
|
|
14
|
-
throw new Error(`authType "${config.authType}" is not supported with connectionType "rfc".`);
|
|
15
|
-
}
|
|
16
|
-
return new RfcAbapConnection_js_1.RfcAbapConnection(config, logger);
|
|
17
|
-
}
|
|
18
|
-
switch (config.authType) {
|
|
19
|
-
case 'basic':
|
|
20
|
-
return new BaseAbapConnection_js_1.BaseAbapConnection(config, logger, sessionId, options);
|
|
21
|
-
case 'jwt':
|
|
22
|
-
return new JwtAbapConnection_js_1.JwtAbapConnection(config, logger, sessionId, tokenRefresher);
|
|
23
|
-
case 'saml':
|
|
24
|
-
return new SamlAbapConnection_js_1.SamlAbapConnection(config, logger, sessionId, options);
|
|
25
|
-
case 'certificate':
|
|
26
|
-
return new CertificateAbapConnection_js_1.CertificateAbapConnection(config, logger, sessionId, options?.certLoader);
|
|
27
|
-
case 'kerberos':
|
|
28
|
-
return new KerberosAbapConnection_js_1.KerberosAbapConnection(config, logger, sessionId);
|
|
29
|
-
default:
|
|
30
|
-
throw new Error(`Unsupported SAP authentication type: ${config.authType}`);
|
|
31
|
-
}
|
|
32
|
-
}
|