@mcp-abap-adt/connection 15.1.0 → 17.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 +187 -1
- package/README.md +137 -33
- package/dist/connection/AbstractAbapConnection.d.ts +140 -58
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +349 -255
- package/dist/connection/AdtCloudConnector.d.ts +6 -1
- package/dist/connection/AdtCloudConnector.d.ts.map +1 -1
- package/dist/connection/AdtCloudConnector.js +7 -2
- package/dist/connection/AdtOnPremConnector.d.ts +6 -1
- package/dist/connection/AdtOnPremConnector.d.ts.map +1 -1
- package/dist/connection/AdtOnPremConnector.js +7 -2
- package/dist/connection/CloudHttpTransport.d.ts +8 -1
- package/dist/connection/CloudHttpTransport.d.ts.map +1 -1
- package/dist/connection/CloudHttpTransport.js +30 -18
- package/dist/connection/CredentialAbapConnection.d.ts +3 -1
- package/dist/connection/CredentialAbapConnection.d.ts.map +1 -1
- package/dist/connection/CredentialAbapConnection.js +4 -2
- package/dist/connection/GenericWebSocketTransport.d.ts.map +1 -1
- package/dist/connection/GenericWebSocketTransport.js +7 -4
- package/dist/connection/HttpTransport.d.ts +80 -6
- package/dist/connection/HttpTransport.d.ts.map +1 -1
- package/dist/connection/HttpTransport.js +258 -25
- package/dist/connection/IAdtTransport.d.ts +46 -22
- package/dist/connection/IAdtTransport.d.ts.map +1 -1
- package/dist/connection/OnPremHttpTransport.d.ts +2 -13
- package/dist/connection/OnPremHttpTransport.d.ts.map +1 -1
- package/dist/connection/OnPremHttpTransport.js +16 -32
- package/dist/connection/RfcTransport.d.ts +7 -6
- package/dist/connection/RfcTransport.d.ts.map +1 -1
- package/dist/connection/RfcTransport.js +27 -49
- package/dist/connection/createConnection.d.ts +95 -0
- package/dist/connection/createConnection.d.ts.map +1 -0
- package/dist/connection/createConnection.js +44 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/docs/INDEX.md +6 -2
- package/docs/MIGRATION-16.0.md +123 -0
- package/docs/MIGRATION-17.0.md +119 -0
- package/docs/SCOPE.md +22 -45
- package/docs/STATEFUL_SESSION_GUIDE.md +49 -49
- package/docs/USAGE.md +244 -120
- package/package.json +2 -2
- package/dist/connection/requestAbort.d.ts +0 -32
- package/dist/connection/requestAbort.d.ts.map +0 -1
- package/dist/connection/requestAbort.js +0 -69
- package/dist/utils/timeouts.d.ts +0 -18
- package/dist/utils/timeouts.d.ts.map +0 -1
- package/dist/utils/timeouts.js +0 -37
package/docs/USAGE.md
CHANGED
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
import {
|
|
20
20
|
AdtOnPremConnector,
|
|
21
21
|
OnPremHttpTransport,
|
|
22
|
-
getTimeout,
|
|
23
22
|
} from '@mcp-abap-adt/connection';
|
|
24
23
|
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
25
24
|
import { SapConfig } from '@mcp-abap-adt/connection';
|
|
@@ -61,7 +60,7 @@ await connection.connect();
|
|
|
61
60
|
const response = await connection.makeAdtRequest({
|
|
62
61
|
method: 'GET',
|
|
63
62
|
url: '/sap/bc/adt/repository/nodestructure',
|
|
64
|
-
timeout:
|
|
63
|
+
timeout: 0,
|
|
65
64
|
});
|
|
66
65
|
|
|
67
66
|
console.log(response.data);
|
|
@@ -122,7 +121,6 @@ For SAP BTP ABAP Environment. Token refresh belongs to
|
|
|
122
121
|
import {
|
|
123
122
|
AdtCloudConnector,
|
|
124
123
|
CloudHttpTransport,
|
|
125
|
-
getTimeout,
|
|
126
124
|
} from '@mcp-abap-adt/connection';
|
|
127
125
|
import { TokenAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
128
126
|
|
|
@@ -151,10 +149,90 @@ await connection.connect(); // required: nothing is established implicitly
|
|
|
151
149
|
const response = await connection.makeAdtRequest({
|
|
152
150
|
method: 'GET',
|
|
153
151
|
url: '/sap/bc/adt/repository/nodestructure',
|
|
154
|
-
timeout:
|
|
152
|
+
timeout: 0,
|
|
155
153
|
});
|
|
156
154
|
```
|
|
157
155
|
|
|
156
|
+
## Building a connection: `createConnection`
|
|
157
|
+
|
|
158
|
+
The recommended way to build a connection. State the system and the wire, and
|
|
159
|
+
the factory picks the connector and the transport. Nothing is inferred:
|
|
160
|
+
|
|
161
|
+
| `system` | `transport` | builds |
|
|
162
|
+
|---|---|---|
|
|
163
|
+
| `cloud` | `http` | `AdtCloudConnector` over `CloudHttpTransport` |
|
|
164
|
+
| `onprem` | `http` | `AdtOnPremConnector` over `OnPremHttpTransport` |
|
|
165
|
+
| `onprem` | `legacy-http` | `AdtOnPremConnector` over `LegacyOnPremHttpTransport` (BASIS 7.40) |
|
|
166
|
+
| `onprem` | `rfc` | `AdtOnPremConnector` over `RfcTransport(rfcConversationFrom(config))` |
|
|
167
|
+
|
|
168
|
+
Any other combination is refused at construction with a `TypeError`.
|
|
169
|
+
`client` and `baseUrl` reach the HTTP wires from `config`. `agentOptions`,
|
|
170
|
+
`rfc`, `wireLogger`, `logger` and `sessionId` are passed through exactly as
|
|
171
|
+
you give them; whatever you leave out takes the constructors' own defaults.
|
|
172
|
+
|
|
173
|
+
**A new instance on every call.** One instance is one SAP session. After its
|
|
174
|
+
`disconnect()` it is spent, and the next session is the next
|
|
175
|
+
`createConnection(...)`. The constructors still work for anything the
|
|
176
|
+
factory does not name.
|
|
177
|
+
|
|
178
|
+
### An instance on an existing session: `session` and `sessionCookies()`
|
|
179
|
+
|
|
180
|
+
`sessionCookies()` returns the cookies of the instance's SAP session as one
|
|
181
|
+
`Cookie`-header string: `SAP_SESSIONID_*`, `sap-usercontext`, `sap-contextid`
|
|
182
|
+
when a stateful request opened a context, and whatever else the server set to
|
|
183
|
+
keep the session where it lives — everything the wire holds but `sap-XSRF_*`,
|
|
184
|
+
which belongs to the CSRF token and is earned again. It is `null` before a
|
|
185
|
+
session, after the session ended, and over RFC. The string acts as the user
|
|
186
|
+
for as long as the session lives: keep it as a secret. The package never logs
|
|
187
|
+
it.
|
|
188
|
+
|
|
189
|
+
Hand it back as `session` to build an instance on that session instead of a
|
|
190
|
+
new one (HTTP wires only — over RFC, whose session is a conversation, it is
|
|
191
|
+
refused at construction; an empty string is refused too):
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
const resumed = createConnection({
|
|
195
|
+
system: 'onprem',
|
|
196
|
+
transport: 'http',
|
|
197
|
+
config,
|
|
198
|
+
credential: new BasicAuthProvider(config.username, config.password),
|
|
199
|
+
session: keptCookies, // what an earlier instance's sessionCookies() returned
|
|
200
|
+
});
|
|
201
|
+
await resumed.connect();
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
What `connect()` does then:
|
|
205
|
+
|
|
206
|
+
1. It prepares the credential as always, and **logs on nowhere**.
|
|
207
|
+
2. It makes **one request in that session, without the credential**: the CSRF
|
|
208
|
+
fetch (`GET /sap/bc/adt/core/discovery` with `x-csrf-token: fetch`, the
|
|
209
|
+
fallback `/sap/bc/adt/discovery` on a `404`; on cloud with
|
|
210
|
+
`x-sap-security-session: use`, and no preflight), following no redirect.
|
|
211
|
+
Without the credential,
|
|
212
|
+
because a credential on that request would open a NEW session when the old
|
|
213
|
+
one is gone (measured: a dead session cookie with a good password gets a new
|
|
214
|
+
`SAP_SESSIONID`).
|
|
215
|
+
3. **Alive** — a CSRF token, and the `SAP_SESSIONID` that was handed over,
|
|
216
|
+
unchanged: the session is this instance's. A stateful request reaches the
|
|
217
|
+
ABAP context `sap-contextid` names (an `UNLOCK` lands in the old context);
|
|
218
|
+
later requests carry the credential as usual; a session lost later is
|
|
219
|
+
reported as for any instance (`ADT_SESSION_REPLACED`); `disconnect()` logs it
|
|
220
|
+
off as for any instance.
|
|
221
|
+
4. **Gone** — a `401`, a redirect (a `3xx` is not the session answering; it is
|
|
222
|
+
not followed, so its target is never asked and nothing it sets is taken), or
|
|
223
|
+
any answer that is not the session's (another `SAP_SESSIONID`, none, no
|
|
224
|
+
token): `connect()` rejects with SAP's answer as it is (`error.response`,
|
|
225
|
+
with the status and headers SAP gave). Nothing was opened, so nothing is logged off, and the
|
|
226
|
+
instance is spent.
|
|
227
|
+
|
|
228
|
+
The credential's logon moment (`establish`, which brings TLS material) is
|
|
229
|
+
offered only after the session answered, so it never rides on that request.
|
|
230
|
+
|
|
231
|
+
Wrapping the connection with your own HTTP request logging stays with the
|
|
232
|
+
consumer. That is a policy of yours, typically read from your environment, not
|
|
233
|
+
a property of the wire. The factory passes `wireLogger` to the transport,
|
|
234
|
+
which is the wire's own logging.
|
|
235
|
+
|
|
158
236
|
## Making ADT Requests
|
|
159
237
|
|
|
160
238
|
All requests are made using the `makeAdtRequest()` method. CSRF token handling
|
|
@@ -165,7 +243,6 @@ them is refused with `ADT_NOT_CONNECTED`.
|
|
|
165
243
|
### GET Request
|
|
166
244
|
|
|
167
245
|
```typescript
|
|
168
|
-
import { getTimeout } from '@mcp-abap-adt/connection';
|
|
169
246
|
// The body is XML: name its type, or the answer's `data` is `unknown`.
|
|
170
247
|
const packages = await connection.makeAdtRequest<string>({
|
|
171
248
|
method: 'GET',
|
|
@@ -175,14 +252,13 @@ const packages = await connection.makeAdtRequest<string>({
|
|
|
175
252
|
parent_type: 'DEVC/K',
|
|
176
253
|
withShortDescriptions: 'true',
|
|
177
254
|
},
|
|
178
|
-
timeout:
|
|
255
|
+
timeout: 0,
|
|
179
256
|
});
|
|
180
257
|
```
|
|
181
258
|
|
|
182
259
|
### POST Request (Create Object)
|
|
183
260
|
|
|
184
261
|
```typescript
|
|
185
|
-
import { getTimeout } from '@mcp-abap-adt/connection';
|
|
186
262
|
const classXml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
187
263
|
<class:abapClass xmlns:class="http://www.sap.com/adt/oo/classes"
|
|
188
264
|
class:name="ZCL_MY_CLASS">
|
|
@@ -195,7 +271,7 @@ const response = await connection.makeAdtRequest({
|
|
|
195
271
|
headers: { 'Content-Type': 'application/xml' },
|
|
196
272
|
data: classXml,
|
|
197
273
|
params: { package: 'ZTEST' },
|
|
198
|
-
timeout:
|
|
274
|
+
timeout: 0,
|
|
199
275
|
});
|
|
200
276
|
```
|
|
201
277
|
|
|
@@ -204,75 +280,27 @@ const response = await connection.makeAdtRequest({
|
|
|
204
280
|
```typescript
|
|
205
281
|
const classSourceCode = 'CLASS zcl_my_class DEFINITION ...';
|
|
206
282
|
const lockToken = 'the handle the lock call returned';
|
|
207
|
-
import { getTimeout } from '@mcp-abap-adt/connection';
|
|
208
283
|
await connection.makeAdtRequest({
|
|
209
284
|
method: 'PUT',
|
|
210
285
|
url: '/sap/bc/adt/oo/classes/zcl_my_class/source/main',
|
|
211
286
|
headers: { 'Content-Type': 'text/plain' },
|
|
212
287
|
data: classSourceCode, // the new source, as a string
|
|
213
288
|
params: { lockHandle: lockToken }, // from the lock you took first
|
|
214
|
-
timeout:
|
|
289
|
+
timeout: 0,
|
|
215
290
|
});
|
|
216
291
|
```
|
|
217
292
|
|
|
218
293
|
### DELETE Request
|
|
219
294
|
|
|
220
295
|
```typescript
|
|
221
|
-
import { getTimeout } from '@mcp-abap-adt/connection';
|
|
222
296
|
await connection.makeAdtRequest({
|
|
223
297
|
method: 'DELETE',
|
|
224
298
|
url: '/sap/bc/adt/oo/classes/zcl_my_class',
|
|
225
299
|
params: { deleteOption: 'deleteAndLocalVersions' },
|
|
226
|
-
timeout:
|
|
300
|
+
timeout: 0,
|
|
227
301
|
});
|
|
228
302
|
```
|
|
229
303
|
|
|
230
|
-
### Cancelling a request
|
|
231
|
-
|
|
232
|
-
A request takes the caller's `AbortSignal` as `signal`. It is checked at every
|
|
233
|
-
point where the request would send something — before the first send, before
|
|
234
|
-
every resend (the CSRF recovery's included) and before the provider is asked to
|
|
235
|
-
renew — and every wait the request makes races it: the provider's `authorize()`
|
|
236
|
-
and `rejected()`, a logon (`establish()`), the token exchange and, over RFC, the
|
|
237
|
-
`open()` of a conversation of its own. Once it aborts, nothing more of the
|
|
238
|
-
request is sent and the call rejects at once with `code: 'ADT_REQUEST_ABORTED'`
|
|
239
|
-
(`ADT_REQUEST_ERROR.ABORTED` from `@mcp-abap-adt/interfaces-adt-connection`),
|
|
240
|
-
in fixed words.
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
import { ADT_REQUEST_ERROR } from '@mcp-abap-adt/interfaces-adt-connection';
|
|
244
|
-
import { getTimeout } from '@mcp-abap-adt/connection';
|
|
245
|
-
const controller = new AbortController();
|
|
246
|
-
try {
|
|
247
|
-
await connection.makeAdtRequest<string>({
|
|
248
|
-
method: 'GET',
|
|
249
|
-
url: '/sap/bc/adt/repository/nodestructure',
|
|
250
|
-
timeout: getTimeout('default'),
|
|
251
|
-
signal: controller.signal,
|
|
252
|
-
});
|
|
253
|
-
} catch (error) {
|
|
254
|
-
if ((error as { code?: unknown }).code === ADT_REQUEST_ERROR.ABORTED) {
|
|
255
|
-
// Nothing more of it was sent. What was already sent may have been acted on.
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
What it does not do:
|
|
261
|
-
|
|
262
|
-
- **It does not recall a request already sent.** The server may act on it, and
|
|
263
|
-
its answer — success or failure — is still the caller's. Only what would
|
|
264
|
-
follow it (a resend, a renewal) is not sent.
|
|
265
|
-
- **It ends a wait for this caller only.** A provider's work behind it runs
|
|
266
|
-
on: a provider shares one renewal among every request it refused. Whatever
|
|
267
|
-
that work answers late is handled and dropped. A token exchange the request
|
|
268
|
-
started makes no further attempt once it aborts; one already on the wire is
|
|
269
|
-
not recalled, and the token it earns is the session's. A conversation an
|
|
270
|
-
RFC call opened for itself alone is closed when its `open()` answers.
|
|
271
|
-
- **It is not the deadline.** `timeout` still bounds a request on the HTTP wire;
|
|
272
|
-
the signal is the caller saying it no longer needs the answer.
|
|
273
|
-
|
|
274
|
-
Without a signal a request behaves exactly as before.
|
|
275
|
-
|
|
276
304
|
## Session Management
|
|
277
305
|
|
|
278
306
|
### Stateless Mode (Default)
|
|
@@ -280,7 +308,7 @@ Without a signal a request behaves exactly as before.
|
|
|
280
308
|
By default, connections are stateless - each request gets fresh cookies and CSRF tokens:
|
|
281
309
|
|
|
282
310
|
```typescript
|
|
283
|
-
import { AdtOnPremConnector, OnPremHttpTransport
|
|
311
|
+
import { AdtOnPremConnector, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
284
312
|
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
285
313
|
const connection = new AdtOnPremConnector(
|
|
286
314
|
config,
|
|
@@ -294,7 +322,7 @@ const connection = new AdtOnPremConnector(
|
|
|
294
322
|
await connection.connect();
|
|
295
323
|
|
|
296
324
|
// Each request is independent
|
|
297
|
-
await connection.makeAdtRequest({ method: 'GET', url: '/sap/bc/adt/discovery' , timeout:
|
|
325
|
+
await connection.makeAdtRequest({ method: 'GET', url: '/sap/bc/adt/discovery' , timeout: 0 });
|
|
298
326
|
```
|
|
299
327
|
|
|
300
328
|
### Stateful Mode (HTTP Context)
|
|
@@ -306,7 +334,7 @@ writes from running in the lock context and failing with PAK/058 or an invalid
|
|
|
306
334
|
lock handle. See [HTTP context isolation](./STATEFUL_SESSION_GUIDE.md#http-context-isolation-931).
|
|
307
335
|
|
|
308
336
|
```typescript
|
|
309
|
-
import { AdtOnPremConnector, OnPremHttpTransport
|
|
337
|
+
import { AdtOnPremConnector, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
310
338
|
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
311
339
|
const connection = new AdtOnPremConnector(
|
|
312
340
|
config,
|
|
@@ -323,7 +351,7 @@ await connection.connect();
|
|
|
323
351
|
connection.setSessionType('stateful');
|
|
324
352
|
|
|
325
353
|
// Following requests use the stateful context until the mode is changed
|
|
326
|
-
await connection.makeAdtRequest({ method: 'GET', url: '/sap/bc/adt/discovery' , timeout:
|
|
354
|
+
await connection.makeAdtRequest({ method: 'GET', url: '/sap/bc/adt/discovery' , timeout: 0 });
|
|
327
355
|
|
|
328
356
|
// Check session mode
|
|
329
357
|
console.log(connection.getSessionMode()); // 'stateful'
|
|
@@ -454,12 +482,11 @@ side instead of a condition that silently stops matching. The codes live in
|
|
|
454
482
|
|
|
455
483
|
```typescript
|
|
456
484
|
import { ADT_SESSION_ERROR } from '@mcp-abap-adt/interfaces-adt-connection';
|
|
457
|
-
import { getTimeout } from '@mcp-abap-adt/connection';
|
|
458
485
|
|
|
459
486
|
const options = {
|
|
460
487
|
method: 'GET',
|
|
461
488
|
url: '/sap/bc/adt/repository/nodestructure',
|
|
462
|
-
timeout:
|
|
489
|
+
timeout: 0,
|
|
463
490
|
};
|
|
464
491
|
|
|
465
492
|
try {
|
|
@@ -478,15 +505,45 @@ than on a concrete class where you can: an `IAbapConnection` may come from
|
|
|
478
505
|
somewhere that implements only the minimum, so the atom you require is also the
|
|
479
506
|
documentation of what your code actually needs.
|
|
480
507
|
|
|
481
|
-
### disconnect()
|
|
508
|
+
### disconnect() resolves once the logoff is written
|
|
482
509
|
|
|
483
510
|
```typescript
|
|
484
|
-
await connection.disconnect(); //
|
|
511
|
+
await connection.disconnect(); // the logoff has left
|
|
512
|
+
await connection.flushGoodbye(); // only if you need SAP's answer too; no bound
|
|
513
|
+
// await connection.flushGoodbye(5000); // a bound of your own, if you need one
|
|
485
514
|
```
|
|
486
515
|
|
|
487
|
-
It never throws,
|
|
488
|
-
|
|
489
|
-
|
|
516
|
+
It never throws, except on a second call (below). **It resolves once the logoff is written** — its bytes handed
|
|
517
|
+
to the socket; over RFC, once the close call has returned — **not when SAP
|
|
518
|
+
answers it**, and it does not wait for requests in flight or anything you hold.
|
|
519
|
+
Deciding when to disconnect is yours, and so is preparing for it.
|
|
520
|
+
|
|
521
|
+
Why the write and not the answer (measured on an on-premise system, 2026-10-12): with a long
|
|
522
|
+
request still running in the same stateful ABAP session, SAP queues the logoff
|
|
523
|
+
behind it and answers only afterwards — about 96 s in one run, nothing in six
|
|
524
|
+
minutes in another — yet once the logoff has arrived the ENQUEUE locks go
|
|
525
|
+
with it, even if the client is killed while the answer is pending. A
|
|
526
|
+
connection dropped *without* a logoff keeps its locks. Checked against 16.0.0
|
|
527
|
+
on an on-premise system on 2026-10-13: LOCK, a long where-used in the same stateful session,
|
|
528
|
+
`await disconnect()`, and the process exiting at once — the lock was still
|
|
529
|
+
held 1 s later and free ~70 s after the exit, long before the 30-minute idle
|
|
530
|
+
timeout: ICM ran the queued logoff after the connection had closed. So a
|
|
531
|
+
process about to exit awaits `disconnect()`; one that needs the server's
|
|
532
|
+
answer awaits `flushGoodbye()` as well — without an argument it waits as long
|
|
533
|
+
as SAP takes and sets no timer; `flushGoodbye(ms)` bounds the wait.
|
|
534
|
+
|
|
535
|
+
Nothing bounds the write with a timer: a server that never takes the bytes
|
|
536
|
+
holds `disconnect()` until the socket fails, and that failure is logged, not
|
|
537
|
+
thrown. "Written" means handed to the operating system, on a connection of
|
|
538
|
+
the logoff's own.
|
|
539
|
+
|
|
540
|
+
**Call it once per instance.** A second call, while the first is still
|
|
541
|
+
writing or after it, rejects with `ADT_SESSION_ERROR.NOT_CONNECTED`; the
|
|
542
|
+
first call is unaffected. A `connect()` that failed after the server opened
|
|
543
|
+
a session logs it off and rejects only after that logoff is written, so the
|
|
544
|
+
`disconnect()` in your `finally` is the first one of that life. Over RFC the
|
|
545
|
+
close waits for a call still running on its conversation (sap-rfc-lite
|
|
546
|
+
serialises them), so there it resolves after that call.
|
|
490
547
|
|
|
491
548
|
Requests already in flight run to completion untouched; nothing is aborted. What
|
|
492
549
|
the connection guarantees is that their results can no longer reach it: a
|
|
@@ -498,9 +555,45 @@ turned out to be unbounded — a request whose caller chose no timeout could hol
|
|
|
498
555
|
teardown open forever, and since lifecycle transitions are serialized, every
|
|
499
556
|
later `connect()` queued behind it.
|
|
500
557
|
|
|
501
|
-
**
|
|
502
|
-
|
|
503
|
-
|
|
558
|
+
**The logoff releases the locks** — once it has arrived, whether or not you
|
|
559
|
+
wait for the answer (measured on an on-premise system). Still unlock what you locked first:
|
|
560
|
+
the logoff is the backstop, not the way to finish your work.
|
|
561
|
+
|
|
562
|
+
### When the logoff is sent
|
|
563
|
+
|
|
564
|
+
1. `disconnect()` sends it iff the connection holds a live `SAP_SESSIONID_*` —
|
|
565
|
+
received, not deleted by a past `expires` / `Max-Age=0`. After a successful
|
|
566
|
+
`connect()` over `http` (on-premise or cloud) it does: such a connect
|
|
567
|
+
requires one. Over `legacy-http` a `connect()` succeeds on a system that
|
|
568
|
+
names no session, and then there is no `SAP_SESSIONID_*` and nothing is
|
|
569
|
+
sent. With only `sap-XSRF_*` nothing is sent either.
|
|
570
|
+
2. A failed `connect()` sends it itself only when both hold: the whole
|
|
571
|
+
`connect()` failed (both `/sap/bc/adt/core/discovery` and the fallback
|
|
572
|
+
`/sap/bc/adt/discovery`), and a live `SAP_SESSIONID_*` was received during
|
|
573
|
+
it (a 403/404 after a successful logon carries one: measured on-premise,
|
|
574
|
+
`CL_HTTP_SERVER_NET->send_response` sets it whatever the status).
|
|
575
|
+
`connect()` then rejects after the logoff is written. A 401 means no
|
|
576
|
+
session: nothing.
|
|
577
|
+
|
|
578
|
+
**A failed `connect()` spends the instance whenever it received a session
|
|
579
|
+
cookie** — the wire reports a non-empty `SAP_SESSIONID_*` (over RFC, an
|
|
580
|
+
open conversation) — even when no logoff was sent: a custom wire's
|
|
581
|
+
`close()` may send none, and a logoff that fails is only logged. A failed
|
|
582
|
+
`connect()` that received none leaves the instance usable, and may be
|
|
583
|
+
retried.
|
|
584
|
+
3. A successful `connect()` (200) sends no logoff; the session lives until
|
|
585
|
+
`disconnect()`.
|
|
586
|
+
4. Where it goes: on-premise, the platform's ICF logoff
|
|
587
|
+
(`/sap/public/bc/icf/logoff`). On cloud, the logoff resource the session
|
|
588
|
+
document links to; when it links none, the same ICF logoff, sent exactly as
|
|
589
|
+
on-premise. Nothing is left to the server's timeout while a live
|
|
590
|
+
`SAP_SESSIONID_*` is held.
|
|
591
|
+
|
|
592
|
+
The logoff never carries `sap-contextid` — only `SAP_SESSIONID_*`,
|
|
593
|
+
`sap-usercontext` and the affinity it needs. Measured on an on-premise system with bare HTTP
|
|
594
|
+
(2026-10-13): a logoff without the context cookie ended the context and
|
|
595
|
+
released its lock; one carrying a stale (deleted) `sap-contextid` got 400 and
|
|
596
|
+
closed nothing.
|
|
504
597
|
|
|
505
598
|
### Uninterruptible spans
|
|
506
599
|
|
|
@@ -508,10 +601,11 @@ The connection does **not** track locks — it does not know one exists, what
|
|
|
508
601
|
object it covers, or what would release it. Pairing every LOCK with its UNLOCK is
|
|
509
602
|
`@mcp-abap-adt/adt-clients`' job, and it does it per object in its lock registry.
|
|
510
603
|
|
|
511
|
-
What this layer owns is
|
|
512
|
-
|
|
513
|
-
leaves an operation whose outcome you cannot
|
|
514
|
-
succeeded server-side, with a handle you
|
|
604
|
+
What this layer owns is that no deadline cuts such a span. A client deadline
|
|
605
|
+
closes the socket, and SAP then ends the synchronous request running on it — a
|
|
606
|
+
write in it lost — and leaves you an operation whose outcome you cannot
|
|
607
|
+
determine: a `LOCK` that may have succeeded server-side, with a handle you
|
|
608
|
+
never received:
|
|
515
609
|
|
|
516
610
|
```typescript
|
|
517
611
|
connection.beginCriticalSection();
|
|
@@ -524,31 +618,30 @@ try {
|
|
|
524
618
|
}
|
|
525
619
|
```
|
|
526
620
|
|
|
527
|
-
While a section is active
|
|
528
|
-
`
|
|
529
|
-
|
|
621
|
+
While a section is active a request carries **no deadline at all** — not the
|
|
622
|
+
`timeout` you passed either, and no ceiling of the package's own (17.0.0
|
|
623
|
+
removed `SAP_TIMEOUT_CRITICAL`). The pair is reference-counted, so nesting is
|
|
530
624
|
safe.
|
|
531
625
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
locked object. Those requests share one ABAP session, and
|
|
535
|
-
session in the same uncertain state during a span someone declared
|
|
536
|
-
precisely to avoid it.
|
|
626
|
+
This is **connection-wide**: while any section is active, every request on that
|
|
627
|
+
connection goes without a deadline, including one that has nothing to do with
|
|
628
|
+
the locked object. Those requests share one ABAP session, and a cut one leaves
|
|
629
|
+
that session in the same uncertain state during a span someone declared
|
|
630
|
+
sensitive precisely to avoid it.
|
|
631
|
+
|
|
632
|
+
Outside a section a request carries the `timeout` you passed, unchanged, and
|
|
633
|
+
nothing else: the CSRF fetch and the cloud preflight carry none either.
|
|
634
|
+
`IAbapRequestOptions.timeout` is still a required field of the contract; `0` is
|
|
635
|
+
none over HTTP, and the RFC wire reads it not at all.
|
|
537
636
|
|
|
538
637
|
### When the session is lost
|
|
539
638
|
|
|
540
639
|
Two different things can cost you the session, and they do not behave alike.
|
|
541
640
|
|
|
542
|
-
**The session was replaced** — a session cookie that changed
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
// no window → transparent; work continues on the new session
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
With nothing held there is nothing to lose, so the connector carries on. The
|
|
550
|
-
error exists to tell you that a lock handle you are carrying is now dead, which
|
|
551
|
-
is the one thing you cannot work out for yourself.
|
|
641
|
+
**The session was replaced** — a session cookie (`SAP_SESSIONID`) that changed
|
|
642
|
+
underneath you. The request rejects with `ADT_SESSION_REPLACED`: a lock handle
|
|
643
|
+
you are carrying is now dead, which is the one thing you cannot work out for
|
|
644
|
+
yourself.
|
|
552
645
|
|
|
553
646
|
**The server says the session is gone** — an answer meaning the session it was
|
|
554
647
|
given no longer exists. This is **always** fatal, window or not: the connection
|
|
@@ -561,6 +654,13 @@ In both cases the connector does **not** retry the request internally. Retrying
|
|
|
561
654
|
blindly is what produced further orphaned locks in the field. That decision is
|
|
562
655
|
yours.
|
|
563
656
|
|
|
657
|
+
**A lost session spends the instance** (since 16.0.0), as `disconnect()` does.
|
|
658
|
+
After either of these, `connect()` and every request on the instance reject
|
|
659
|
+
`ADT_SESSION_ERROR.NOT_CONNECTED`, and a new session is a new connection.
|
|
660
|
+
`disconnect()` is still owed once. It sends the logoff only if the instance
|
|
661
|
+
still holds a live `SAP_SESSIONID`, and after a loss the connection has
|
|
662
|
+
already cleared its cookies, so it sends nothing.
|
|
663
|
+
|
|
564
664
|
## Advanced Features
|
|
565
665
|
|
|
566
666
|
### Session ID Management
|
|
@@ -599,7 +699,7 @@ console.log(connectionWithOwnId.getSessionId()); // 'custom-session-123'
|
|
|
599
699
|
Dynamically switch between stateful and stateless modes:
|
|
600
700
|
|
|
601
701
|
```typescript
|
|
602
|
-
import { AdtOnPremConnector, OnPremHttpTransport
|
|
702
|
+
import { AdtOnPremConnector, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
603
703
|
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
604
704
|
// Start in stateless mode (default)
|
|
605
705
|
const connection = new AdtOnPremConnector(
|
|
@@ -617,7 +717,7 @@ await connection.connect();
|
|
|
617
717
|
connection.setSessionType('stateful');
|
|
618
718
|
|
|
619
719
|
// Do stateful operations...
|
|
620
|
-
await connection.makeAdtRequest({ method: 'POST', url: '...' , timeout:
|
|
720
|
+
await connection.makeAdtRequest({ method: 'POST', url: '...' , timeout: 0 });
|
|
621
721
|
|
|
622
722
|
// Switch back to stateless
|
|
623
723
|
connection.setSessionType('stateless');
|
|
@@ -627,15 +727,31 @@ connection.setSessionType('stateless');
|
|
|
627
727
|
|
|
628
728
|
There is no local-only reset. Discarding the cookie does not end the ABAP
|
|
629
729
|
session — the server keeps it until its own timeout, and sessions are limited
|
|
630
|
-
per user — so starting over means telling the server, then connecting
|
|
730
|
+
per user — so starting over means telling the server, then connecting a NEW
|
|
731
|
+
instance. One connection instance is one session: after `disconnect()` (or a
|
|
732
|
+
failed `connect()` that logged off its session) `connect()` on it rejects
|
|
733
|
+
`NOT_CONNECTED`. Creating the new instance is yours — your own factory, or
|
|
734
|
+
`createConnection` — as mcp-abap-adt's server does with `createAbapConnection`
|
|
735
|
+
per connection:
|
|
631
736
|
|
|
632
737
|
```typescript
|
|
633
738
|
await connection.disconnect(); // ends the session on the server too
|
|
634
|
-
|
|
739
|
+
const next = new AdtOnPremConnector(
|
|
740
|
+
config,
|
|
741
|
+
new BasicAuthProvider(config.username!, config.password!),
|
|
742
|
+
new OnPremHttpTransport(() => ({}), logger, {
|
|
743
|
+
client: config.client,
|
|
744
|
+
baseUrl: config.url,
|
|
745
|
+
}),
|
|
746
|
+
logger,
|
|
747
|
+
);
|
|
748
|
+
await next.connect(); // a new session is a new instance
|
|
635
749
|
```
|
|
636
750
|
|
|
637
751
|
A connection that was connected must be disconnected, which is why this belongs
|
|
638
|
-
in a `finally`. `disconnect()` never throws, so it is safe there
|
|
752
|
+
in a `finally`. The first `disconnect()` never throws, so it is safe there; a
|
|
753
|
+
second call on the same instance rejects `NOT_CONNECTED`, so let one path own
|
|
754
|
+
the call.
|
|
639
755
|
|
|
640
756
|
## Custom Logging
|
|
641
757
|
|
|
@@ -682,12 +798,11 @@ const connection = new AdtOnPremConnector(
|
|
|
682
798
|
### Basic Error Handling
|
|
683
799
|
|
|
684
800
|
```typescript
|
|
685
|
-
import { getTimeout } from '@mcp-abap-adt/connection';
|
|
686
801
|
try {
|
|
687
802
|
await connection.makeAdtRequest({
|
|
688
803
|
method: 'GET',
|
|
689
804
|
url: '/sap/bc/adt/invalid/endpoint',
|
|
690
|
-
timeout:
|
|
805
|
+
timeout: 0,
|
|
691
806
|
});
|
|
692
807
|
} catch (error) {
|
|
693
808
|
const failure = error as {
|
|
@@ -720,12 +835,11 @@ When these errors occur, the connection:
|
|
|
720
835
|
3. **Logs the error** with full context for troubleshooting
|
|
721
836
|
|
|
722
837
|
```typescript
|
|
723
|
-
import { getTimeout } from '@mcp-abap-adt/connection';
|
|
724
838
|
try {
|
|
725
839
|
await connection.makeAdtRequest({
|
|
726
840
|
method: 'GET',
|
|
727
841
|
url: '/sap/bc/adt/repository/nodestructure',
|
|
728
|
-
timeout:
|
|
842
|
+
timeout: 0,
|
|
729
843
|
});
|
|
730
844
|
} catch (error) {
|
|
731
845
|
const failure = error as {
|
|
@@ -798,6 +912,7 @@ class AdtOnPremConnector<
|
|
|
798
912
|
transport: TTransport,
|
|
799
913
|
logger?: ILogger | null,
|
|
800
914
|
sessionId?: string,
|
|
915
|
+
session?: string, // an existing session to take over; HTTP wires only
|
|
801
916
|
);
|
|
802
917
|
}
|
|
803
918
|
|
|
@@ -811,6 +926,7 @@ class AdtCloudConnector<
|
|
|
811
926
|
transport: TTransport,
|
|
812
927
|
logger?: ILogger | null,
|
|
813
928
|
sessionId?: string,
|
|
929
|
+
session?: string, // an existing session to take over
|
|
814
930
|
);
|
|
815
931
|
}
|
|
816
932
|
```
|
|
@@ -818,7 +934,8 @@ class AdtCloudConnector<
|
|
|
818
934
|
The difference is what each does with the session: on-prem takes it from the
|
|
819
935
|
establishing call and gives it back with the platform's ICF logoff; cloud opens
|
|
820
936
|
one at `/sap/bc/adt/core/http/sessions` and gives it back through the logoff
|
|
821
|
-
resource the server links to in the same answer
|
|
937
|
+
resource the server links to in the same answer — or, when it links none, with
|
|
938
|
+
the platform's ICF logoff, sent exactly as on-prem. Not by `DELETE` on the
|
|
822
939
|
session's own address: from inside that session it answers `200` and ends
|
|
823
940
|
nothing (measured on a BTP trial, 2026-10-12).
|
|
824
941
|
|
|
@@ -1012,8 +1129,8 @@ token the provider renewed is on the very next attempt.
|
|
|
1012
1129
|
|
|
1013
1130
|
| answer | what happens |
|
|
1014
1131
|
|---|---|
|
|
1015
|
-
| **
|
|
1016
|
-
| **401**
|
|
1132
|
+
| **403** "CSRF token validation failed", or a **401** to a mutation that holds no CSRF token yet | the wire's own CSRF recovery: a token fetched in the same session (its cookies kept) and one resend. None of this discards the session or opens another |
|
|
1133
|
+
| any other **401** — a mutation's with a CSRF token cached included — or a logon the system refused | put to `provider.rejected({ at, status?, error })`. On Ok the request is authorized again and sent **once more**, in the same session; on no, `AuthRefusedError` carrying SAP's 401 as its cause |
|
|
1017
1134
|
| the same refusal after an Ok | the verdict. The provider is not asked again — asking would invite a second renewal — and you get an `AuthRefusedError` saying the credential was refused again after the provider renewed it |
|
|
1018
1135
|
| **403** | propagates untouched, never put to the provider. The server authenticated the caller and refused the action anyway, so a new credential is the same caller — usually the body names the authorization object |
|
|
1019
1136
|
| anything else | untouched |
|
|
@@ -1022,21 +1139,28 @@ The one more attempt keeps the request's own lease and generation, so
|
|
|
1022
1139
|
stale-request fencing applies to it: a request from a superseded session asks
|
|
1023
1140
|
nobody and gets its error back. After a rejection `at: 'request'` it goes out on
|
|
1024
1141
|
the same session; after a rejection `at: 'logon'` the wire logs on again — token
|
|
1025
|
-
dropped, established anew — before the resend.
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1142
|
+
dropped, established anew — before the resend.
|
|
1143
|
+
|
|
1144
|
+
**No 401 opens a new session.** One instance is one session: nothing discards
|
|
1145
|
+
the session's cookies to open another and retry there. A mutation that meets a
|
|
1146
|
+
401 with a CSRF token cached is put to the provider like any other 401; on Ok it
|
|
1147
|
+
is resent on the same session with the same token, inside a critical section or
|
|
1148
|
+
not, and if SAP did replace the session the request fails with
|
|
1149
|
+
`SESSION_REPLACED`. Before 16.0.0, outside a critical section, that mutation
|
|
1150
|
+
discarded the session and retried in a new one on the same instance, a GET
|
|
1151
|
+
401 on a wire with no cookies fetched a token to open one, and a GET 401 with
|
|
1152
|
+
cookies held was resent once before the provider was asked; all three are
|
|
1153
|
+
gone. If you
|
|
1154
|
+
want a new session after a 401, create a new connection.
|
|
1155
|
+
|
|
1156
|
+
**A dead session can look like a refused credential.** When SAP answers the
|
|
1157
|
+
resend with the same session cookie and no `Set-Cookie`, the connection cannot
|
|
1158
|
+
tell a dead session from a refused credential: the 401 comes back a second time,
|
|
1159
|
+
and the request ends as `AuthRefusedError` with the refused-again verdict
|
|
1036
1160
|
(`at: 'request'`), not `SESSION_REPLACED`. The connection stays connected on
|
|
1037
|
-
that session. If you
|
|
1038
|
-
|
|
1039
|
-
|
|
1161
|
+
that session. If you suspect the session is gone, `disconnect()` and create a
|
|
1162
|
+
new connection; if you held a lock, treat it as lost and redo the work under a
|
|
1163
|
+
new lock there.
|
|
1040
1164
|
|
|
1041
1165
|
One credential retry per request: the upfront token fetch before a mutation and
|
|
1042
1166
|
a later rejection draw on the same allowance.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-abap-adt/connection",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "ABAP connection layer for MCP ABAP ADT server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@mcp-abap-adt/auth-errors": "^2.2.1",
|
|
54
|
-
"@mcp-abap-adt/interfaces-adt-connection": "^
|
|
54
|
+
"@mcp-abap-adt/interfaces-adt-connection": "^3.0.0",
|
|
55
55
|
"@mcp-abap-adt/interfaces-auth": "^7.5.0",
|
|
56
56
|
"@mcp-abap-adt/interfaces-auth-sap": "^3.3.0",
|
|
57
57
|
"@mcp-abap-adt/interfaces-network": "^2.0.1",
|