@mcp-abap-adt/connection 22.0.1 → 24.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 CHANGED
@@ -7,6 +7,66 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [24.0.0] - 2026-11-12
11
+
12
+ The shared contract moves to `@mcp-abap-adt/interfaces-adt-connection` 5.
13
+ Breaking for code typed against `IAbapConnection` or `AbapConnection` that
14
+ names a type argument on `makeAdtRequest`. Nothing changes at run time. See
15
+ [docs/MIGRATION-24.0.md](docs/MIGRATION-24.0.md).
16
+
17
+ ### Changed — breaking
18
+
19
+ - **The shared contract is `@mcp-abap-adt/interfaces-adt-connection` `^5.0.0`.**
20
+ Its `IAbapConnection.makeAdtRequest(options)` takes no type parameter and
21
+ answers `Promise<IAdtWireResponse>`, the answer's `data` `unknown`. The
22
+ connectors' own `makeAdtRequest` keeps its generic signature, and a
23
+ connector is assignable to version 5's `IAbapConnection`. Code holding a
24
+ value typed `IAbapConnection` (or the `AbapConnection` alias) that names a
25
+ type argument — `makeAdtRequest<string>(…)` — no longer compiles: drop the
26
+ type argument and narrow `data` from `unknown`. README and docs/USAGE.md describe the version 5 contract.
27
+
28
+ ## [23.0.0] - 2026-11-12
29
+
30
+ A stateless request keeps its answer when the SAP session was replaced
31
+ (fr0ster/mcp-abap-adt#354). Breaking for code that learned of the loss from the
32
+ `ADT_SESSION_REPLACED` rejection of a stateless request. See
33
+ [docs/MIGRATION-23.0.md](docs/MIGRATION-23.0.md).
34
+
35
+ ### Changed — breaking
36
+
37
+ - **A stateless request whose answer shows the session replaced gets that
38
+ answer.** A success resolves, a refusal rejects as itself; either carries
39
+ `sessionLost: 'ADT_SESSION_REPLACED'`. The session is lost before the answer
40
+ reaches the caller (the instance spent, the replacing session logged off), and
41
+ nothing is sent again: no CSRF retry and no credential renewal start from it.
42
+ A stateful request, the connection's own exchanges inside a request (a CSRF
43
+ fetch, a logon) and an answer saying the session no longer exists that shows
44
+ no replacement keep rejecting `ADT_SESSION_REPLACED`; `connect()` and a resumed
45
+ session behave as in 22.x. A refusal that cannot take the mark (frozen,
46
+ sealed) is answered by an object on top of it that reads through to it.
47
+
48
+ ### Added
49
+
50
+ - `sessionLost` on the resolved response and on the rejected refusal, typed by
51
+ `@mcp-abap-adt/interfaces-adt-connection` 4.2.0 (`AdtSessionLoss`).
52
+
53
+ ### Fixed
54
+
55
+ - **The CSRF retry's refused resend is observed.** Its answer used to be dropped
56
+ for the first attempt's `403` without being read, so a replacement on it went
57
+ unnoticed.
58
+ - **A refusal whose body is absent or does not serialise is read like any
59
+ other.** Its log preview threw (`JSON.stringify(undefined).slice`, a circular
60
+ body) before the answer was observed, so the caller got a `TypeError` and a
61
+ replacement on it went unnoticed; the preview is now empty instead.
62
+ - **A logger that throws on the success line no longer takes the answer.** The
63
+ `REQUEST_SUCCESS` debug line is written as the failure lines are, its throw
64
+ dropped.
65
+
66
+ ### Dependencies
67
+
68
+ - `@mcp-abap-adt/interfaces-adt-connection` `^4.2.0`.
69
+
10
70
  ## [22.0.1] - 2026-11-12
11
71
 
12
72
  ### Fixed
@@ -2968,7 +3028,9 @@ const connection = createAbapConnection(config, logger);
2968
3028
  - JWT token refresh now properly handles connection errors (401/403 during initial connect)
2969
3029
  - Permission errors (403 with "ExceptionResourceNoAccess") no longer trigger JWT refresh loops
2970
3030
  - Proper separation: base class handles HTTP/session, concrete classes handle auth-specific errors
2971
- [Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v22.0.1...HEAD
3031
+ [Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v24.0.0...HEAD
3032
+ [24.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v23.0.0...v24.0.0
3033
+ [23.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v22.0.1...v23.0.0
2972
3034
  [22.0.1]: https://github.com/fr0ster/mcp-abap-connection/compare/v22.0.0...v22.0.1
2973
3035
  [22.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v21.0.0...v22.0.0
2974
3036
  [21.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v20.1.0...v21.0.0
package/README.md CHANGED
@@ -162,6 +162,8 @@ the packages above. See [Migration to 9.0.0](./docs/MIGRATION-9.0.md).
162
162
 
163
163
  - 📦 **[Installation Guide](./docs/INSTALLATION.md)** - Setup and installation instructions
164
164
  - 📚 **[Usage Guide](./docs/USAGE.md)** - Detailed usage examples and API documentation
165
+ - 🚚 **[Migration to 24.0.0](./docs/MIGRATION-24.0.md)** - on `@mcp-abap-adt/interfaces-adt-connection` ^5.0.0: `IAbapConnection` / `AbapConnection`'s `makeAdtRequest` takes no type argument; drop it and narrow `data` from `unknown`; the connectors are unchanged
166
+ - 🚚 **[Migration to 23.0.0](./docs/MIGRATION-23.0.md)** - a stateless request whose answer shows the SAP session replaced keeps that answer, marked `sessionLost`, and the instance is spent; a stateful request still rejects `ADT_SESSION_REPLACED`; nothing is resent; `@mcp-abap-adt/interfaces-adt-connection` ^4.2.0
165
167
  - 🚚 **[Migration to 22.0.0](./docs/MIGRATION-22.0.md)** - over RFC: a connection-ending RFC error on the stateful conversation is `ADT_SESSION_REPLACED` and spends the instance (no silent reconnect); a failed RFC call carries `rfc: { key, group, code, codeString }`; the `SAP-PASSPORT` header becomes the RFC call's passport; `@mcp-abap-adt/sap-rfc-lite` ^0.4.0
166
168
  - 🚚 **[Migration to 21.0.0](./docs/MIGRATION-21.0.md)** - the CSRF token fetch asks once: no retry, no delay; `CSRF_CONFIG.RETRY_COUNT` / `RETRY_DELAY`, the establish context's `retries` / `retryDelayMs` / `isFatal`, `fetchCsrfToken`'s retry parameters and `endsTheExchange` are removed
167
169
  - 🚚 **[Migration to 20.0.0](./docs/MIGRATION-20.0.md)** - an RFC config is an `ISapRfcConfig` that states its address (`ashost` + `sysnr`, or `mshost` + `msserv` / `sysid` + `group`), `client` and `language`: no URL, no defaults, no `SAP_SYSNR`; `getBaseUrl()` may answer `undefined`; hand-built HTTP transports take `baseUrl`; `IAdtSessionContext` has no `baseUrl`
@@ -706,8 +708,9 @@ await connection.connect();
706
708
  // as the attempt it repeats, so stale-request fencing applies. After a rejection
707
709
  // at 'request' it goes out on the same session; after one at 'logon' the wire
708
710
  // logs on again first. No 401 opens a new session: the resend stays in this
709
- // one, or fails with SESSION_REPLACED if SAP replaced it. For a new session,
710
- // create a new connection.
711
+ // one. If SAP replaced it, a stateful request fails with ADT_SESSION_REPLACED
712
+ // and a stateless one gets SAP's answer marked `sessionLost`; the instance is
713
+ // spent either way. For a new session, create a new connection.
711
714
  const response = await connection.makeAdtRequest({
712
715
  method: "GET",
713
716
  url: "/sap/bc/adt/programs/programs/your-program",
@@ -846,6 +849,13 @@ connection.setSessionType("stateless");
846
849
 
847
850
  ```
848
851
 
852
+ **When SAP replaced the session** (an idle timeout, usually): a stateful
853
+ request rejects `ADT_SESSION_REPLACED`; a stateless one gets SAP's answer as it
854
+ came — a success resolves, a refusal rejects as itself — marked
855
+ `sessionLost: 'ADT_SESSION_REPLACED'` (since 23.0.0). Either way the instance
856
+ is spent and nothing is sent again: create a new connection. See
857
+ [When the session is lost](./docs/USAGE.md#when-the-session-is-lost).
858
+
849
859
  ### Custom Logger
850
860
 
851
861
  ```typescript
@@ -915,10 +925,9 @@ import type { IAdtWireResponse } from '@mcp-abap-adt/interfaces-adt-connection';
915
925
  // The shared contract (IAbapConnection), what every connection provides:
916
926
  interface AbapConnection {
917
927
  connect(): Promise<void>; // REQUIRED before any request; rejects on failure
918
- // An answer whose type is not named is `unknown` (interfaces-adt-connection 2).
919
- makeAdtRequest<T = unknown, D = unknown>(
920
- options: AbapRequestOptions,
921
- ): Promise<IAdtWireResponse<T, D>>;
928
+ // The answer's `data` is `unknown`; the caller names no type for it
929
+ // (interfaces-adt-connection 5).
930
+ makeAdtRequest(options: AbapRequestOptions): Promise<IAdtWireResponse>;
922
931
  getBaseUrl(): Promise<string | undefined>; // undefined over RFC: no HTTP origin
923
932
  setSessionType(type: "stateless" | "stateful"): void; // Switch session type
924
933
  getSessionId(): string | null; // Client-side conversation id
@@ -6,6 +6,12 @@ import { type RequestLease, SessionLifecycle } from '../session/SessionLifecycle
6
6
  import type { AbapConnection, AbapRequestOptions } from './AbapConnection.js';
7
7
  import { type GuardedAnswer } from './authErrors.js';
8
8
  import { type IAdtSessionContext, type IAdtTransport } from './IAdtTransport.js';
9
+ /**
10
+ * What observing an answer decided: `'kept'` — the session is as it was, or the
11
+ * answer's effects are fenced; `'lost'` — the answer showed the session
12
+ * replaced, the session is lost, and the answer is the caller's.
13
+ */
14
+ type SessionObservation = 'kept' | 'lost';
9
15
  declare abstract class AbstractAbapConnection implements AbapConnection, ISessionLifecycleAware, ICriticalSection, IRequestProfiling {
10
16
  private readonly config;
11
17
  /**
@@ -488,7 +494,14 @@ declare abstract class AbstractAbapConnection implements AbapConnection, ISessio
488
494
  * later check reads `unchanged`. That is one call site forgetting, and it
489
495
  * happened — on the error path and on every retry response.
490
496
  */
491
- protected observeResponse(headers?: Record<string, unknown>, generation?: number): void;
497
+ protected observeResponse(headers?: Record<string, unknown>, generation?: number,
498
+ /**
499
+ * The answer is an attempt of a stateless caller's request: a replacement
500
+ * it shows loses the session as always, and the answer is then the
501
+ * caller's — `'lost'` is returned instead of the throw. Not given for the
502
+ * connection's own exchanges and for stateful requests.
503
+ */
504
+ keepAnswer?: boolean): SessionObservation;
492
505
  /**
493
506
  * Acts on what a response said about the session identity.
494
507
  *
@@ -580,6 +593,15 @@ declare abstract class AbstractAbapConnection implements AbapConnection, ISessio
580
593
  * act inside a session the request was never admitted to.
581
594
  */
582
595
  private sendObserved;
596
+ /**
597
+ * SAP's refusal of a stateless request whose answer showed the session
598
+ * replaced, as the caller gets it: the refusal itself, marked `sessionLost`.
599
+ * The wire's error is its own object, made for this attempt, so the mark is
600
+ * set on it. One that cannot take it — frozen, sealed, or holding its own
601
+ * fixed `sessionLost` — is answered by an object on top of it: every field of
602
+ * the refusal read through to it, its class kept, the mark its own.
603
+ */
604
+ private markedLost;
583
605
  /**
584
606
  * One attempt's headers: the request's own, with what the credential writes
585
607
  * for THIS attempt on top.
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractAbapConnection.d.ts","sourceRoot":"","sources":["../../src/connection/AbstractAbapConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,KAAK,YAAY,EACjB,gBAAgB,EAEjB,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAGnB,MAAM,oBAAoB,CAAC;AA8D5B,uBAAe,sBACb,YACE,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB;IAwIjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,EAAE,aAAa;IACjC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAnJ3C;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,mBAA0B;IAEtD;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,WAAW,CAAyC;IAE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OAWG;YACW,uBAAuB;IA6DrC;;;;;;;;;OASG;IACH,OAAO,CAAC,kBAAkB;IAkB1B;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAe5B;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAQpB,+EAA+E;IAC/E,OAAO,CAAC,OAAO;IAOf;;;;;;;OAOG;YACW,eAAe;IAsB7B;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;OAOG;YACW,gBAAgB;IAqC9B;;;;;;;;OAQG;cACa,cAAc,CAC5B,IAAI,EAAE,MAAM;IACZ;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,GAChD,OAAO,CAAC,MAAM,CAAC;IAelB,SAAS,CAAC,YAAY,IAAI,MAAM,GAAG,IAAI;IAIvC;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAMlD;;OAEG;IACH,SAAS,CAAC,UAAU,IAAI,MAAM,GAAG,IAAI;IAIrC;;;;;;OAMG;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMlD;;;;;;;;OAQG;YACW,eAAe;IAO7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,aAAa;IAgCrB;;;;;;;;OAQG;IACH,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,eAAe;CA6BxB;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
1
+ {"version":3,"file":"AbstractAbapConnection.d.ts","sourceRoot":"","sources":["../../src/connection/AbstractAbapConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EACV,cAAc,E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B;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;OAOG;YACW,gBAAgB;IAqC9B;;;;;;;;OAQG;cACa,cAAc,CAC5B,IAAI,EAAE,MAAM;IACZ;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,GAChD,OAAO,CAAC,MAAM,CAAC;IAelB,SAAS,CAAC,YAAY,IAAI,MAAM,GAAG,IAAI;IAIvC;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAMlD;;OAEG;IACH,SAAS,CAAC,UAAU,IAAI,MAAM,GAAG,IAAI;IAIrC;;;;;;OAMG;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMlD;;;;;;;;OAQG;YACW,eAAe;IAO7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,aAAa;IAgCrB;;;;;;;;OAQG;IACH,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,eAAe;CA6BxB;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -8,6 +8,7 @@ const networkErrors_js_1 = require("../utils/networkErrors.js");
8
8
  const authErrors_js_1 = require("./authErrors.js");
9
9
  const csrfConfig_js_1 = require("./csrfConfig.js");
10
10
  const IAdtTransport_js_1 = require("./IAdtTransport.js");
11
+ const statefulRequest_js_1 = require("./statefulRequest.js");
11
12
  /**
12
13
  * Declares the capabilities explicitly rather than satisfying them by accident.
13
14
  * `AbapConnection` is the base contract every transport honours; these two are
@@ -47,6 +48,29 @@ function hasHeader(headers, name) {
47
48
  * wire's session token and the request's content negotiation.
48
49
  */
49
50
  const OUTRANK_THE_CREDENTIAL = ['x-csrf-token', 'content-type', 'accept'];
51
+ /**
52
+ * The first 200 characters of a refusal's body, for a log line. The body is
53
+ * the wire's, from outside the type system: an absent one, or one that will
54
+ * not serialise (circular, a throwing `toJSON`), is no preview — never a throw
55
+ * that would stand in for the refusal and skip what the answer means.
56
+ */
57
+ function dataPreview(data) {
58
+ if (typeof data === 'string')
59
+ return data.slice(0, 200);
60
+ try {
61
+ return JSON.stringify(data)?.slice(0, 200);
62
+ }
63
+ catch {
64
+ return undefined;
65
+ }
66
+ }
67
+ /** Whether a thrown value is a refusal this connection marked `sessionLost`. */
68
+ function carriesSessionLost(error) {
69
+ return (typeof error === 'object' &&
70
+ error !== null &&
71
+ 'sessionLost' in error &&
72
+ error.sessionLost === interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED);
73
+ }
50
74
  const DEAD_SESSION_PHRASES = [
51
75
  'session not found',
52
76
  'session timed out or not found',
@@ -979,7 +1003,8 @@ class AbstractAbapConnection {
979
1003
  const code = error?.code;
980
1004
  return (code === interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED ||
981
1005
  code === interfaces_adt_connection_1.ADT_SESSION_ERROR.NOT_CONNECTED ||
982
- code === interfaces_adt_connection_1.ADT_SESSION_ERROR.RELEASE_PENDING);
1006
+ code === interfaces_adt_connection_1.ADT_SESSION_ERROR.RELEASE_PENDING ||
1007
+ carriesSessionLost(error));
983
1008
  }
984
1009
  /**
985
1010
  * Folds a response into the session state AND acts on what it means, in one
@@ -990,7 +1015,14 @@ class AbstractAbapConnection {
990
1015
  * later check reads `unchanged`. That is one call site forgetting, and it
991
1016
  * happened — on the error path and on every retry response.
992
1017
  */
993
- observeResponse(headers, generation) {
1018
+ observeResponse(headers, generation,
1019
+ /**
1020
+ * The answer is an attempt of a stateless caller's request: a replacement
1021
+ * it shows loses the session as always, and the answer is then the
1022
+ * caller's — `'lost'` is returned instead of the throw. Not given for the
1023
+ * connection's own exchanges and for stateful requests.
1024
+ */
1025
+ keepAnswer = false) {
994
1026
  // Fenced by SESSION GENERATION, not by the teardown epoch. Only a
995
1027
  // caller-initiated teardown moves the epoch — a recovery deliberately does
996
1028
  // not — so after a session loss and a successful recovery, a request from
@@ -1003,12 +1035,12 @@ class AbstractAbapConnection {
1003
1035
  if (generation !== undefined &&
1004
1036
  generation !== this.lifecycle.sessionGeneration) {
1005
1037
  this.logger?.debug('Ignoring a response from a previous session: its effects are fenced');
1006
- return;
1038
+ return 'kept';
1007
1039
  }
1008
1040
  // The wire folds the response into its own state; what the change MEANS
1009
1041
  // is decided here, because it is a question about the session's lifetime.
1010
1042
  this.transport.ingest(headers);
1011
- this.applyIdentityPolicy(this.lifecycle.observe(this.transport.sessionFingerprint()));
1043
+ return this.applyIdentityPolicy(this.lifecycle.observe(this.transport.sessionFingerprint()), keepAnswer);
1012
1044
  }
1013
1045
  /**
1014
1046
  * Acts on what a response said about the session identity.
@@ -1026,9 +1058,9 @@ class AbstractAbapConnection {
1026
1058
  * Being wrong in this direction costs a reconnect; being wrong the other way
1027
1059
  * costs a lock nobody can find.
1028
1060
  */
1029
- applyIdentityPolicy(classification) {
1061
+ applyIdentityPolicy(classification, keepAnswer) {
1030
1062
  if (classification !== 'replaced')
1031
- return;
1063
+ return 'kept';
1032
1064
  // The answer that replaced the session brought a session of its own,
1033
1065
  // which SAP opened and which nothing here will ever use: it is logged off
1034
1066
  // now, while the wire still holds its cookie, as `disconnect()` logs off
@@ -1047,6 +1079,12 @@ class AbstractAbapConnection {
1047
1079
  this.endSession(this.sessionContext());
1048
1080
  this.clearSessionState();
1049
1081
  this.raiseSessionLost('the session cookie changed under us');
1082
+ // A stateless request's answer is SAP's, and valid: it is returned, marked,
1083
+ // the session already lost (fr0ster/mcp-abap-adt#354). Nothing is sent
1084
+ // again for it. A stateful request — the one a lock is taken and released
1085
+ // in — and the connection's own exchanges keep failing loudly.
1086
+ if (keepAnswer)
1087
+ return 'lost';
1050
1088
  throw (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED, 'The SAP session this connection was using is gone and the requests are now on a different one; anything held against the old session — a lock and any write under it — is dead. ' +
1051
1089
  'The server does not swap sessions on a whim: the usual causes are the session idling out (the timeout is idle-based, so a quiet connection loses it while a busy one does not) or a request landing on a different application server. ' +
1052
1090
  'What to do about it is yours: re-establish and redo the work, or fail the operation. Nothing is retried here.');
@@ -1147,9 +1185,9 @@ class AbstractAbapConnection {
1147
1185
  async credentialRejected(_rejection) {
1148
1186
  return { outcome: { ok: false, refusal: authErrors_js_1.NO_CREDENTIAL_TO_RENEW } };
1149
1187
  }
1150
- // The defaults are IAbapConnection's (interfaces-adt-connection 2: `unknown`),
1151
- // which this implements: changing them here alone would type every caller's
1152
- // response differently from the contract it codes against.
1188
+ // The defaults are IAdtWireResponse's (`unknown`). IAbapConnection
1189
+ // (interfaces-adt-connection 5) takes no type parameter; this generic
1190
+ // implementation is assignable to it, and its callers keep their signature.
1153
1191
  async makeAdtRequest(options) {
1154
1192
  // Admission first, synchronously, before any await: the check and the
1155
1193
  // count must happen in one step, or a request could be admitted and still
@@ -1284,12 +1322,15 @@ class AbstractAbapConnection {
1284
1322
  });
1285
1323
  try {
1286
1324
  const response = await this.sendObserved(requestConfig, lease);
1287
- this.logger?.debug(`Request succeeded with status ${response.status}`, {
1325
+ // The answer outranks the logger's word on it: a logger that throws
1326
+ // must not take a received answer — one marked `sessionLost` above all,
1327
+ // whose session is already gone — from the caller.
1328
+ this.logQuietly(() => this.logger?.debug(`Request succeeded with status ${response.status}`, {
1288
1329
  type: 'REQUEST_SUCCESS',
1289
1330
  status: response.status,
1290
1331
  url: requestUrl,
1291
1332
  method: normalizedMethod,
1292
- });
1333
+ }));
1293
1334
  return response;
1294
1335
  }
1295
1336
  catch (error) {
@@ -1317,8 +1358,42 @@ class AbstractAbapConnection {
1317
1358
  throw (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.NOT_CONNECTED, 'The session this request was admitted to is gone; nothing was sent');
1318
1359
  }
1319
1360
  const response = await this.transport.send(requestConfig);
1320
- this.observeResponse(response.headers, lease.generation);
1321
- return response;
1361
+ const observed = this.observeResponse(response.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
1362
+ const answer = response;
1363
+ // The answer itself says the session is gone: a field, on the one object
1364
+ // that answers this request, never a word.
1365
+ return observed === 'lost'
1366
+ ? { ...answer, sessionLost: interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED }
1367
+ : answer;
1368
+ }
1369
+ /**
1370
+ * SAP's refusal of a stateless request whose answer showed the session
1371
+ * replaced, as the caller gets it: the refusal itself, marked `sessionLost`.
1372
+ * The wire's error is its own object, made for this attempt, so the mark is
1373
+ * set on it. One that cannot take it — frozen, sealed, or holding its own
1374
+ * fixed `sessionLost` — is answered by an object on top of it: every field of
1375
+ * the refusal read through to it, its class kept, the mark its own.
1376
+ */
1377
+ markedLost(error) {
1378
+ // A refusal is an object: `refusalOf` found its `response` on it.
1379
+ if (typeof error !== 'object' || error === null)
1380
+ return error;
1381
+ const mark = {
1382
+ value: interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED,
1383
+ enumerable: true,
1384
+ configurable: true,
1385
+ writable: false,
1386
+ };
1387
+ if (Object.isExtensible(error)) {
1388
+ try {
1389
+ Object.defineProperty(error, 'sessionLost', mark);
1390
+ return error;
1391
+ }
1392
+ catch {
1393
+ // An own `sessionLost` that cannot be redefined: marked from above.
1394
+ }
1395
+ }
1396
+ return Object.create(error, { sessionLost: mark });
1322
1397
  }
1323
1398
  /**
1324
1399
  * One attempt's headers: the request's own, with what the credential writes
@@ -1395,13 +1470,14 @@ class AbstractAbapConnection {
1395
1470
  };
1396
1471
  const refusal = (0, IAdtTransport_js_1.refusalOf)(error);
1397
1472
  if (refusal) {
1398
- errorDetails.data =
1399
- typeof refusal.data === 'string'
1400
- ? refusal.data.slice(0, 200)
1401
- : JSON.stringify(refusal.data).slice(0, 200);
1473
+ errorDetails.data = dataPreview(refusal.data);
1402
1474
  // Every wire's refusal, not only axios's. A response the connection
1403
- // never observed is a session replacement it never noticed.
1404
- this.observeResponse(refusal.headers, lease.generation);
1475
+ // never observed is a session replacement it never noticed. A stateless
1476
+ // request's refusal that showed one is the caller's answer: no recovery
1477
+ // starts from it — no CSRF retry, no credential renewal.
1478
+ const observed = this.observeResponse(refusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
1479
+ if (observed === 'lost')
1480
+ throw this.markedLost(error);
1405
1481
  }
1406
1482
  this.throwIfSessionDead(error, lease);
1407
1483
  // Check if this is a network error (connection refused, timeout, DNS, etc.)
@@ -1450,6 +1526,14 @@ class AbstractAbapConnection {
1450
1526
  if (!this.lifecycle.isCurrent(lease)) {
1451
1527
  throw this.staleVerdict(retryError);
1452
1528
  }
1529
+ // The resend's refusal is observed like the first attempt's: a
1530
+ // replacement it shows is its own answer, not the first attempt's 403.
1531
+ const retryRefusal = (0, IAdtTransport_js_1.refusalOf)(retryError);
1532
+ if (retryRefusal) {
1533
+ const observed = this.observeResponse(retryRefusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
1534
+ if (observed === 'lost')
1535
+ throw this.markedLost(retryError);
1536
+ }
1453
1537
  this.throwIfSessionDead(retryError, lease);
1454
1538
  // A session verdict outranks the error that started the retry: the
1455
1539
  // caller can retry a 403 itself, but it cannot discover that its lock
@@ -1479,6 +1563,10 @@ class AbstractAbapConnection {
1479
1563
  * `requestHeaders` are the request's own, and the resend is authorized anew.
1480
1564
  */
1481
1565
  async answerCredentialFailure(failure, requestConfig, requestHeaders, lease, renewal) {
1566
+ // A session verdict is already the caller's answer — a stateless
1567
+ // request's refusal marked `sessionLost` above all: no provider is asked.
1568
+ if (this.isSessionVerdict(failure))
1569
+ throw failure;
1482
1570
  // A resend inside the wire's recovery that met a dead session.
1483
1571
  this.throwIfSessionDead(failure, lease);
1484
1572
  const rejection = this.credentialRejection(failure);
@@ -1522,7 +1610,9 @@ class AbstractAbapConnection {
1522
1610
  // SAP replaced in between is SESSION_REPLACED, not a bare status.
1523
1611
  const refusal = (0, IAdtTransport_js_1.refusalOf)(again);
1524
1612
  if (refusal) {
1525
- this.observeResponse(refusal.headers, lease.generation);
1613
+ const observed = this.observeResponse(refusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
1614
+ if (observed === 'lost')
1615
+ throw this.markedLost(again);
1526
1616
  }
1527
1617
  this.throwIfSessionDead(again, lease);
1528
1618
  const secondRejection = this.credentialRejection(again);
package/docs/INDEX.md CHANGED
@@ -15,6 +15,8 @@ mcp-abap-connection/
15
15
  │ ├── INSTALLATION.md # Setup and installation guide
16
16
  │ ├── USAGE.md # API documentation and examples
17
17
  │ ├── MIGRATION-2.0.md # Moving to the explicit session lifecycle
18
+ │ ├── MIGRATION-24.0.md # interfaces-adt-connection 5: IAbapConnection.makeAdtRequest takes no type argument
19
+ │ ├── MIGRATION-23.0.md # a stateless request keeps its answer when the session was replaced: sessionLost
18
20
  │ ├── MIGRATION-22.0.md # RFC: the session lost after a connection-ending error; rfc fields; the passport
19
21
  │ ├── MIGRATION-21.0.md # the CSRF token fetch asks once: no retry, no delay
20
22
  │ ├── MIGRATION-20.0.md # an RFC config states its address, client and language; no URL over RFC
@@ -52,6 +54,7 @@ mcp-abap-connection/
52
54
  - 🧭 [Scope](./SCOPE.md) - What this package answers for, and only that
53
55
 
54
56
  ### Upgrading
57
+ - 🚚 [Migrating to 24.0.0](./MIGRATION-24.0.md) - on `@mcp-abap-adt/interfaces-adt-connection` 5: `IAbapConnection` / `AbapConnection`'s `makeAdtRequest` takes no type argument; narrow `data` from `unknown`
55
58
  - 🚚 [Migrating to 21.0.0](./MIGRATION-21.0.md) - the CSRF token fetch asks once: no retry, no delay; the retry constants, context fields and parameters are removed
56
59
  - 🚚 [Migrating to 20.0.0](./MIGRATION-20.0.md) - an RFC config is an `ISapRfcConfig` stating its address, `client` and `language`: no URL, no defaults, no `SAP_SYSNR`; `getBaseUrl()` may answer `undefined`; HTTP transports take `baseUrl`
57
60
  - 🚚 [Migrating to 18.0.0](./MIGRATION-18.0.md) - `rfcParamsFrom` returns `RfcAddress`; RFC through a message server and a logon group
@@ -0,0 +1,78 @@
1
+ # Migration to 23.0
2
+
3
+ 23.0.0 changes what a stateless request gets when the SAP session behind the
4
+ connection was replaced (fr0ster/mcp-abap-adt#354). Stateful requests, RFC and
5
+ everything else are unchanged.
6
+
7
+ ## What changed
8
+
9
+ - **A stateless request keeps its answer.** SAP replaces a session that idled
10
+ out: the next request's answer carries a new `SAP_SESSIONID`. A stateless
11
+ request — any request that is not stateful; it holds no lock and no lock
12
+ state — now gets that answer as SAP gave it: a success resolves, a refusal
13
+ rejects as itself. The answer carries `sessionLost: 'ADT_SESSION_REPLACED'`
14
+ (on the resolved `IAdtWireResponse`, or on the rejected error, beside its own
15
+ `code`). With 22.x the same request rejected `ADT_SESSION_REPLACED` and its
16
+ answer was thrown away, so a read-only call failed once and succeeded right
17
+ after on a new connection.
18
+ - **The session is still lost.** Before the answer reaches you the instance is
19
+ spent, as after any lost session: `isConnected()` is `false`,
20
+ `sessionCookies()` is `null`, every later request and `connect()` reject
21
+ `ADT_NOT_CONNECTED` with nothing sent, and the session SAP opened with that
22
+ answer is logged off. Nothing is sent again for it: no CSRF retry and no
23
+ credential renewal start from an answer that showed the replacement.
24
+ - **Stateful requests keep failing.** A stateful request (`LOCK`, `UNLOCK`, or
25
+ any request the session mode or the `x-sap-adt-sessiontype: stateful` header
26
+ marks stateful) whose answer shows the replacement rejects
27
+ `ADT_SESSION_REPLACED`, as before. So do the connection's own exchanges
28
+ inside a request (a CSRF fetch, a logon), and an answer saying the session no
29
+ longer exists when it shows no replacement — a stateless refusal that both
30
+ changes the `SAP_SESSIONID` and says the session is gone is that refusal,
31
+ marked. `connect()` and a resumed session (`createConnection({ session })`)
32
+ behave as in 22.x.
33
+ - **A refused CSRF resend is now observed.** The resend after a refused CSRF
34
+ token used to rethrow the first attempt's `403` without looking at the
35
+ resend's own answer; a replacement on it went unnoticed. Its answer is now
36
+ read like every other.
37
+ - **`@mcp-abap-adt/interfaces-adt-connection` ^4.2.0**, which types
38
+ `sessionLost` (`AdtSessionLoss`).
39
+
40
+ ## What to do
41
+
42
+ **Read `sessionLost` where you caught `ADT_SESSION_REPLACED` for a stateless
43
+ request.** The answer is valid and is yours to use; the instance is not. Create
44
+ a new connection for the next request:
45
+
46
+ ```typescript
47
+ import {
48
+ ADT_SESSION_ERROR,
49
+ type IAbapConnection,
50
+ type IAbapConnectionError,
51
+ type IAbapRequestOptions,
52
+ } from "@mcp-abap-adt/interfaces-adt-connection";
53
+
54
+ async function readOnce(
55
+ connection: IAbapConnection,
56
+ options: IAbapRequestOptions,
57
+ ): Promise<unknown> {
58
+ const response = await connection.makeAdtRequest(options);
59
+ if (response.sessionLost === ADT_SESSION_ERROR.SESSION_REPLACED) {
60
+ // the answer is valid; the next request needs a new connection
61
+ }
62
+ return response.data;
63
+ }
64
+
65
+ function sessionWasLost(error: Error & IAbapConnectionError): boolean {
66
+ return (
67
+ error.code === ADT_SESSION_ERROR.SESSION_REPLACED || // stateful
68
+ error.sessionLost === ADT_SESSION_ERROR.SESSION_REPLACED // stateless refusal
69
+ );
70
+ }
71
+ ```
72
+
73
+ **Do not resend on your own** unless you mean to: the connection never does.
74
+ A write that carried a lock handle of the old session is refused by SAP (`403`
75
+ for the old CSRF token, `423` for the gone lock), and that refusal is what you
76
+ get, marked.
77
+
78
+ `disconnect()` is still owed once on the spent instance; it sends nothing.
@@ -0,0 +1,42 @@
1
+ # Migration to 24.0
2
+
3
+ 24.0.0 moves the shared contract to `@mcp-abap-adt/interfaces-adt-connection`
4
+ ^5.0.0. Nothing changes at run time.
5
+
6
+ ## What changed
7
+
8
+ - **`IAbapConnection.makeAdtRequest` takes no type argument.** Version 5
9
+ declares `makeAdtRequest(options): Promise<IAdtWireResponse>`; the answer's
10
+ `data` is `unknown`. This package's `AbapConnection` is an alias for
11
+ `IAbapConnection`, so it changed with it.
12
+ - **The connectors are unchanged.** `AdtOnPremConnector` and
13
+ `AdtCloudConnector` keep their own `makeAdtRequest` signature, and each is
14
+ assignable to version 5's `IAbapConnection`.
15
+
16
+ ## Who is affected
17
+
18
+ Code that holds a value typed `IAbapConnection` or `AbapConnection` and calls
19
+ `makeAdtRequest<T>(…)` with a type argument. It no longer compiles. Code that
20
+ calls it without a type argument, or holds a connector type, is not affected.
21
+
22
+ ## What to do
23
+
24
+ Drop the type argument and narrow `data` from `unknown` before using it:
25
+
26
+ ```typescript
27
+ import type {
28
+ IAbapConnection,
29
+ IAbapRequestOptions,
30
+ } from "@mcp-abap-adt/interfaces-adt-connection";
31
+
32
+ async function readXml(
33
+ connection: IAbapConnection,
34
+ options: IAbapRequestOptions,
35
+ ): Promise<string> {
36
+ const response = await connection.makeAdtRequest(options);
37
+ if (typeof response.data !== "string") {
38
+ throw new Error("expected a text body");
39
+ }
40
+ return response.data;
41
+ }
42
+ ```
@@ -178,7 +178,9 @@ same session; after a rejection at `'logon'` the wire logs on again before the r
178
178
  **No 401 opens a new session, and the lock in the session is kept:** a mutation
179
179
  (POST / PUT / DELETE) refused with a 401 while a CSRF token is cached goes to the provider and is
180
180
  resent on the same session with the same token, inside a critical section or not, and if SAP did
181
- replace the session the request fails with `SESSION_REPLACED` instead of carrying on in a new one.
181
+ replace the session the instance is spent instead of carrying on in a new one: a stateful request
182
+ fails with `ADT_SESSION_REPLACED`, a stateless one (the mutation is) gets the resend's answer as SAP
183
+ gave it, marked `sessionLost` (since 23.0.0).
182
184
  Before 16.0.0, outside a critical section, that mutation discarded the session and retried in a
183
185
  new one on the same instance; that recovery is gone. One instance is one session: if you want a
184
186
  new session after a 401, create a new connection.
@@ -223,8 +225,9 @@ a substitute: a repeat call does not wait either.
223
225
  - A workflow cannot be resumed by restoring HTTP state into this package: the
224
226
  methods that once did that were removed in 0.2.0. Establish a session with
225
227
  `connect()` and take the locks again — a lock handle from a previous session
226
- is dead, and the connection will say so with `ADT_SESSION_REPLACED` rather
227
- than let you use it.
228
+ is dead. A stateful request (`LOCK`, `UNLOCK`) on a replaced session rejects
229
+ `ADT_SESSION_REPLACED`; a stateless one returns SAP's answer marked
230
+ `sessionLost` (since 23.0.0), and the instance is spent either way.
228
231
 
229
232
  ---
230
233
 
@@ -240,8 +243,9 @@ The link to the ABAP session is not guaranteed, and that is the whole problem:
240
243
 
241
244
  Both are reported, neither is worked around. `connect()` fails with the reason
242
245
  when no session was opened; a session lost afterwards surfaces as
243
- `ADT_SESSION_REPLACED` rather than a request quietly continuing somewhere it
244
- does not belong. What to do about either — wait, retry, create a new connection, release
246
+ `ADT_SESSION_REPLACED` on a stateful request, and as `sessionLost` on the answer
247
+ of a stateless one (since 23.0.0), rather than a request quietly continuing
248
+ somewhere it does not belong. What to do about either — wait, retry, create a new connection, release
245
249
  sessions the user still holds, carry on read-only — is the caller's decision,
246
250
  made with the cookies and the answers in hand.
247
251
 
@@ -349,7 +353,8 @@ close, belongs to whoever passes them around.
349
353
  The server never tells the client how long it has: the session cookie carries no
350
354
  expiry and no response header mentions one. The only honest signals are the ones
351
355
  you get by asking — `getSessionIdentity()` for which session you are in, and
352
- `ADT_SESSION_REPLACED` when the one you were in is gone.
356
+ `ADT_SESSION_REPLACED` (a stateful request) or `sessionLost` (on a stateless
357
+ answer) when the one you were in is gone.
353
358
 
354
359
  ## Troubleshooting
355
360
 
package/docs/USAGE.md CHANGED
@@ -219,7 +219,8 @@ What `connect()` does then:
219
219
  unchanged: the session is this instance's. A stateful request reaches the
220
220
  ABAP context `sap-contextid` names (an `UNLOCK` lands in the old context);
221
221
  later requests carry the credential as usual; a session lost later is
222
- reported as for any instance (`ADT_SESSION_REPLACED`); `disconnect()` logs it
222
+ reported as for any instance (`ADT_SESSION_REPLACED`, or `sessionLost` on a
223
+ stateless answer); `disconnect()` logs it
223
224
  off as for any instance.
224
225
  4. **Gone** — a `401`, a redirect (a `3xx` is not the session answering; it is
225
226
  not followed, so its target is never asked and nothing it sets is taken), or
@@ -274,8 +275,8 @@ them is refused with `ADT_NOT_CONNECTED`.
274
275
  ### GET Request
275
276
 
276
277
  ```typescript
277
- // The body is XML: name its type, or the answer's `data` is `unknown`.
278
- const packages = await connection.makeAdtRequest<string>({
278
+ // The answer's `data` is `unknown`: read the XML body after checking it is text.
279
+ const packages = await connection.makeAdtRequest({
279
280
  method: 'GET',
280
281
  url: '/sap/bc/adt/repository/nodestructure',
281
282
  params: {
@@ -285,6 +286,8 @@ const packages = await connection.makeAdtRequest<string>({
285
286
  },
286
287
  timeout: 0,
287
288
  });
289
+ if (typeof packages.data !== 'string') throw new Error('expected an XML body');
290
+ const xml = packages.data;
288
291
  ```
289
292
 
290
293
  ### POST Request (Create Object)
@@ -512,7 +515,17 @@ side instead of a condition that silently stops matching. The codes live in
512
515
  `@mcp-abap-adt/interfaces-adt-connection` — import them from there, not from this package:
513
516
 
514
517
  ```typescript
515
- import { ADT_SESSION_ERROR } from '@mcp-abap-adt/interfaces-adt-connection';
518
+ import {
519
+ ADT_SESSION_ERROR,
520
+ type IAbapConnectionError,
521
+ } from '@mcp-abap-adt/interfaces-adt-connection';
522
+
523
+ // A caught value comes from outside the type system: your own check narrows it.
524
+ function isConnectionError(
525
+ value: unknown,
526
+ ): value is Error & IAbapConnectionError {
527
+ return value instanceof Error;
528
+ }
516
529
 
517
530
  const options = {
518
531
  method: 'GET',
@@ -521,11 +534,23 @@ const options = {
521
534
  };
522
535
 
523
536
  try {
524
- await connection.makeAdtRequest(options);
537
+ const response = await connection.makeAdtRequest(options);
538
+ if (response.sessionLost === ADT_SESSION_ERROR.SESSION_REPLACED) {
539
+ // A stateless request: SAP's answer is valid and here, and the SAP session
540
+ // is gone with it (since 23.0.0). The instance is spent: the next request
541
+ // needs a new connection.
542
+ }
525
543
  } catch (error) {
526
- if ((error as { code?: string }).code === ADT_SESSION_ERROR.SESSION_REPLACED) {
527
- // The SAP session was replaced under us. Anything locked over the old one
528
- // is orphaned: re-connect, then re-acquire the lock.
544
+ // Narrow the caught value with your own check, then read it by
545
+ // IAbapConnectionError — never by its message.
546
+ if (isConnectionError(error)) {
547
+ if (error.code === ADT_SESSION_ERROR.SESSION_REPLACED) {
548
+ // A stateful request (LOCK, UNLOCK): the session was replaced. Anything
549
+ // locked over the old one is orphaned: re-connect, then re-acquire.
550
+ } else if (error.sessionLost === ADT_SESSION_ERROR.SESSION_REPLACED) {
551
+ // A stateless request refused by SAP, its refusal as it came, and the
552
+ // session gone with it.
553
+ }
529
554
  }
530
555
  }
531
556
  ```
@@ -673,13 +698,34 @@ none over HTTP, and the RFC wire reads it not at all.
673
698
  Two different things can cost you the session, and they do not behave alike.
674
699
 
675
700
  **The session was replaced** — a session cookie (`SAP_SESSIONID`) that changed
676
- underneath you. The request rejects with `ADT_SESSION_REPLACED`: a lock handle
677
- you are carrying is now dead, which is the one thing you cannot work out for
678
- yourself.
701
+ underneath you, the usual cause an idle timeout. What the request gets depends
702
+ on whether it is stateful (since 23.0.0):
703
+
704
+ - **a stateful request** (`LOCK`, `UNLOCK`, anything the connection's session
705
+ mode or the caller's `x-sap-adt-sessiontype: stateful` header marks stateful)
706
+ rejects with `ADT_SESSION_REPLACED`: a lock handle you are carrying is now
707
+ dead, which is the one thing you cannot work out for yourself;
708
+ - **a stateless request** holds no lock and no lock state, so the answer SAP
709
+ gave it is valid and is returned as it came — a success resolves, a refusal
710
+ rejects as itself — with `sessionLost: 'ADT_SESSION_REPLACED'` on that
711
+ response or on that error (`IAdtWireResponse`, `IAbapConnectionError`,
712
+ `@mcp-abap-adt/interfaces-adt-connection`, since 4.2.0). Only the request whose own
713
+ answer showed the replacement carries it. Nothing is sent again for it: no
714
+ CSRF retry, no credential renewal. The session is lost before the answer
715
+ reaches you.
716
+
717
+ The connection's own exchanges inside a request (a CSRF fetch, a logon) have no
718
+ answer of yours to keep: a replacement seen on one is `ADT_SESSION_REPLACED`.
719
+ `connect()` forgets the identity between its own requests, so what it sets up
720
+ is never read as a replacement.
721
+ A resumed session (`createConnection({ …, session })`) whose answer names another
722
+ `SAP_SESSIONID` rejects `connect()` with SAP's answer, as before.
679
723
 
680
724
  **The server says the session is gone** — an answer meaning the session it was
681
725
  given no longer exists. This is **always** fatal, window or not: the connection
682
- raises `ADT_SESSION_REPLACED` and stops being usable. Unlike a replacement,
726
+ raises `ADT_SESSION_REPLACED` and stops being usable — stateless or not, unless
727
+ the same answer also changed the `SAP_SESSIONID`: a stateless refusal that does
728
+ both is a replacement first, that refusal, marked. Unlike a replacement,
683
729
  nothing here suggests a working session to continue on — the one we had is
684
730
  confirmed dead, and re-establishing silently is what let the old connector
685
731
  carry on over a session the caller never opened.
@@ -691,7 +737,8 @@ an answer on a dead pooled socket — see "Kept-alive connections, and the one
691
737
  resend" under the transports; it never resends a request the server answered.)
692
738
 
693
739
  **A lost session spends the instance** (since 16.0.0), as `disconnect()` does.
694
- After either of these, `connect()` and every request on the instance reject
740
+ After either of these — a stateless answer marked `sessionLost` included —
741
+ `connect()` and every request on the instance reject
695
742
  `ADT_SESSION_ERROR.NOT_CONNECTED`, and a new session is a new connection.
696
743
  `disconnect()` is still owed once. It sends the logoff only if the instance
697
744
  still holds a live `SAP_SESSIONID`, and after a loss the connection has
@@ -706,7 +753,9 @@ timeout. `disconnect()` waits for that logoff's write, `flushGoodbye()` for
706
753
  its answer; a `connect()` that found its session replaced rejects once it is
707
754
  written. The old session SAP already ended, and a session reported gone
708
755
  (`400 "Session not found"`) brought no new one: nothing is sent for either.
709
- `ADT_SESSION_REPLACED` reaches the caller as before. Over RFC the
756
+ What reaches the caller is the replacement's answer above: `ADT_SESSION_REPLACED`
757
+ for a stateful request, SAP's answer marked `sessionLost` for a stateless one.
758
+ Over RFC the
710
759
  conversation is the session and no answer can replace it.
711
760
 
712
761
  **Over RFC, an RFC error can end the session** (22.0.0). When an RFC error
@@ -947,10 +996,9 @@ import type { AbapRequestOptions } from '@mcp-abap-adt/connection';
947
996
  import type { IAdtWireResponse } from '@mcp-abap-adt/interfaces-adt-connection';
948
997
  interface AbapConnection {
949
998
  connect(): Promise<void>; // REQUIRED before any request
950
- // An answer whose type is not named is `unknown` (interfaces-adt-connection 2).
951
- makeAdtRequest<T = unknown, D = unknown>(
952
- options: AbapRequestOptions,
953
- ): Promise<IAdtWireResponse<T, D>>;
999
+ // The answer's `data` is `unknown`; the caller names no type for it
1000
+ // (interfaces-adt-connection 5).
1001
+ makeAdtRequest(options: AbapRequestOptions): Promise<IAdtWireResponse>;
954
1002
  getBaseUrl(): Promise<string | undefined>; // undefined over RFC: no HTTP origin
955
1003
  setSessionType(type: "stateless" | "stateful"): void;
956
1004
  getSessionId(): string | null; // client-side conversation id
@@ -1278,8 +1326,9 @@ dropped, established anew — before the resend.
1278
1326
  the session's cookies to open another and retry there. A mutation that meets a
1279
1327
  401 with a CSRF token cached is put to the provider like any other 401; on Ok it
1280
1328
  is resent on the same session with the same token, inside a critical section or
1281
- not, and if SAP did replace the session the request fails with
1282
- `SESSION_REPLACED`. Before 16.0.0, outside a critical section, that mutation
1329
+ not, and if SAP did replace the session the instance is spent: a stateful
1330
+ request fails with `ADT_SESSION_REPLACED`, a stateless one gets the resend's
1331
+ answer marked `sessionLost` (since 23.0.0). Before 16.0.0, outside a critical section, that mutation
1283
1332
  discarded the session and retried in a new one on the same instance, a GET
1284
1333
  401 on a wire with no cookies fetched a token to open one, and a GET 401 with
1285
1334
  cookies held was resent once before the provider was asked; all three are
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-abap-adt/connection",
3
- "version": "22.0.1",
3
+ "version": "24.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",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@mcp-abap-adt/auth-errors": "^2.2.1",
55
- "@mcp-abap-adt/interfaces-adt-connection": "^4.1.0",
55
+ "@mcp-abap-adt/interfaces-adt-connection": "^5.0.0",
56
56
  "@mcp-abap-adt/interfaces-auth": "^7.5.0",
57
57
  "@mcp-abap-adt/interfaces-auth-sap": "^4.0.0",
58
58
  "@mcp-abap-adt/interfaces-network": "^2.0.1",