@mcp-abap-adt/connection 20.1.0 → 22.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.
@@ -0,0 +1,87 @@
1
+ # Migration to 21.0
2
+
3
+ 21.0.0 fetches the CSRF token of a logon with one request. Before, a fetch that
4
+ failed was asked again three times, a second apart: a logon against a closed
5
+ port made four requests and reported its failure about three seconds later.
6
+ A failed request is its own error now — the caller hears it at once, as SAP or
7
+ the network gave it, and whether to try again is the caller's to decide.
8
+
9
+ The fallback endpoint stays, and is not a retry: `/sap/bc/adt/discovery` is
10
+ asked, once, only after `/sap/bc/adt/core/discovery` answered `404` (or `501`)
11
+ — a system that has no such endpoint (BASIS < 7.52).
12
+
13
+ The one named resend stays too: a request sent on a pooled kept-alive socket
14
+ that ended before any byte of an answer is sent once more on a new connection
15
+ (see "Kept-alive connections, and the one resend" in [USAGE](./USAGE.md)).
16
+
17
+ Two more named exceptions stay, unchanged, and are named now beside it (see
18
+ "Two more named resends" in [USAGE](./USAGE.md)). Each sends a request once
19
+ more, at most once for a request, and neither is a plain retry — the second
20
+ attempt carries something the first did not:
21
+
22
+ - **The CSRF recovery.** A request SAP refused over its CSRF token (a `403`
23
+ "CSRF token validation failed", or a `401` to a `POST`, `PUT` or `DELETE`
24
+ sent without a token) gets a token fetched in the same session — one fetch,
25
+ no retry — and is sent once more with it.
26
+ - **The credential's renewal.** A `401`, or a refused logon, goes to the
27
+ provider's `rejected()`; on Ok the request or the logon is sent once more
28
+ with the renewed credential. A second refusal is `AuthRefusedError`.
29
+
30
+ ## What changed
31
+
32
+ - **The token fetch is one request per endpoint**, with no delay: on
33
+ `connect()`, before a mutation that holds no token, and in the recovery
34
+ after a `403` "CSRF token validation failed" (which asked up to six times,
35
+ two seconds apart). A `500`, a refused connection or a `200` without a token
36
+ ends the fetch at once with that error: `connect()` rejects with it, the
37
+ recovery rethrows the error it started from, as before, and the fetch before
38
+ a mutation is still only logged, the mutation sent as it was.
39
+ - **Removed from the public surface:**
40
+ - `CSRF_CONFIG.RETRY_COUNT` and `CSRF_CONFIG.RETRY_DELAY`;
41
+ - `IAdtEstablishContext.retries` and `IAdtEstablishContext.retryDelayMs`;
42
+ - `IAdtEstablishContext.isFatal`. It said which failures must not be
43
+ retried. With nothing retried it has nothing left to decide: a session
44
+ verdict the connection throws (from `authorize` or `observe`) carries no
45
+ response, so the wire neither folds it in nor reads it as an absent
46
+ endpoint, and it reaches the caller as it is;
47
+ - the `retryCount` and `retryDelay` parameters of the protected
48
+ `fetchCsrfToken(url, retryCount?, retryDelay?, fence?)`, now
49
+ `fetchCsrfToken(url, fence?)`;
50
+ - the protected `endsTheExchange(error)`, which only fed `isFatal`.
51
+
52
+ `IAdtEstablishContext` itself stays, now with the members of
53
+ `IAdtSessionContext`. `CSRF_CONFIG.ENDPOINT`, `FALLBACK_ENDPOINT`,
54
+ `REQUIRED_HEADERS` and `CSRF_ERROR_MESSAGES` are unchanged.
55
+
56
+ ## What to do
57
+
58
+ **Code that read `CSRF_CONFIG.RETRY_COUNT` or `RETRY_DELAY`** (a connection
59
+ class of your own, say) drops them. To fetch a token the way this package
60
+ does: one request to `ENDPOINT`, and one to `FALLBACK_ENDPOINT` only when the
61
+ first answered `404` or `501` — see the `CSRF_CONFIG` example in [USAGE](./USAGE.md).
62
+
63
+ **A wire of your own** (`IAdtTransport.establish(context)`) that read
64
+ `context.retries`, `context.retryDelayMs` or `context.isFatal` stops reading
65
+ them: the connection no longer passes them. If your wire repeats its own
66
+ exchange, the connection's rule is that it should not.
67
+
68
+ **A subclass that called `fetchCsrfToken`** drops the two numbers:
69
+
70
+ ```diff
71
+ -this.fetchCsrfToken(url, 0, 0, generation)
72
+ +this.fetchCsrfToken(url, generation)
73
+ ```
74
+
75
+ **A subclass that overrode `endsTheExchange`** removes the override: nothing
76
+ calls it.
77
+
78
+ **A caller that relied on the retries** to ride out a system that was not
79
+ answering yet — an application server restarting, a tunnel coming up — waits
80
+ and calls `connect()` again on a new instance, on its own schedule. A failed
81
+ `connect()` that received no session cookie leaves its instance usable, and
82
+ `connect()` may be called on it again (see "Session Lifecycle" in
83
+ [USAGE](./USAGE.md)).
84
+
85
+ If you only call `createConnection`, the connectors and `makeAdtRequest`, there
86
+ is nothing to change in your code; a failure to fetch the token reaches you
87
+ sooner.
@@ -0,0 +1,78 @@
1
+ # Migration to 22.0
2
+
3
+ 22.0.0 changes three things on the RFC wire. HTTP is unchanged.
4
+
5
+ ## What changed
6
+
7
+ - **An RFC error that ends the stateful conversation ends the instance's
8
+ session.** The stateful conversation carries the instance's session and every
9
+ lock taken in it. When an RFC error ends it — sap-rfc-lite 0.4.0 releases it
10
+ (`alive` is `false`) — the request rejects with `code`
11
+ `ADT_SESSION_REPLACED` and the RFC call's fields as `rfc`; the instance is
12
+ spent: every later request and `connect()` reject `ADT_NOT_CONNECTED`, and
13
+ nothing is sent. The connection opens no new session on its own. With 21.x
14
+ and sap-rfc-lite 0.3.x the next request went on, silently, on a new session,
15
+ and a lock taken in the old one was gone without a word.
16
+ - **A failed RFC call carries `rfc`.** When the SDK names the failure, the
17
+ error carries `rfc: { key, group, code, codeString }` (`IRfcErrorInfo` from
18
+ `@mcp-abap-adt/interfaces-adt-connection` 4.1; `codeString` is one of
19
+ `RFC_RCS`), on every conversation, stateful or not. The top-level `code`
20
+ keeps its meaning: unset on a call's failure, whose message is the call's
21
+ (`RFC call to SADT_REST_RFC_ENDPOINT failed: …`); when the error ended the
22
+ stateful conversation, the message is the session-lost one and `code` is
23
+ `ADT_SESSION_REPLACED` (above).
24
+ - **The `SAP-PASSPORT` header becomes the RFC call's passport.** Over RFC the
25
+ header is hex-decoded and handed to sap-rfc-lite for that call only; it is no
26
+ longer sent to `SADT_REST_RFC_ENDPOINT` as a header field (which never read
27
+ it). A value that is not hex, or the header named twice, is refused before
28
+ anything is sent.
29
+ - **`@mcp-abap-adt/sap-rfc-lite` ^0.4.0**, an optional dependency as before.
30
+
31
+ ## What to do
32
+
33
+ **Read an RFC failure from `rfc`, not from the message.** The caught value
34
+ is checked, as anything caught is; what it may carry is
35
+ `IAbapConnectionError` (`code`, `rfc`):
36
+
37
+ ```typescript
38
+ import type { RfcReturnCodeName } from "@mcp-abap-adt/interfaces-adt-connection";
39
+
40
+ function rfcCodeOf(error: unknown): string | undefined {
41
+ if (typeof error !== "object" || error === null || !("rfc" in error)) {
42
+ return undefined;
43
+ }
44
+ const { rfc } = error;
45
+ return typeof rfc === "object" && rfc !== null && "codeString" in rfc &&
46
+ typeof rfc.codeString === "string"
47
+ ? rfc.codeString
48
+ : undefined;
49
+ }
50
+
51
+ const closed: RfcReturnCodeName = "RFC_CLOSED";
52
+ function conversationClosed(error: unknown): boolean {
53
+ return rfcCodeOf(error) === closed;
54
+ }
55
+ ```
56
+
57
+ **After `ADT_SESSION_REPLACED` over RFC, create a new connection.** The
58
+ instance is spent, as after any lost session. Every lock taken on the old
59
+ session is gone: take it again on the new one, never carry its lock handle
60
+ over. `disconnect()` is still owed once on the old instance; it sends nothing
61
+ for the ended conversation.
62
+
63
+ **A stateful session caught by a debugger stays caught.** Once an external
64
+ debugger caught a call on the stateful RFC session, later calls on it are
65
+ caught too, with or without a passport, until the session ends; the connection
66
+ does not reset it, because that would drop its locks. Send a run meant to be
67
+ caught as a non-stateful request, or on a connection of its own.
68
+
69
+ **Install sap-rfc-lite 0.4.0 or newer** where you take the RFC wire:
70
+ `npm install @mcp-abap-adt/sap-rfc-lite@^0.4.0`.
71
+
72
+ **A wire of your own** that loses the session it carries throws
73
+ `WireSessionLostError` (exported beside `WireLogonError`); the connection then
74
+ reports `ADT_SESSION_REPLACED` and spends the instance, as it does for RFC.
75
+
76
+ **A conversation factory of your own** (`RfcConversationFactory`) keeps
77
+ working: `IRfcConversation.call` gains an optional third parameter
78
+ (`{ passport? }`), passed only when a request carries a passport.
package/docs/USAGE.md CHANGED
@@ -209,7 +209,7 @@ What `connect()` does then:
209
209
  1. It prepares the credential as always, and **logs on nowhere**.
210
210
  2. It makes **one request in that session, without the credential**: the CSRF
211
211
  fetch (`GET /sap/bc/adt/core/discovery` with `x-csrf-token: fetch`, the
212
- fallback `/sap/bc/adt/discovery` on a `404`; on cloud with
212
+ fallback `/sap/bc/adt/discovery` on a `404` or `501`; on cloud with
213
213
  `x-sap-security-session: use`, and no preflight), following no redirect.
214
214
  Without the credential,
215
215
  because a credential on that request would open a NEW session when the old
@@ -709,6 +709,24 @@ written. The old session SAP already ended, and a session reported gone
709
709
  `ADT_SESSION_REPLACED` reaches the caller as before. Over RFC the
710
710
  conversation is the session and no answer can replace it.
711
711
 
712
+ **Over RFC, an RFC error can end the session** (22.0.0). When an RFC error
713
+ ends the stateful conversation — sap-rfc-lite releases it (`alive` is
714
+ `false`) — the session it carried is gone with its locks. The request rejects
715
+ `ADT_SESSION_REPLACED`, with the RFC call's fields as `rfc` (`key`, `group`,
716
+ `code`, `codeString`), and the instance is spent as above: `connect()` and
717
+ every request reject `ADT_NOT_CONNECTED`, nothing is sent, and no new
718
+ conversation is opened. Before 22.0.0 the next request went on, silently, on a
719
+ new session, its locks gone. Create a new connection for a new session. A
720
+ non-stateful conversation an RFC error ends is not the instance's session: it
721
+ is dropped as a failed reset drops it, the next call opens another, and the
722
+ instance goes on. The wire says it with `WireSessionLostError`; the connection
723
+ acts on that class, whichever wire throws it.
724
+
725
+ **A caught stateful session stays caught.** Once an external debugger caught
726
+ a call on the stateful RFC session, later calls on it are caught too, with or
727
+ without a passport, until it ends. The connection does not reset it: that
728
+ would drop its locks.
729
+
712
730
  ## Advanced Features
713
731
 
714
732
  ### Session ID Management
@@ -1069,12 +1087,55 @@ carries it; the wire never reads `config.username` or `config.password`.
1069
1087
  enqueue lock stayed until SM12 (mcp-abap-adt#314).
1070
1088
  The logoff goes out on a connection of its own, with `Connection: close`,
1071
1089
  whatever your `agentOptions` say.
1090
+ - **Two more named resends** (named in 21.0.0; the behaviour is older). Beside
1091
+ the one above, a request is sent once more in exactly two cases — each at most
1092
+ once for a request, never a second time:
1093
+
1094
+ - **The CSRF recovery.** SAP refused the request over its CSRF token — a `403`
1095
+ "CSRF token validation failed", or an answer whose body names the CSRF token
1096
+ — or answered `401` to a `POST`, `PUT` or `DELETE` sent while the wire held
1097
+ no token. The wire fetches a token in the same session (its cookies kept; one
1098
+ fetch, no retry) and sends the request once more, authorized anew. Not a plain
1099
+ retry: the request was refused for what it carried — a stale or missing token
1100
+ — and goes again carrying something different, the fresh token; sent as it
1101
+ was, it would only be refused again. A resend that fails ends the request: a
1102
+ session verdict or the credential's refusal is thrown, anything else rethrows
1103
+ the error the recovery started from.
1104
+ - **The credential's renewal.** A `401`, or a logon the system refused, goes to
1105
+ the provider (`rejected()`); when it answers Ok, the request — or the logon —
1106
+ is authorized again and sent once more, in the same session. Not a plain retry
1107
+ either: the provider renewed what the attempt carries, and the attempt carries
1108
+ the new credential. One per request: a second refusal is `AuthRefusedError`
1109
+ (refused again), and the provider is not asked twice. A `403` never goes to
1110
+ the provider.
1111
+
1112
+ Nothing else is sent again: a failed request — the CSRF token fetch included
1113
+ (21.0.0) — is its own error.
1072
1114
  - RFC takes logon parameters (a password, or SNC settings) on every conversation
1073
1115
  it opens, the session's own and each per-call one. RFC refuses TLS material,
1074
1116
  and a provider that writes no logon parameters (a bearer token) cannot log on
1075
1117
  over RFC: the open fails, the provider is asked, and you get its refusal.
1076
1118
  - A failed RFC open is thrown as `WireLogonError` with the SDK's own error as
1077
1119
  `cause`, so a provider can read the SDK's `key` and message.
1120
+ - **A failed RFC call carries `rfc`** (22.0.0): `{ key, group, code,
1121
+ codeString }` (`IRfcErrorInfo`, `codeString` one of `RFC_RCS`, both from
1122
+ `@mcp-abap-adt/interfaces-adt-connection`), checked once where the wire
1123
+ receives the SDK's error — own data properties only, nothing read out of a
1124
+ message. An error the SDK did not name carries no `rfc`. `rfc` is carried on
1125
+ every conversation, stateful or not. The message is the call's
1126
+ (`RFC call to SADT_REST_RFC_ENDPOINT failed: …`, ending in fixed words when
1127
+ the thrown value cannot be described) and the top-level `code` is not set —
1128
+ except when the error ended the stateful conversation: then the message is
1129
+ the session-lost one ("The RFC conversation that carried this connection's
1130
+ SAP session has ended; …") and `code` is `ADT_SESSION_REPLACED`, the instance
1131
+ spent (README, "RFC").
1132
+ - **The `SAP-PASSPORT` header is the RFC call's passport** (22.0.0). Its name
1133
+ read without case, its value hex-decoded and handed to sap-rfc-lite as
1134
+ `call(…, { passport })` for that call only, on whichever conversation carries
1135
+ the request; it is not sent as a header field (`SADT_REST_RFC_ENDPOINT` reads
1136
+ none). A value that is not hex, or the header named twice, is refused before
1137
+ anything is sent, the value never quoted. No header: no passport, the call as
1138
+ before.
1078
1139
 
1079
1140
  **`logWire` dumps the wire, and is off.** With it on, `RfcTransport` adds three
1080
1141
  debug lines per request — the header fields, the request body and the response
@@ -1115,9 +1176,8 @@ Exported constants for consistent CSRF token handling across different connectio
1115
1176
 
1116
1177
  // CSRF_CONFIG structure:
1117
1178
  const config = {
1118
- RETRY_COUNT: 3, // Number of retry attempts
1119
- RETRY_DELAY: 1000, // Delay between retries (ms)
1120
1179
  ENDPOINT: '/sap/bc/adt/core/discovery', // CSRF token endpoint
1180
+ FALLBACK_ENDPOINT: '/sap/bc/adt/discovery', // asked only after a 404 or 501 there (BASIS < 7.52)
1121
1181
  REQUIRED_HEADERS: {
1122
1182
  'x-csrf-token': 'fetch',
1123
1183
  'Accept': 'application/atomsvc+xml'
@@ -1140,43 +1200,27 @@ import { executeHttpRequest } from '@sap-cloud-sdk/http-client';
1140
1200
 
1141
1201
  export class CloudSdkAbapConnection {
1142
1202
  async fetchCsrfToken(baseUrl: string): Promise<string> {
1143
- const csrfUrl = `${baseUrl}${CSRF_CONFIG.ENDPOINT}`;
1144
-
1145
- for (let attempt = 0; attempt <= CSRF_CONFIG.RETRY_COUNT; attempt++) {
1146
- try {
1147
- const response = await executeHttpRequest(
1148
- { destinationName: this.destination },
1149
- {
1150
- method: 'GET',
1151
- url: csrfUrl,
1152
- headers: CSRF_CONFIG.REQUIRED_HEADERS
1153
- }
1154
- );
1155
-
1156
- const token = response.headers['x-csrf-token'];
1157
- if (!token) {
1158
- if (attempt < CSRF_CONFIG.RETRY_COUNT) {
1159
- await new Promise(resolve => setTimeout(resolve, CSRF_CONFIG.RETRY_DELAY));
1160
- continue;
1161
- }
1162
- throw new Error(CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
1163
- }
1164
-
1165
- return token;
1166
- } catch (error) {
1167
- if (attempt >= CSRF_CONFIG.RETRY_COUNT) {
1168
- throw new Error(
1169
- CSRF_ERROR_MESSAGES.FETCH_FAILED(
1170
- CSRF_CONFIG.RETRY_COUNT + 1,
1171
- error instanceof Error ? failure.message : String(error)
1172
- )
1173
- );
1174
- }
1175
- await new Promise(resolve => setTimeout(resolve, CSRF_CONFIG.RETRY_DELAY));
1176
- }
1203
+ // One request, and the fallback endpoint only when the first answers
1204
+ // 404 or 501 — the way this package fetches its own: no retry, no delay. A
1205
+ // failed request is its own error.
1206
+ const ask = (path: string) =>
1207
+ executeHttpRequest(
1208
+ { destinationName: this.destination },
1209
+ { method: 'GET', url: `${baseUrl}${path}`, headers: CSRF_CONFIG.REQUIRED_HEADERS }
1210
+ );
1211
+
1212
+ let response;
1213
+ try {
1214
+ response = await ask(CSRF_CONFIG.ENDPOINT);
1215
+ } catch (error) {
1216
+ const status = error?.response?.status;
1217
+ if (status !== 404 && status !== 501) throw error;
1218
+ response = await ask(CSRF_CONFIG.FALLBACK_ENDPOINT);
1177
1219
  }
1178
-
1179
- throw new Error(CSRF_ERROR_MESSAGES.FETCH_FAILED(CSRF_CONFIG.RETRY_COUNT + 1, 'Unknown error'));
1220
+
1221
+ const token = response.headers['x-csrf-token'];
1222
+ if (!token) throw new Error(CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
1223
+ return token;
1180
1224
  }
1181
1225
  }
1182
1226
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-abap-adt/connection",
3
- "version": "20.1.0",
3
+ "version": "22.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.0.0",
55
+ "@mcp-abap-adt/interfaces-adt-connection": "^4.1.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",
@@ -60,7 +60,7 @@
60
60
  "axios": "^1.16.0"
61
61
  },
62
62
  "optionalDependencies": {
63
- "@mcp-abap-adt/sap-rfc-lite": "^0.3.2"
63
+ "@mcp-abap-adt/sap-rfc-lite": "^0.4.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@biomejs/biome": "^2.3.14",