@mcp-abap-adt/connection 15.1.0 → 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 +144 -1
- package/README.md +68 -20
- package/dist/connection/AbstractAbapConnection.d.ts +89 -39
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +249 -223
- 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 -21
- package/dist/connection/IAdtTransport.d.ts +12 -19
- 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 +0 -6
- package/dist/connection/RfcTransport.d.ts.map +1 -1
- package/dist/connection/RfcTransport.js +13 -46
- 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 -38
- package/docs/USAGE.md +156 -84
- 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
|
@@ -81,7 +81,7 @@ is what every stateless call cost with `sap-rfc-lite` 0.1.x (and with 0.2.0,
|
|
|
81
81
|
whose npm package lacks the reset), and why 9.4.2 requires 0.2.1. Direct connector users must mark
|
|
82
82
|
LOCK and UNLOCK stateful to retain their conversation. If disconnect occurs
|
|
83
83
|
while a temporary conversation is logging on, it is closed without sending
|
|
84
|
-
the request;
|
|
84
|
+
the request; a new connection does not revive that pending request.
|
|
85
85
|
|
|
86
86
|
## Enabling Stateful Sessions
|
|
87
87
|
|
|
@@ -172,51 +172,47 @@ Every ADT request issued through `makeAdtRequest` automatically:
|
|
|
172
172
|
|
|
173
173
|
This logic is transparent to callers (Builders, handlers, CLI scripts).
|
|
174
174
|
|
|
175
|
-
A
|
|
176
|
-
something after its caller aborted: the upfront token fetch, the send itself,
|
|
177
|
-
the CSRF retry, the cookie retry of a GET and the provider's renewal below. Each
|
|
178
|
-
wait in between — the provider's `authorize()` and `rejected()`, a logon, the
|
|
179
|
-
token exchange, an RFC conversation's `open()` — ends for that caller at the
|
|
180
|
-
abort, with `ADT_REQUEST_ABORTED`; the session's token and cookies are left as
|
|
181
|
-
they are, for the requests still running on them. A request already on the wire
|
|
182
|
-
is not recalled. See [USAGE.md — Cancelling a request](./USAGE.md#cancelling-a-request).
|
|
183
|
-
|
|
184
|
-
A 401 that survives the wire's own CSRF recovery is put to the provider (`rejected`). On Ok the
|
|
175
|
+
A 401 that survives the wire's own CSRF recovery (in the same session) is put to the provider (`rejected`). On Ok the
|
|
185
176
|
request is sent once more, always under the same lease and generation as the attempt it repeats,
|
|
186
177
|
so stale-request fencing applies. After a rejection at `'request'` that resend goes out on the
|
|
187
178
|
same session; after a rejection at `'logon'` the wire logs on again before the resend.
|
|
188
|
-
**
|
|
179
|
+
**No 401 opens a new session, and the lock in the session is kept:** a mutation
|
|
189
180
|
(POST / PUT / DELETE) refused with a 401 while a CSRF token is cached goes to the provider and is
|
|
190
|
-
resent on the same session with the same token,
|
|
191
|
-
fails with `SESSION_REPLACED` instead of carrying on in a new one.
|
|
192
|
-
that mutation
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
**
|
|
196
|
-
the SAME session cookie (no `Set-Cookie`), the connection cannot tell it
|
|
197
|
-
credential — the second 401 ends the request as `AuthRefusedError` with the
|
|
198
|
-
verdict (`at: 'request'`), not `SESSION_REPLACED`, and the connection stays
|
|
199
|
-
|
|
200
|
-
a new lock.
|
|
181
|
+
resent on the same session with the same token, inside a critical section or not, and if SAP did
|
|
182
|
+
replace the session the request fails with `SESSION_REPLACED` instead of carrying on in a new one.
|
|
183
|
+
Before 16.0.0, outside a critical section, that mutation discarded the session and retried in a
|
|
184
|
+
new one on the same instance; that recovery is gone. One instance is one session: if you want a
|
|
185
|
+
new session after a 401, create a new connection.
|
|
186
|
+
**A dead session can look like a refused credential:** when the session is really dead but SAP
|
|
187
|
+
answers the resend with the SAME session cookie (no `Set-Cookie`), the connection cannot tell it
|
|
188
|
+
from a refused credential — the second 401 ends the request as `AuthRefusedError` with the
|
|
189
|
+
refused-again verdict (`at: 'request'`), not `SESSION_REPLACED`, and the connection stays
|
|
190
|
+
connected. Treat that as a lost session, and any lock in it as lost: `disconnect()`, create a new
|
|
191
|
+
connection, and redo the work under a new lock there.
|
|
201
192
|
If the provider says no, or the retry is refused too, the caller gets an `AuthRefusedError` (the refused-again verdict is `refusal.kind === 'connection'`, `facts.problem === 'refused-after-renewal'`). A 403 is an authorization answer, not a credential one: it never goes to the
|
|
202
193
|
provider. See [When the credential is refused](./USAGE.md#when-the-credential-is-refused).
|
|
203
194
|
|
|
204
|
-
|
|
195
|
+
**One connection instance is one session.** After `disconnect()`, or a failed `connect()` that
|
|
196
|
+
received a session cookie (whether or not a logoff was sent for it), the instance is spent and `connect()` on it rejects `NOT_CONNECTED`. A new
|
|
197
|
+
session is a new instance, created by the consumer (its own factory, or `createConnection`), and
|
|
198
|
+
outside a lock window rather than inside one.
|
|
205
199
|
|
|
206
|
-
**Wait for the goodbye before opening the next one.** `disconnect()`
|
|
207
|
-
not
|
|
208
|
-
still
|
|
200
|
+
**Wait for the goodbye before opening the next one.** `disconnect()` resolves once the logoff is
|
|
201
|
+
written, not answered, so a new connection otherwise opens the next session while the previous
|
|
202
|
+
one's goodbye is still unanswered, and the server keeps both:
|
|
209
203
|
|
|
210
204
|
```typescript
|
|
211
205
|
await conn.disconnect();
|
|
212
|
-
await conn.flushGoodbye(); //
|
|
213
|
-
|
|
206
|
+
await conn.flushGoodbye(); // wait for the goodbye's answer; flushGoodbye(ms) bounds it
|
|
207
|
+
const next = createYourConnection(); // a new instance for the new session
|
|
208
|
+
await next.connect();
|
|
214
209
|
```
|
|
215
210
|
|
|
216
211
|
Measured on E19 through a harness that recycled the session after each test: a new ABAP session
|
|
217
212
|
every one to two seconds for a whole run, none released, each living to its own thirty-minute idle
|
|
218
|
-
timeout.
|
|
219
|
-
|
|
213
|
+
timeout. Without an argument `flushGoodbye()` waits for the answer as long as SAP takes; a budget
|
|
214
|
+
you pass bounds the waiting, not the overlap — if the goodbye finishes in time there is none, and if
|
|
215
|
+
it does not you proceed while it stays outstanding. Calling `disconnect()` again is not
|
|
220
216
|
a substitute: a repeat call does not wait either.
|
|
221
217
|
|
|
222
218
|
---
|
|
@@ -246,7 +242,7 @@ The link to the ABAP session is not guaranteed, and that is the whole problem:
|
|
|
246
242
|
Both are reported, neither is worked around. `connect()` fails with the reason
|
|
247
243
|
when no session was opened; a session lost afterwards surfaces as
|
|
248
244
|
`ADT_SESSION_REPLACED` rather than a request quietly continuing somewhere it
|
|
249
|
-
does not belong. What to do about either — wait, retry,
|
|
245
|
+
does not belong. What to do about either — wait, retry, create a new connection, release
|
|
250
246
|
sessions the user still holds, carry on read-only — is the caller's decision,
|
|
251
247
|
made with the cookies and the answers in hand.
|
|
252
248
|
|
|
@@ -295,9 +291,10 @@ What it promises is narrow and worth stating exactly — inside a section the
|
|
|
295
291
|
short: the ceiling is `SAP_TIMEOUT_CRITICAL`, ten minutes by default, and a
|
|
296
292
|
socket ends a request whatever a contract says.
|
|
297
293
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
294
|
+
A section keeps its session through a credential renewal: a mutation refused
|
|
295
|
+
with a 401 inside it is renewed and resent on the same session, never moved to
|
|
296
|
+
a new one. Since 16.0.0 that holds outside a section too: no 401 moves a
|
|
297
|
+
request to a new session (see [Request Hooks](#request-hooks)).
|
|
301
298
|
|
|
302
299
|
### Two sessions, and they are not the same thing
|
|
303
300
|
|
|
@@ -348,7 +345,8 @@ you get by asking — `getSessionIdentity()` for which session you are in, and
|
|
|
348
345
|
## Troubleshooting
|
|
349
346
|
|
|
350
347
|
- **CSRF token errors**: discard the session and establish a new one. That is
|
|
351
|
-
`disconnect()
|
|
348
|
+
`disconnect()`, then a NEW connection's `connect()` — one instance is one
|
|
349
|
+
session — and there is no local-only discard, because
|
|
352
350
|
dropping the cookie leaves the ABAP session open on the server. Both live on
|
|
353
351
|
the HTTP connection classes and are **not** on the `IAbapConnection` type
|
|
354
352
|
a bare `IAbapConnection` carries — reach them through a connector type, or
|
|
@@ -360,9 +358,10 @@ import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
|
360
358
|
|
|
361
359
|
const connection = new AdtOnPremConnector(config, new BasicAuthProvider(user, pass), new OnPremHttpTransport(() => ({}), logger, { client: config.client, baseUrl: config.url }), logger);
|
|
362
360
|
await connection.disconnect(); // ends the session on the server, then clears
|
|
363
|
-
|
|
361
|
+
const next = new AdtOnPremConnector(config, new BasicAuthProvider(user, pass), new OnPremHttpTransport(() => ({}), logger, { client: config.client, baseUrl: config.url }), logger);
|
|
362
|
+
await next.connect(); // a new session is a new instance
|
|
364
363
|
```
|
|
365
|
-
- **Session expired**:
|
|
364
|
+
- **Session expired**: create a new connection; a new session is a new instance.
|
|
366
365
|
- **Multiple connections**: each connector holds its own wire, and the wire holds the cookie jar; share the instance if you need continuity.
|
|
367
366
|
|
|
368
367
|
---
|
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
|
|
@@ -227,52 +254,6 @@ await connection.makeAdtRequest({
|
|
|
227
254
|
});
|
|
228
255
|
```
|
|
229
256
|
|
|
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
257
|
## Session Management
|
|
277
258
|
|
|
278
259
|
### Stateless Mode (Default)
|
|
@@ -478,15 +459,45 @@ than on a concrete class where you can: an `IAbapConnection` may come from
|
|
|
478
459
|
somewhere that implements only the minimum, so the atom you require is also the
|
|
479
460
|
documentation of what your code actually needs.
|
|
480
461
|
|
|
481
|
-
### disconnect()
|
|
462
|
+
### disconnect() resolves once the logoff is written
|
|
482
463
|
|
|
483
464
|
```typescript
|
|
484
|
-
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
|
|
485
468
|
```
|
|
486
469
|
|
|
487
|
-
It never throws,
|
|
488
|
-
|
|
489
|
-
|
|
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.
|
|
490
501
|
|
|
491
502
|
Requests already in flight run to completion untouched; nothing is aborted. What
|
|
492
503
|
the connection guarantees is that their results can no longer reach it: a
|
|
@@ -498,9 +509,45 @@ turned out to be unbounded — a request whose caller chose no timeout could hol
|
|
|
498
509
|
teardown open forever, and since lifecycle transitions are serialized, every
|
|
499
510
|
later `connect()` queued behind it.
|
|
500
511
|
|
|
501
|
-
**
|
|
502
|
-
|
|
503
|
-
|
|
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.
|
|
504
551
|
|
|
505
552
|
### Uninterruptible spans
|
|
506
553
|
|
|
@@ -539,16 +586,10 @@ precisely to avoid it.
|
|
|
539
586
|
|
|
540
587
|
Two different things can cost you the session, and they do not behave alike.
|
|
541
588
|
|
|
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.
|
|
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.
|
|
552
593
|
|
|
553
594
|
**The server says the session is gone** — an answer meaning the session it was
|
|
554
595
|
given no longer exists. This is **always** fatal, window or not: the connection
|
|
@@ -561,6 +602,13 @@ In both cases the connector does **not** retry the request internally. Retrying
|
|
|
561
602
|
blindly is what produced further orphaned locks in the field. That decision is
|
|
562
603
|
yours.
|
|
563
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
|
+
|
|
564
612
|
## Advanced Features
|
|
565
613
|
|
|
566
614
|
### Session ID Management
|
|
@@ -627,15 +675,31 @@ connection.setSessionType('stateless');
|
|
|
627
675
|
|
|
628
676
|
There is no local-only reset. Discarding the cookie does not end the ABAP
|
|
629
677
|
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
|
|
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:
|
|
631
684
|
|
|
632
685
|
```typescript
|
|
633
686
|
await connection.disconnect(); // ends the session on the server too
|
|
634
|
-
|
|
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
|
|
635
697
|
```
|
|
636
698
|
|
|
637
699
|
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
|
|
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.
|
|
639
703
|
|
|
640
704
|
## Custom Logging
|
|
641
705
|
|
|
@@ -818,7 +882,8 @@ class AdtCloudConnector<
|
|
|
818
882
|
The difference is what each does with the session: on-prem takes it from the
|
|
819
883
|
establishing call and gives it back with the platform's ICF logoff; cloud opens
|
|
820
884
|
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
|
|
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
|
|
822
887
|
session's own address: from inside that session it answers `200` and ends
|
|
823
888
|
nothing (measured on a BTP trial, 2026-10-12).
|
|
824
889
|
|
|
@@ -1012,8 +1077,8 @@ token the provider renewed is on the very next attempt.
|
|
|
1012
1077
|
|
|
1013
1078
|
| answer | what happens |
|
|
1014
1079
|
|---|---|
|
|
1015
|
-
| **
|
|
1016
|
-
| **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 |
|
|
1017
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 |
|
|
1018
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 |
|
|
1019
1084
|
| anything else | untouched |
|
|
@@ -1022,21 +1087,28 @@ The one more attempt keeps the request's own lease and generation, so
|
|
|
1022
1087
|
stale-request fencing applies to it: a request from a superseded session asks
|
|
1023
1088
|
nobody and gets its error back. After a rejection `at: 'request'` it goes out on
|
|
1024
1089
|
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
|
-
|
|
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
|
|
1036
1108
|
(`at: 'request'`), not `SESSION_REPLACED`. The connection stays connected on
|
|
1037
|
-
that session. If you
|
|
1038
|
-
|
|
1039
|
-
|
|
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.
|
|
1040
1112
|
|
|
1041
1113
|
One credential retry per request: the upfront token fetch before a mutation and
|
|
1042
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",
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What a request's signal does to it: the error it ends with, the check made
|
|
3
|
-
* at each send boundary, and the race each of its waits runs against it.
|
|
4
|
-
*
|
|
5
|
-
* The signal belongs to ONE caller. A wait it ends — the provider's
|
|
6
|
-
* `authorize()` or `rejected()`, a logon, a conversation's `open()` — ends for
|
|
7
|
-
* that caller only: the work behind it runs on, because another caller may be
|
|
8
|
-
* waiting on the very same work (a provider shares one renewal among all who
|
|
9
|
-
* ask). Its late answer is handled here and dropped, never left unhandled.
|
|
10
|
-
*
|
|
11
|
-
* A request already sent is not recalled: nothing here reaches into the wire.
|
|
12
|
-
*/
|
|
13
|
-
import { type AdtRequestErrorCode } from '@mcp-abap-adt/interfaces-adt-connection';
|
|
14
|
-
export type RequestAbortedError = Error & {
|
|
15
|
-
code: AdtRequestErrorCode;
|
|
16
|
-
};
|
|
17
|
-
/** The error an aborted request rejects with: `ADT_REQUEST_ERROR.ABORTED`. */
|
|
18
|
-
export declare function requestAborted(): RequestAbortedError;
|
|
19
|
-
/** Whether an error is a request's abort. Read structurally, by its code. */
|
|
20
|
-
export declare function isRequestAborted(error: unknown): boolean;
|
|
21
|
-
/** A send boundary: an aborted request goes no further. */
|
|
22
|
-
export declare function throwIfAborted(signal: AbortSignal | undefined): void;
|
|
23
|
-
/**
|
|
24
|
-
* One wait of a request, raced against its signal.
|
|
25
|
-
*
|
|
26
|
-
* Settles as `work` does, or rejects with the abort the moment the signal
|
|
27
|
-
* fires — at once when it already has. `work` is never cancelled: it runs on
|
|
28
|
-
* for whoever else waits on it, and what it answers after the abort is
|
|
29
|
-
* handled and dropped. Without a signal, `work` itself.
|
|
30
|
-
*/
|
|
31
|
-
export declare function untilAborted<T>(signal: AbortSignal | undefined, work: Promise<T>): Promise<T>;
|
|
32
|
-
//# sourceMappingURL=requestAbort.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"requestAbort.d.ts","sourceRoot":"","sources":["../../src/connection/requestAbort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,yCAAyC,CAAC;AASjD,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAExE,8EAA8E;AAC9E,wBAAgB,cAAc,IAAI,mBAAmB,CAKpD;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKxD;AAED,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAEpE;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GACf,OAAO,CAAC,CAAC,CAAC,CAoBZ"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requestAborted = requestAborted;
|
|
4
|
-
exports.isRequestAborted = isRequestAborted;
|
|
5
|
-
exports.throwIfAborted = throwIfAborted;
|
|
6
|
-
exports.untilAborted = untilAborted;
|
|
7
|
-
/**
|
|
8
|
-
* What a request's signal does to it: the error it ends with, the check made
|
|
9
|
-
* at each send boundary, and the race each of its waits runs against it.
|
|
10
|
-
*
|
|
11
|
-
* The signal belongs to ONE caller. A wait it ends — the provider's
|
|
12
|
-
* `authorize()` or `rejected()`, a logon, a conversation's `open()` — ends for
|
|
13
|
-
* that caller only: the work behind it runs on, because another caller may be
|
|
14
|
-
* waiting on the very same work (a provider shares one renewal among all who
|
|
15
|
-
* ask). Its late answer is handled here and dropped, never left unhandled.
|
|
16
|
-
*
|
|
17
|
-
* A request already sent is not recalled: nothing here reaches into the wire.
|
|
18
|
-
*/
|
|
19
|
-
const interfaces_adt_connection_1 = require("@mcp-abap-adt/interfaces-adt-connection");
|
|
20
|
-
/**
|
|
21
|
-
* Fixed words: nothing of the request, the signal's reason or anything a
|
|
22
|
-
* server said reaches them.
|
|
23
|
-
*/
|
|
24
|
-
const ABORTED_WORDS = 'The request was aborted by its caller; nothing more of it was sent.';
|
|
25
|
-
/** The error an aborted request rejects with: `ADT_REQUEST_ERROR.ABORTED`. */
|
|
26
|
-
function requestAborted() {
|
|
27
|
-
const error = new Error(ABORTED_WORDS);
|
|
28
|
-
error.name = 'AdtRequestAbortedError';
|
|
29
|
-
error.code = interfaces_adt_connection_1.ADT_REQUEST_ERROR.ABORTED;
|
|
30
|
-
return error;
|
|
31
|
-
}
|
|
32
|
-
/** Whether an error is a request's abort. Read structurally, by its code. */
|
|
33
|
-
function isRequestAborted(error) {
|
|
34
|
-
return (error?.code ===
|
|
35
|
-
interfaces_adt_connection_1.ADT_REQUEST_ERROR.ABORTED);
|
|
36
|
-
}
|
|
37
|
-
/** A send boundary: an aborted request goes no further. */
|
|
38
|
-
function throwIfAborted(signal) {
|
|
39
|
-
if (signal?.aborted)
|
|
40
|
-
throw requestAborted();
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* One wait of a request, raced against its signal.
|
|
44
|
-
*
|
|
45
|
-
* Settles as `work` does, or rejects with the abort the moment the signal
|
|
46
|
-
* fires — at once when it already has. `work` is never cancelled: it runs on
|
|
47
|
-
* for whoever else waits on it, and what it answers after the abort is
|
|
48
|
-
* handled and dropped. Without a signal, `work` itself.
|
|
49
|
-
*/
|
|
50
|
-
function untilAborted(signal, work) {
|
|
51
|
-
if (!signal)
|
|
52
|
-
return work;
|
|
53
|
-
// Handled before anything else can happen: an answer that arrives after
|
|
54
|
-
// the abort is nobody's, and must not surface as an unhandled rejection.
|
|
55
|
-
work.catch(() => { });
|
|
56
|
-
if (signal.aborted)
|
|
57
|
-
return Promise.reject(requestAborted());
|
|
58
|
-
return new Promise((resolve, reject) => {
|
|
59
|
-
const onAbort = () => reject(requestAborted());
|
|
60
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
61
|
-
work.then((value) => {
|
|
62
|
-
signal.removeEventListener('abort', onAbort);
|
|
63
|
-
resolve(value);
|
|
64
|
-
}, (error) => {
|
|
65
|
-
signal.removeEventListener('abort', onAbort);
|
|
66
|
-
reject(error);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|