@mcp-abap-adt/connection 20.0.0 → 21.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/docs/INDEX.md CHANGED
@@ -15,6 +15,7 @@ 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-21.0.md # the CSRF token fetch asks once: no retry, no delay
18
19
  │ ├── MIGRATION-20.0.md # an RFC config states its address, client and language; no URL over RFC
19
20
  │ ├── MIGRATION-18.0.md # rfcParamsFrom returns RfcAddress; RFC through a message server
20
21
  │ ├── MIGRATION-17.0.md # no deadline of the package's own; an instance on an existing session
@@ -50,6 +51,7 @@ mcp-abap-connection/
50
51
  - 🧭 [Scope](./SCOPE.md) - What this package answers for, and only that
51
52
 
52
53
  ### Upgrading
54
+ - 🚚 [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
53
55
  - 🚚 [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`
54
56
  - 🚚 [Migrating to 18.0.0](./MIGRATION-18.0.md) - `rfcParamsFrom` returns `RfcAddress`; RFC through a message server and a logon group
55
57
  - 🚚 [Migrating to 17.0.0](./MIGRATION-17.0.md) - `getTimeout`, `getTimeoutConfig` and `SAP_TIMEOUT_*` are gone; a request carries only the caller's `timeout`, and none inside a critical section; `createConnection({ …, session })` and `sessionCookies()`
@@ -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.
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
@@ -1003,7 +1003,7 @@ establishing, and whatever session state it keeps.
1003
1003
  ```text
1004
1004
  new HttpTransport(agentOptions?, logger?, { client?, baseUrl, httpClient? })
1005
1005
  new RfcTransport(
1006
- connect: (logon: Readonly<Record<string, string>>) => IRfcConversation,
1006
+ connect: RfcConversationFactory, // (logon) => IRfcConversation, and its logon `language`
1007
1007
  logger?,
1008
1008
  { logWire?, maxLoggedBodyChars? },
1009
1009
  )
@@ -1028,7 +1028,14 @@ here, under the wire, so what the wire adds to its own requests still runs.
1028
1028
  `RfcTransport` you build
1029
1029
  with `rfcConversationFrom(rfcConfig)`, which takes the RFC config's stated
1030
1030
  address, `client` and `language` as they are and loads the SAP NW RFC SDK only
1031
- when a conversation opens.
1031
+ when a conversation opens. It states that `language` as the factory's logon
1032
+ language. A request's `sap-language` (header or query parameter) is compared
1033
+ with the logon language of the conversation that would carry it — the `lang`
1034
+ its logon carries: the provider's where it writes one, else the factory's. A
1035
+ non-stateful request naming another one goes on a conversation logged on in
1036
+ it, opened for that call and closed after it, and a stateful one is refused
1037
+ before it is sent — a session cannot change its language. See the README, "A request's
1038
+ language over RFC".
1032
1039
 
1033
1040
  **What the wire takes from the credential.** The provider writes it, the wire
1034
1041
  carries it; the wire never reads `config.username` or `config.password`.
@@ -1062,6 +1069,30 @@ carries it; the wire never reads `config.username` or `config.password`.
1062
1069
  enqueue lock stayed until SM12 (mcp-abap-adt#314).
1063
1070
  The logoff goes out on a connection of its own, with `Connection: close`,
1064
1071
  whatever your `agentOptions` say.
1072
+ - **Two more named resends** (named in 21.0.0; the behaviour is older). Beside
1073
+ the one above, a request is sent once more in exactly two cases — each at most
1074
+ once for a request, never a second time:
1075
+
1076
+ - **The CSRF recovery.** SAP refused the request over its CSRF token — a `403`
1077
+ "CSRF token validation failed", or an answer whose body names the CSRF token
1078
+ — or answered `401` to a `POST`, `PUT` or `DELETE` sent while the wire held
1079
+ no token. The wire fetches a token in the same session (its cookies kept; one
1080
+ fetch, no retry) and sends the request once more, authorized anew. Not a plain
1081
+ retry: the request was refused for what it carried — a stale or missing token
1082
+ — and goes again carrying something different, the fresh token; sent as it
1083
+ was, it would only be refused again. A resend that fails ends the request: a
1084
+ session verdict or the credential's refusal is thrown, anything else rethrows
1085
+ the error the recovery started from.
1086
+ - **The credential's renewal.** A `401`, or a logon the system refused, goes to
1087
+ the provider (`rejected()`); when it answers Ok, the request — or the logon —
1088
+ is authorized again and sent once more, in the same session. Not a plain retry
1089
+ either: the provider renewed what the attempt carries, and the attempt carries
1090
+ the new credential. One per request: a second refusal is `AuthRefusedError`
1091
+ (refused again), and the provider is not asked twice. A `403` never goes to
1092
+ the provider.
1093
+
1094
+ Nothing else is sent again: a failed request — the CSRF token fetch included
1095
+ (21.0.0) — is its own error.
1065
1096
  - RFC takes logon parameters (a password, or SNC settings) on every conversation
1066
1097
  it opens, the session's own and each per-call one. RFC refuses TLS material,
1067
1098
  and a provider that writes no logon parameters (a bearer token) cannot log on
@@ -1108,9 +1139,8 @@ Exported constants for consistent CSRF token handling across different connectio
1108
1139
 
1109
1140
  // CSRF_CONFIG structure:
1110
1141
  const config = {
1111
- RETRY_COUNT: 3, // Number of retry attempts
1112
- RETRY_DELAY: 1000, // Delay between retries (ms)
1113
1142
  ENDPOINT: '/sap/bc/adt/core/discovery', // CSRF token endpoint
1143
+ FALLBACK_ENDPOINT: '/sap/bc/adt/discovery', // asked only after a 404 or 501 there (BASIS < 7.52)
1114
1144
  REQUIRED_HEADERS: {
1115
1145
  'x-csrf-token': 'fetch',
1116
1146
  'Accept': 'application/atomsvc+xml'
@@ -1133,43 +1163,27 @@ import { executeHttpRequest } from '@sap-cloud-sdk/http-client';
1133
1163
 
1134
1164
  export class CloudSdkAbapConnection {
1135
1165
  async fetchCsrfToken(baseUrl: string): Promise<string> {
1136
- const csrfUrl = `${baseUrl}${CSRF_CONFIG.ENDPOINT}`;
1137
-
1138
- for (let attempt = 0; attempt <= CSRF_CONFIG.RETRY_COUNT; attempt++) {
1139
- try {
1140
- const response = await executeHttpRequest(
1141
- { destinationName: this.destination },
1142
- {
1143
- method: 'GET',
1144
- url: csrfUrl,
1145
- headers: CSRF_CONFIG.REQUIRED_HEADERS
1146
- }
1147
- );
1148
-
1149
- const token = response.headers['x-csrf-token'];
1150
- if (!token) {
1151
- if (attempt < CSRF_CONFIG.RETRY_COUNT) {
1152
- await new Promise(resolve => setTimeout(resolve, CSRF_CONFIG.RETRY_DELAY));
1153
- continue;
1154
- }
1155
- throw new Error(CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
1156
- }
1157
-
1158
- return token;
1159
- } catch (error) {
1160
- if (attempt >= CSRF_CONFIG.RETRY_COUNT) {
1161
- throw new Error(
1162
- CSRF_ERROR_MESSAGES.FETCH_FAILED(
1163
- CSRF_CONFIG.RETRY_COUNT + 1,
1164
- error instanceof Error ? failure.message : String(error)
1165
- )
1166
- );
1167
- }
1168
- await new Promise(resolve => setTimeout(resolve, CSRF_CONFIG.RETRY_DELAY));
1169
- }
1166
+ // One request, and the fallback endpoint only when the first answers
1167
+ // 404 or 501 — the way this package fetches its own: no retry, no delay. A
1168
+ // failed request is its own error.
1169
+ const ask = (path: string) =>
1170
+ executeHttpRequest(
1171
+ { destinationName: this.destination },
1172
+ { method: 'GET', url: `${baseUrl}${path}`, headers: CSRF_CONFIG.REQUIRED_HEADERS }
1173
+ );
1174
+
1175
+ let response;
1176
+ try {
1177
+ response = await ask(CSRF_CONFIG.ENDPOINT);
1178
+ } catch (error) {
1179
+ const status = error?.response?.status;
1180
+ if (status !== 404 && status !== 501) throw error;
1181
+ response = await ask(CSRF_CONFIG.FALLBACK_ENDPOINT);
1170
1182
  }
1171
-
1172
- throw new Error(CSRF_ERROR_MESSAGES.FETCH_FAILED(CSRF_CONFIG.RETRY_COUNT + 1, 'Unknown error'));
1183
+
1184
+ const token = response.headers['x-csrf-token'];
1185
+ if (!token) throw new Error(CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
1186
+ return token;
1173
1187
  }
1174
1188
  }
1175
1189
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-abap-adt/connection",
3
- "version": "20.0.0",
3
+ "version": "21.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",