@mcp-abap-adt/connection 15.0.1 → 16.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 +68 -9
- package/dist/connection/AbstractAbapConnection.d.ts +86 -31
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +216 -136
- package/dist/connection/CloudHttpTransport.d.ts +8 -1
- package/dist/connection/CloudHttpTransport.d.ts.map +1 -1
- package/dist/connection/CloudHttpTransport.js +28 -15
- package/dist/connection/HttpTransport.d.ts +61 -6
- package/dist/connection/HttpTransport.d.ts.map +1 -1
- package/dist/connection/HttpTransport.js +144 -15
- package/dist/connection/IAdtTransport.d.ts +12 -1
- 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/createConnection.d.ts +77 -0
- package/dist/connection/createConnection.d.ts.map +1 -0
- package/dist/connection/createConnection.js +39 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/docs/INDEX.md +4 -2
- package/docs/MIGRATION-16.0.md +123 -0
- package/docs/SCOPE.md +17 -45
- package/docs/STATEFUL_SESSION_GUIDE.md +37 -29
- package/docs/USAGE.md +156 -38
- package/package.json +2 -2
package/docs/USAGE.md
CHANGED
|
@@ -155,6 +155,33 @@ const response = await connection.makeAdtRequest({
|
|
|
155
155
|
});
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
## Building a connection: `createConnection`
|
|
159
|
+
|
|
160
|
+
The recommended way to build a connection. State the system and the wire, and
|
|
161
|
+
the factory picks the connector and the transport. Nothing is inferred:
|
|
162
|
+
|
|
163
|
+
| `system` | `transport` | builds |
|
|
164
|
+
|---|---|---|
|
|
165
|
+
| `cloud` | `http` | `AdtCloudConnector` over `CloudHttpTransport` |
|
|
166
|
+
| `onprem` | `http` | `AdtOnPremConnector` over `OnPremHttpTransport` |
|
|
167
|
+
| `onprem` | `legacy-http` | `AdtOnPremConnector` over `LegacyOnPremHttpTransport` (BASIS 7.40) |
|
|
168
|
+
| `onprem` | `rfc` | `AdtOnPremConnector` over `RfcTransport(rfcConversationFrom(config))` |
|
|
169
|
+
|
|
170
|
+
Any other combination is refused at construction with a `TypeError`.
|
|
171
|
+
`client` and `baseUrl` reach the HTTP wires from `config`. `agentOptions`,
|
|
172
|
+
`rfc`, `wireLogger`, `logger` and `sessionId` are passed through exactly as
|
|
173
|
+
you give them; whatever you leave out takes the constructors' own defaults.
|
|
174
|
+
|
|
175
|
+
**A new instance on every call.** One instance is one SAP session. After its
|
|
176
|
+
`disconnect()` it is spent, and the next session is the next
|
|
177
|
+
`createConnection(...)`. The constructors still work for anything the
|
|
178
|
+
factory does not name.
|
|
179
|
+
|
|
180
|
+
Wrapping the connection with your own HTTP request logging stays with the
|
|
181
|
+
consumer. That is a policy of yours, typically read from your environment, not
|
|
182
|
+
a property of the wire. The factory passes `wireLogger` to the transport,
|
|
183
|
+
which is the wire's own logging.
|
|
184
|
+
|
|
158
185
|
## Making ADT Requests
|
|
159
186
|
|
|
160
187
|
All requests are made using the `makeAdtRequest()` method. CSRF token handling
|
|
@@ -432,15 +459,45 @@ than on a concrete class where you can: an `IAbapConnection` may come from
|
|
|
432
459
|
somewhere that implements only the minimum, so the atom you require is also the
|
|
433
460
|
documentation of what your code actually needs.
|
|
434
461
|
|
|
435
|
-
### disconnect()
|
|
462
|
+
### disconnect() resolves once the logoff is written
|
|
436
463
|
|
|
437
464
|
```typescript
|
|
438
|
-
await connection.disconnect(); //
|
|
465
|
+
await connection.disconnect(); // the logoff has left
|
|
466
|
+
await connection.flushGoodbye(); // only if you need SAP's answer too; no bound
|
|
467
|
+
// await connection.flushGoodbye(5000); // a bound of your own, if you need one
|
|
439
468
|
```
|
|
440
469
|
|
|
441
|
-
It never throws,
|
|
442
|
-
|
|
443
|
-
|
|
470
|
+
It never throws, except on a second call (below). **It resolves once the logoff is written** — its bytes handed
|
|
471
|
+
to the socket; over RFC, once the close call has returned — **not when SAP
|
|
472
|
+
answers it**, and it does not wait for requests in flight or anything you hold.
|
|
473
|
+
Deciding when to disconnect is yours, and so is preparing for it.
|
|
474
|
+
|
|
475
|
+
Why the write and not the answer (measured on an on-premise system, 2026-10-12): with a long
|
|
476
|
+
request still running in the same stateful ABAP session, SAP queues the logoff
|
|
477
|
+
behind it and answers only afterwards — about 96 s in one run, nothing in six
|
|
478
|
+
minutes in another — yet once the logoff has arrived the ENQUEUE locks go
|
|
479
|
+
with it, even if the client is killed while the answer is pending. A
|
|
480
|
+
connection dropped *without* a logoff keeps its locks. Checked against 16.0.0
|
|
481
|
+
on an on-premise system on 2026-10-13: LOCK, a long where-used in the same stateful session,
|
|
482
|
+
`await disconnect()`, and the process exiting at once — the lock was still
|
|
483
|
+
held 1 s later and free ~70 s after the exit, long before the 30-minute idle
|
|
484
|
+
timeout: ICM ran the queued logoff after the connection had closed. So a
|
|
485
|
+
process about to exit awaits `disconnect()`; one that needs the server's
|
|
486
|
+
answer awaits `flushGoodbye()` as well — without an argument it waits as long
|
|
487
|
+
as SAP takes and sets no timer; `flushGoodbye(ms)` bounds the wait.
|
|
488
|
+
|
|
489
|
+
Nothing bounds the write with a timer: a server that never takes the bytes
|
|
490
|
+
holds `disconnect()` until the socket fails, and that failure is logged, not
|
|
491
|
+
thrown. "Written" means handed to the operating system, on a connection of
|
|
492
|
+
the logoff's own.
|
|
493
|
+
|
|
494
|
+
**Call it once per instance.** A second call, while the first is still
|
|
495
|
+
writing or after it, rejects with `ADT_SESSION_ERROR.NOT_CONNECTED`; the
|
|
496
|
+
first call is unaffected. A `connect()` that failed after the server opened
|
|
497
|
+
a session logs it off and rejects only after that logoff is written, so the
|
|
498
|
+
`disconnect()` in your `finally` is the first one of that life. Over RFC the
|
|
499
|
+
close waits for a call still running on its conversation (sap-rfc-lite
|
|
500
|
+
serialises them), so there it resolves after that call.
|
|
444
501
|
|
|
445
502
|
Requests already in flight run to completion untouched; nothing is aborted. What
|
|
446
503
|
the connection guarantees is that their results can no longer reach it: a
|
|
@@ -452,9 +509,45 @@ turned out to be unbounded — a request whose caller chose no timeout could hol
|
|
|
452
509
|
teardown open forever, and since lifecycle transitions are serialized, every
|
|
453
510
|
later `connect()` queued behind it.
|
|
454
511
|
|
|
455
|
-
**
|
|
456
|
-
|
|
457
|
-
|
|
512
|
+
**The logoff releases the locks** — once it has arrived, whether or not you
|
|
513
|
+
wait for the answer (measured on an on-premise system). Still unlock what you locked first:
|
|
514
|
+
the logoff is the backstop, not the way to finish your work.
|
|
515
|
+
|
|
516
|
+
### When the logoff is sent
|
|
517
|
+
|
|
518
|
+
1. `disconnect()` sends it iff the connection holds a live `SAP_SESSIONID_*` —
|
|
519
|
+
received, not deleted by a past `expires` / `Max-Age=0`. After a successful
|
|
520
|
+
`connect()` over `http` (on-premise or cloud) it does: such a connect
|
|
521
|
+
requires one. Over `legacy-http` a `connect()` succeeds on a system that
|
|
522
|
+
names no session, and then there is no `SAP_SESSIONID_*` and nothing is
|
|
523
|
+
sent. With only `sap-XSRF_*` nothing is sent either.
|
|
524
|
+
2. A failed `connect()` sends it itself only when both hold: the whole
|
|
525
|
+
`connect()` failed (both `/sap/bc/adt/core/discovery` and the fallback
|
|
526
|
+
`/sap/bc/adt/discovery`), and a live `SAP_SESSIONID_*` was received during
|
|
527
|
+
it (a 403/404 after a successful logon carries one: measured on-premise,
|
|
528
|
+
`CL_HTTP_SERVER_NET->send_response` sets it whatever the status).
|
|
529
|
+
`connect()` then rejects after the logoff is written. A 401 means no
|
|
530
|
+
session: nothing.
|
|
531
|
+
|
|
532
|
+
**A failed `connect()` spends the instance whenever it received a session
|
|
533
|
+
cookie** — the wire reports a non-empty `SAP_SESSIONID_*` (over RFC, an
|
|
534
|
+
open conversation) — even when no logoff was sent: a custom wire's
|
|
535
|
+
`close()` may send none, and a logoff that fails is only logged. A failed
|
|
536
|
+
`connect()` that received none leaves the instance usable, and may be
|
|
537
|
+
retried.
|
|
538
|
+
3. A successful `connect()` (200) sends no logoff; the session lives until
|
|
539
|
+
`disconnect()`.
|
|
540
|
+
4. Where it goes: on-premise, the platform's ICF logoff
|
|
541
|
+
(`/sap/public/bc/icf/logoff`). On cloud, the logoff resource the session
|
|
542
|
+
document links to; when it links none, the same ICF logoff, sent exactly as
|
|
543
|
+
on-premise. Nothing is left to the server's timeout while a live
|
|
544
|
+
`SAP_SESSIONID_*` is held.
|
|
545
|
+
|
|
546
|
+
The logoff never carries `sap-contextid` — only `SAP_SESSIONID_*`,
|
|
547
|
+
`sap-usercontext` and the affinity it needs. Measured on an on-premise system with bare HTTP
|
|
548
|
+
(2026-10-13): a logoff without the context cookie ended the context and
|
|
549
|
+
released its lock; one carrying a stale (deleted) `sap-contextid` got 400 and
|
|
550
|
+
closed nothing.
|
|
458
551
|
|
|
459
552
|
### Uninterruptible spans
|
|
460
553
|
|
|
@@ -493,16 +586,10 @@ precisely to avoid it.
|
|
|
493
586
|
|
|
494
587
|
Two different things can cost you the session, and they do not behave alike.
|
|
495
588
|
|
|
496
|
-
**The session was replaced** — a session cookie that changed
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
// no window → transparent; work continues on the new session
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
With nothing held there is nothing to lose, so the connector carries on. The
|
|
504
|
-
error exists to tell you that a lock handle you are carrying is now dead, which
|
|
505
|
-
is the one thing you cannot work out for yourself.
|
|
589
|
+
**The session was replaced** — a session cookie (`SAP_SESSIONID`) that changed
|
|
590
|
+
underneath you. The request rejects with `ADT_SESSION_REPLACED`: a lock handle
|
|
591
|
+
you are carrying is now dead, which is the one thing you cannot work out for
|
|
592
|
+
yourself.
|
|
506
593
|
|
|
507
594
|
**The server says the session is gone** — an answer meaning the session it was
|
|
508
595
|
given no longer exists. This is **always** fatal, window or not: the connection
|
|
@@ -515,6 +602,13 @@ In both cases the connector does **not** retry the request internally. Retrying
|
|
|
515
602
|
blindly is what produced further orphaned locks in the field. That decision is
|
|
516
603
|
yours.
|
|
517
604
|
|
|
605
|
+
**A lost session spends the instance** (since 16.0.0), as `disconnect()` does.
|
|
606
|
+
After either of these, `connect()` and every request on the instance reject
|
|
607
|
+
`ADT_SESSION_ERROR.NOT_CONNECTED`, and a new session is a new connection.
|
|
608
|
+
`disconnect()` is still owed once. It sends the logoff only if the instance
|
|
609
|
+
still holds a live `SAP_SESSIONID`, and after a loss the connection has
|
|
610
|
+
already cleared its cookies, so it sends nothing.
|
|
611
|
+
|
|
518
612
|
## Advanced Features
|
|
519
613
|
|
|
520
614
|
### Session ID Management
|
|
@@ -581,15 +675,31 @@ connection.setSessionType('stateless');
|
|
|
581
675
|
|
|
582
676
|
There is no local-only reset. Discarding the cookie does not end the ABAP
|
|
583
677
|
session — the server keeps it until its own timeout, and sessions are limited
|
|
584
|
-
per user — so starting over means telling the server, then connecting
|
|
678
|
+
per user — so starting over means telling the server, then connecting a NEW
|
|
679
|
+
instance. One connection instance is one session: after `disconnect()` (or a
|
|
680
|
+
failed `connect()` that logged off its session) `connect()` on it rejects
|
|
681
|
+
`NOT_CONNECTED`. Creating the new instance is yours — your own factory, or
|
|
682
|
+
`createConnection` — as mcp-abap-adt's server does with `createAbapConnection`
|
|
683
|
+
per connection:
|
|
585
684
|
|
|
586
685
|
```typescript
|
|
587
686
|
await connection.disconnect(); // ends the session on the server too
|
|
588
|
-
|
|
687
|
+
const next = new AdtOnPremConnector(
|
|
688
|
+
config,
|
|
689
|
+
new BasicAuthProvider(config.username!, config.password!),
|
|
690
|
+
new OnPremHttpTransport(() => ({}), logger, {
|
|
691
|
+
client: config.client,
|
|
692
|
+
baseUrl: config.url,
|
|
693
|
+
}),
|
|
694
|
+
logger,
|
|
695
|
+
);
|
|
696
|
+
await next.connect(); // a new session is a new instance
|
|
589
697
|
```
|
|
590
698
|
|
|
591
699
|
A connection that was connected must be disconnected, which is why this belongs
|
|
592
|
-
in a `finally`. `disconnect()` never throws, so it is safe there
|
|
700
|
+
in a `finally`. The first `disconnect()` never throws, so it is safe there; a
|
|
701
|
+
second call on the same instance rejects `NOT_CONNECTED`, so let one path own
|
|
702
|
+
the call.
|
|
593
703
|
|
|
594
704
|
## Custom Logging
|
|
595
705
|
|
|
@@ -772,7 +882,8 @@ class AdtCloudConnector<
|
|
|
772
882
|
The difference is what each does with the session: on-prem takes it from the
|
|
773
883
|
establishing call and gives it back with the platform's ICF logoff; cloud opens
|
|
774
884
|
one at `/sap/bc/adt/core/http/sessions` and gives it back through the logoff
|
|
775
|
-
resource the server links to in the same answer
|
|
885
|
+
resource the server links to in the same answer — or, when it links none, with
|
|
886
|
+
the platform's ICF logoff, sent exactly as on-prem. Not by `DELETE` on the
|
|
776
887
|
session's own address: from inside that session it answers `200` and ends
|
|
777
888
|
nothing (measured on a BTP trial, 2026-10-12).
|
|
778
889
|
|
|
@@ -966,8 +1077,8 @@ token the provider renewed is on the very next attempt.
|
|
|
966
1077
|
|
|
967
1078
|
| answer | what happens |
|
|
968
1079
|
|---|---|
|
|
969
|
-
| **
|
|
970
|
-
| **401**
|
|
1080
|
+
| **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 |
|
|
1081
|
+
| 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 |
|
|
971
1082
|
| 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 |
|
|
972
1083
|
| **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 |
|
|
973
1084
|
| anything else | untouched |
|
|
@@ -976,21 +1087,28 @@ The one more attempt keeps the request's own lease and generation, so
|
|
|
976
1087
|
stale-request fencing applies to it: a request from a superseded session asks
|
|
977
1088
|
nobody and gets its error back. After a rejection `at: 'request'` it goes out on
|
|
978
1089
|
the same session; after a rejection `at: 'logon'` the wire logs on again — token
|
|
979
|
-
dropped, established anew — before the resend.
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1090
|
+
dropped, established anew — before the resend.
|
|
1091
|
+
|
|
1092
|
+
**No 401 opens a new session.** One instance is one session: nothing discards
|
|
1093
|
+
the session's cookies to open another and retry there. A mutation that meets a
|
|
1094
|
+
401 with a CSRF token cached is put to the provider like any other 401; on Ok it
|
|
1095
|
+
is resent on the same session with the same token, inside a critical section or
|
|
1096
|
+
not, and if SAP did replace the session the request fails with
|
|
1097
|
+
`SESSION_REPLACED`. Before 16.0.0, outside a critical section, that mutation
|
|
1098
|
+
discarded the session and retried in a new one on the same instance, a GET
|
|
1099
|
+
401 on a wire with no cookies fetched a token to open one, and a GET 401 with
|
|
1100
|
+
cookies held was resent once before the provider was asked; all three are
|
|
1101
|
+
gone. If you
|
|
1102
|
+
want a new session after a 401, create a new connection.
|
|
1103
|
+
|
|
1104
|
+
**A dead session can look like a refused credential.** When SAP answers the
|
|
1105
|
+
resend with the same session cookie and no `Set-Cookie`, the connection cannot
|
|
1106
|
+
tell a dead session from a refused credential: the 401 comes back a second time,
|
|
1107
|
+
and the request ends as `AuthRefusedError` with the refused-again verdict
|
|
990
1108
|
(`at: 'request'`), not `SESSION_REPLACED`. The connection stays connected on
|
|
991
|
-
that session. If you
|
|
992
|
-
|
|
993
|
-
|
|
1109
|
+
that session. If you suspect the session is gone, `disconnect()` and create a
|
|
1110
|
+
new connection; if you held a lock, treat it as lost and redo the work under a
|
|
1111
|
+
new lock there.
|
|
994
1112
|
|
|
995
1113
|
One credential retry per request: the upfront token fetch before a mutation and
|
|
996
1114
|
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": "16.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",
|