@mcp-abap-adt/connection 20.1.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/CHANGELOG.md CHANGED
@@ -7,6 +7,43 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [21.0.0] - 2026-11-11
11
+
12
+ The CSRF token fetch asks once. Breaking for code that reads `CSRF_CONFIG.RETRY_COUNT` /
13
+ `RETRY_DELAY`, for a wire of its own that reads the establish context's `retries`,
14
+ `retryDelayMs` or `isFatal`, and for a subclass that calls `fetchCsrfToken` with retry numbers or
15
+ overrides `endsTheExchange`; a caller of `createConnection`, the connectors and `makeAdtRequest`
16
+ changes nothing. See [docs/MIGRATION-21.0.md](docs/MIGRATION-21.0.md).
17
+
18
+ ### Changed — breaking
19
+
20
+ - **The CSRF token fetch is one request per endpoint, with no retry and no delay.** A logon
21
+ against a closed port made four requests about a second apart and reported its failure some
22
+ three seconds later; the recovery after a `403` "CSRF token validation failed" asked up to six
23
+ times, two seconds apart. A failed request is its own error now: `connect()` rejects with it at
24
+ once. The fallback endpoint `/sap/bc/adt/discovery` is still asked, once, only after
25
+ `/sap/bc/adt/core/discovery` answered `404` or `501` (BASIS < 7.52) — it is not a retry. The
26
+ named resend on a pooled socket that ended before any answer byte (#314) is unchanged.
27
+ - **Removed:** `CSRF_CONFIG.RETRY_COUNT`, `CSRF_CONFIG.RETRY_DELAY`;
28
+ `IAdtEstablishContext.retries`, `.retryDelayMs` and `.isFatal` (with nothing retried it decides
29
+ nothing: a session verdict carries no response, so the wire neither folds it in nor reads it as
30
+ an absent endpoint); the `retryCount` / `retryDelay` parameters of the protected
31
+ `fetchCsrfToken`, now `fetchCsrfToken(url, fence?)`; the protected `endsTheExchange`.
32
+
33
+ ### Fixed
34
+
35
+ - **A CSRF token is read as one non-empty string.** Response headers come from outside the type
36
+ system: an `x-csrf-token` that arrived as an array (the header twice), a number or an empty
37
+ value was stored as the token; it is now no token — on a success the fetch fails
38
+ `NOT_IN_HEADERS`, on a refusal nothing is kept.
39
+
40
+ ### Documentation
41
+
42
+ - **The two other resends are named beside the #314 one**, in the README and USAGE ("Two more
43
+ named resends"): the CSRF recovery (a token fetched in the same session and one resend after a
44
+ refusal over the token) and the credential's renewal (one more attempt after `rejected()`
45
+ answers Ok). Both are unchanged; each happens at most once for a request.
46
+
10
47
  ## [20.1.0] - 2026-11-09
11
48
 
12
49
  A request runs in its `sap-language` over RFC as it does over HTTP.
@@ -2870,7 +2907,8 @@ const connection = createAbapConnection(config, logger);
2870
2907
  - JWT token refresh now properly handles connection errors (401/403 during initial connect)
2871
2908
  - Permission errors (403 with "ExceptionResourceNoAccess") no longer trigger JWT refresh loops
2872
2909
  - Proper separation: base class handles HTTP/session, concrete classes handle auth-specific errors
2873
- [Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v20.1.0...HEAD
2910
+ [Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v21.0.0...HEAD
2911
+ [21.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v20.1.0...v21.0.0
2874
2912
  [20.1.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v20.0.0...v20.1.0
2875
2913
  [20.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v19.1.0...v20.0.0
2876
2914
  [19.1.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v19.0.0...v19.1.0
package/README.md CHANGED
@@ -162,6 +162,7 @@ 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 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
165
166
  - 🚚 **[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`
166
167
  - 🚚 **[Migration to 19.0.0](./docs/MIGRATION-19.0.md)** - `@mcp-abap-adt/sap-rfc-lite` ^0.3.2: no compile on install; prebuilt RFC bindings for linux-x64, win32-x64, darwin-arm64; elsewhere build sap-rfc-lite's binding from its repository; the API is unchanged
167
168
  - 🚚 **[Migration to 18.0.0](./docs/MIGRATION-18.0.md)** - `rfcParamsFrom` returns `RfcAddress` (application server or message server): narrow before reading `.ashost` / `.sysnr`; RFC through a message server and a logon group (`mshost`, `msserv` | `sysid`, `group`, `saprouter`)
@@ -301,6 +302,31 @@ answer would run it twice; for a socket the server closed while it was idle,
301
302
  that does not happen. Without the resend, a cleanup `UNLOCK` died so and the
302
303
  enqueue lock stayed until SM12 (mcp-abap-adt#314).
303
304
 
305
+ **Two more named resends** (named in 21.0.0; the behaviour is older). Beside
306
+ the one above, a request is sent once more in exactly two cases — each at most
307
+ once for a request, never a second time:
308
+
309
+ - **The CSRF recovery.** SAP refused the request over its CSRF token — a `403`
310
+ "CSRF token validation failed", or an answer whose body names the CSRF token
311
+ — or answered `401` to a `POST`, `PUT` or `DELETE` sent while the wire held
312
+ no token. The wire fetches a token in the same session (its cookies kept; one
313
+ fetch, no retry) and sends the request once more, authorized anew. Not a plain
314
+ retry: the request was refused for what it carried — a stale or missing token
315
+ — and goes again carrying something different, the fresh token; sent as it
316
+ was, it would only be refused again. A resend that fails ends the request: a
317
+ session verdict or the credential's refusal is thrown, anything else rethrows
318
+ the error the recovery started from.
319
+ - **The credential's renewal.** A `401`, or a logon the system refused, goes to
320
+ the provider (`rejected()`); when it answers Ok, the request — or the logon —
321
+ is authorized again and sent once more, in the same session. Not a plain retry
322
+ either: the provider renewed what the attempt carries, and the attempt carries
323
+ the new credential. One per request: a second refusal is `AuthRefusedError`
324
+ (refused again), and the provider is not asked twice. A `403` never goes to
325
+ the provider.
326
+
327
+ Nothing else is sent again: a failed request — the CSRF token fetch included
328
+ (21.0.0) — is its own error.
329
+
304
330
  ### An instance on an existing session
305
331
 
306
332
  An instance may be built on a session that already exists, instead of logging
@@ -988,9 +1014,8 @@ own in that language, and every stateful one naming it is refused.
988
1014
  import { CSRF_CONFIG, CSRF_ERROR_MESSAGES } from '@mcp-abap-adt/connection';
989
1015
 
990
1016
  // CSRF_CONFIG contains:
991
- // - RETRY_COUNT: number (default: 3)
992
- // - RETRY_DELAY: number (default: 1000ms)
993
1017
  // - ENDPOINT: string (default: '/sap/bc/adt/core/discovery')
1018
+ // - FALLBACK_ENDPOINT: string (default: '/sap/bc/adt/discovery', BASIS < 7.52)
994
1019
  // - REQUIRED_HEADERS: { 'x-csrf-token': 'fetch', 'Accept': 'application/atomsvc+xml' }
995
1020
 
996
1021
  // CSRF_ERROR_MESSAGES contains:
@@ -1010,41 +1035,28 @@ const yourHttpClient = {
1010
1035
  ({ headers: {} as Record<string, string> }),
1011
1036
  };
1012
1037
 
1038
+ // One request, and the fallback endpoint only when the first answers 404 or 501 —
1039
+ // the way this package fetches its own: no retry, no delay. A failed request
1040
+ // is its own error, and the caller decides what to do about it.
1013
1041
  async function fetchCsrfToken(baseUrl: string): Promise<string> {
1014
- const csrfUrl = `${baseUrl}${CSRF_CONFIG.ENDPOINT}`;
1015
-
1016
- for (let attempt = 0; attempt <= CSRF_CONFIG.RETRY_COUNT; attempt++) {
1017
- try {
1018
- const response = await yourHttpClient.get(csrfUrl, {
1019
- headers: CSRF_CONFIG.REQUIRED_HEADERS
1020
- });
1021
-
1022
- const token = response.headers['x-csrf-token'];
1023
- if (!token) {
1024
- if (attempt < CSRF_CONFIG.RETRY_COUNT) {
1025
- await new Promise(resolve => setTimeout(resolve, CSRF_CONFIG.RETRY_DELAY));
1026
- continue;
1027
- }
1028
- throw new Error(CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
1029
- }
1030
-
1031
- return token;
1032
- } catch (error) {
1033
- if (attempt >= CSRF_CONFIG.RETRY_COUNT) {
1034
- throw new Error(
1035
- CSRF_ERROR_MESSAGES.FETCH_FAILED(
1036
- CSRF_CONFIG.RETRY_COUNT + 1,
1037
- error instanceof Error ? error.message : String(error)
1038
- )
1039
- );
1040
- }
1041
- await new Promise(resolve => setTimeout(resolve, CSRF_CONFIG.RETRY_DELAY));
1042
- }
1042
+ let response: { headers: Record<string, string> };
1043
+ try {
1044
+ response = await yourHttpClient.get(`${baseUrl}${CSRF_CONFIG.ENDPOINT}`, {
1045
+ headers: CSRF_CONFIG.REQUIRED_HEADERS,
1046
+ });
1047
+ } catch (error) {
1048
+ const status = (error as { response?: { status?: number } }).response
1049
+ ?.status;
1050
+ if (status !== 404 && status !== 501) throw error;
1051
+ response = await yourHttpClient.get(
1052
+ `${baseUrl}${CSRF_CONFIG.FALLBACK_ENDPOINT}`,
1053
+ { headers: CSRF_CONFIG.REQUIRED_HEADERS },
1054
+ );
1043
1055
  }
1044
1056
 
1045
- // Unreachable: the last attempt either returns or throws above. Stated so the
1046
- // function has a return type the compiler can agree with.
1047
- throw new Error(CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
1057
+ const token = response.headers['x-csrf-token'];
1058
+ if (!token) throw new Error(CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
1059
+ return token;
1048
1060
  }
1049
1061
  ```
1050
1062
 
@@ -681,7 +681,7 @@ declare abstract class AbstractAbapConnection implements AbapConnection, ISessio
681
681
  * the wire: fencing the answer by generation, and letting the identity policy
682
682
  * read what it means.
683
683
  */
684
- protected fetchCsrfToken(_url: string, retryCount?: number, retryDelay?: number,
684
+ protected fetchCsrfToken(_url: string,
685
685
  /**
686
686
  * The request's lease: fences what is sent and the response effects.
687
687
  * A plain session generation — what this parameter took before 10.0.1,
@@ -727,7 +727,7 @@ declare abstract class AbstractAbapConnection implements AbapConnection, ISessio
727
727
  * written: that is the last await before the wire sends, and a provider may
728
728
  * take long enough for the caller to disconnect and connect again — sent
729
729
  * then, the request would carry the new session's cookies. The throw is a
730
- * session verdict, so the exchange stops at once, past its retries.
730
+ * session verdict, so the exchange stops at once.
731
731
  *
732
732
  * Without one — connect()'s own establishment, which is making the session
733
733
  * rather than working in it — nothing is fenced. `generation` alone fences
@@ -735,12 +735,6 @@ declare abstract class AbstractAbapConnection implements AbapConnection, ISessio
735
735
  * sent, and the wire still folds the answer into its jar.
736
736
  */
737
737
  private leasedContext;
738
- /**
739
- * What stops a token exchange at once, past its retries: a session verdict,
740
- * or the provider's refusal to authorize it — asking again would only ask
741
- * the provider again.
742
- */
743
- protected endsTheExchange(error: unknown): boolean;
744
738
  /**
745
739
  * Clear SAP-side session state when SAP rejects the cached CSRF token + session
746
740
  * cookies (HTTP 401 on a mutation while a cached token exists). This forces the
@@ -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,EAInB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G;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMlD;;;;;;;;OAQG;YACW,eAAe;IAU7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,aAAa;IAgCrB;;;;OAIG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAIlD;;;;;;;;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,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,EAInB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAGnB,MAAM,oBAAoB,CAAC;AAwD5B,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;IA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cpB,cAAc;IA2L5B;;;;;;;;OAQG;YACW,YAAY;IAkB1B;;;;;;;;;;;;;;;OAeG;YACW,cAAc;IAgB5B;;;;;;;;;;;;;;;OAeG;YACW,aAAa;IAwI3B;;;;;;;;;;;OAWG;YACW,uBAAuB;IA6DrC;;;;;;;;;OASG;IACH,OAAO,CAAC,kBAAkB;IAe1B;;;;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"}
@@ -1412,7 +1412,7 @@ class AbstractAbapConnection {
1412
1412
  method: normalizedMethod,
1413
1413
  });
1414
1414
  try {
1415
- this.setCsrfToken(await this.fetchCsrfToken(requestUrl, 5, 2000, lease));
1415
+ this.setCsrfToken(await this.fetchCsrfToken(requestUrl, lease));
1416
1416
  const refreshedToken = this.getCsrfToken();
1417
1417
  if (refreshedToken) {
1418
1418
  requestHeaders['x-csrf-token'] = refreshedToken;
@@ -1636,7 +1636,7 @@ class AbstractAbapConnection {
1636
1636
  * the wire: fencing the answer by generation, and letting the identity policy
1637
1637
  * read what it means.
1638
1638
  */
1639
- async fetchCsrfToken(_url, retryCount = csrfConfig_js_1.CSRF_CONFIG.RETRY_COUNT, retryDelay = csrfConfig_js_1.CSRF_CONFIG.RETRY_DELAY,
1639
+ async fetchCsrfToken(_url,
1640
1640
  /**
1641
1641
  * The request's lease: fences what is sent and the response effects.
1642
1642
  * A plain session generation — what this parameter took before 10.0.1,
@@ -1654,9 +1654,6 @@ class AbstractAbapConnection {
1654
1654
  ...(typeof fence === 'number'
1655
1655
  ? this.leasedContext(undefined, fence)
1656
1656
  : this.leasedContext(fence)),
1657
- retries: retryCount,
1658
- retryDelayMs: retryDelay,
1659
- isFatal: (error) => this.endsTheExchange(error),
1660
1657
  });
1661
1658
  const token = this.transport.csrfToken();
1662
1659
  if (!token)
@@ -1704,10 +1701,7 @@ class AbstractAbapConnection {
1704
1701
  async ensureWireReady(
1705
1702
  /** The request's lease: fences what is sent and the response effects. */
1706
1703
  lease) {
1707
- await this.transport.establish({
1708
- ...this.leasedContext(lease),
1709
- isFatal: (error) => this.endsTheExchange(error),
1710
- });
1704
+ await this.transport.establish(this.leasedContext(lease));
1711
1705
  }
1712
1706
  /**
1713
1707
  * The context for a token exchange a request makes on its own behalf — its
@@ -1718,7 +1712,7 @@ class AbstractAbapConnection {
1718
1712
  * written: that is the last await before the wire sends, and a provider may
1719
1713
  * take long enough for the caller to disconnect and connect again — sent
1720
1714
  * then, the request would carry the new session's cookies. The throw is a
1721
- * session verdict, so the exchange stops at once, past its retries.
1715
+ * session verdict, so the exchange stops at once.
1722
1716
  *
1723
1717
  * Without one — connect()'s own establishment, which is making the session
1724
1718
  * rather than working in it — nothing is fenced. `generation` alone fences
@@ -1747,14 +1741,6 @@ class AbstractAbapConnection {
1747
1741
  },
1748
1742
  };
1749
1743
  }
1750
- /**
1751
- * What stops a token exchange at once, past its retries: a session verdict,
1752
- * or the provider's refusal to authorize it — asking again would only ask
1753
- * the provider again.
1754
- */
1755
- endsTheExchange(error) {
1756
- return this.isSessionVerdict(error) || error instanceof authErrors_js_1.AuthRefusedError;
1757
- }
1758
1744
  /**
1759
1745
  * Clear SAP-side session state when SAP rejects the cached CSRF token + session
1760
1746
  * cookies (HTTP 401 on a mutation while a cached token exists). This forces the
@@ -1 +1 @@
1
- {"version":3,"file":"CredentialAbapConnection.d.ts","sourceRoot":"","sources":["../../src/connection/CredentialAbapConnection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,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,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAoB,KAAK,aAAa,EAAW,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,KAAK,aAAa,EAAa,MAAM,oBAAoB,CAAC;AAGnE,8BAAsB,wBAAwB,CAC5C,WAAW,SAAS,aAAa,GAAG,aAAa,CACjD,SAAQ,sBAAsB;IAG5B,6EAA6E;IAC7E,QAAQ,CAAC,UAAU,EAAE,WAAW;gBAFhC,MAAM,EAAE,SAAS;IACjB,6EAA6E;IACpE,UAAU,EAAE,WAAW,EAChC,SAAS,EAAE,aAAa,EACxB,MAAM,GAAE,OAAO,GAAG,IAAW,EAC7B,SAAS,CAAC,EAAE,MAAM;IAClB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM;IAKlB;;;;;;;;;;OAUG;cACsB,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AI,OAAO,CAAC,IAAI,CAAC;IAU3D;;;;;;;OAOG;cACsB,gBAAgB,CACvC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IAYhB,6EAA6E;cACpD,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAUnE;;;OAGG;cACsB,kBAAkB,CACzC,SAAS,EAAE,cAAc,GACxB,OAAO,CAAC,aAAa,CAAC;cAIT,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CA2ClD"}
@@ -87,10 +87,7 @@ class CredentialAbapConnection extends AbstractAbapConnection_js_1.AbstractAbapC
87
87
  // does not need one: the wire authorizes PER ATTEMPT, so a one-shot token
88
88
  // is offered on the establishing call and withheld afterwards by the
89
89
  // credential itself, with nobody deciding anything.
90
- await this.transport.establish({
91
- ...this.sessionContext(),
92
- isFatal: (error) => this.endsTheExchange(error),
93
- });
90
+ await this.transport.establish(this.sessionContext());
94
91
  this.logger?.debug('Connected', {
95
92
  credential: this.credential.kind,
96
93
  hasCsrfToken: !!this.getCsrfToken(),
@@ -1 +1 @@
1
- {"version":3,"file":"HttpTransport.d.ts","sourceRoot":"","sources":["../../src/connection/HttpTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,IAAI,SAAS,EAGlB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAA2B,MAAM,YAAY,CAAC;AAG/E,OAAO,KAAK,EAGV,YAAY,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAc,EACZ,KAAK,aAAa,EAGnB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,k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,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAKzE;;;;;;OAMG;IACH,OAAO,CAAC,GAAG;IAmBX;;;;;;;;;;;;;;OAcG;cACa,YAAY,CAC1B,OAAO,EAAE,oBAAoB;IAC7B,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,IAAI,GACnB,OAAO,CAAC,qBAAqB,CAAC;IAIjC;;;;;OAKG;IACH,SAAS,CAAC,aAAa,CACrB,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,GAC9C,aAAa;IAOhB,0DAA0D;IAC1D,OAAO,CAAC,YAAY;IAOpB;;;;;;;;;;;;;;;;;;OAkBG;YACW,UAAU;YA+BV,QAAQ;CAgEvB"}
@@ -202,6 +202,40 @@ function withoutContextCookie(cookie) {
202
202
  var statefulRequest_js_2 = require("./statefulRequest.js");
203
203
  Object.defineProperty(exports, "isStatefulRequest", { enumerable: true, get: function () { return statefulRequest_js_2.isStatefulRequest; } });
204
204
  /** A 404 there means the system has no such endpoint, not that it is unwell. */
205
+ /**
206
+ * A response's headers as fields, or none. They come from outside the type
207
+ * system: whatever is not a plain object of fields is no headers at all.
208
+ */
209
+ function headerFields(headers) {
210
+ return isFields(headers) ? headers : undefined;
211
+ }
212
+ function isFields(value) {
213
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
214
+ }
215
+ /** The headers of the response a failed request carries, or none. */
216
+ function refusalHeaders(error) {
217
+ if (typeof error !== 'object' || error === null || !('response' in error)) {
218
+ return undefined;
219
+ }
220
+ const response = error.response;
221
+ if (typeof response !== 'object' ||
222
+ response === null ||
223
+ !('headers' in response)) {
224
+ return undefined;
225
+ }
226
+ return headerFields(response.headers);
227
+ }
228
+ /**
229
+ * The CSRF token a response's headers carry: a non-empty string, else none —
230
+ * an array, a number or an empty value is no token.
231
+ */
232
+ function csrfTokenIn(headers) {
233
+ const fields = headerFields(headers);
234
+ if (fields === undefined)
235
+ return undefined;
236
+ const token = fields['x-csrf-token'];
237
+ return typeof token === 'string' && token !== '' ? token : undefined;
238
+ }
205
239
  function absentEndpoint(error) {
206
240
  const status = error
207
241
  ?.response?.status;
@@ -643,84 +677,75 @@ class HttpTransport {
643
677
  // BASIS < 7.52 has no /sap/bc/adt/core/discovery.
644
678
  `${base}${csrfConfig_js_1.CSRF_CONFIG.FALLBACK_ENDPOINT}`,
645
679
  ];
646
- const retries = context.retries ?? csrfConfig_js_1.CSRF_CONFIG.RETRY_COUNT;
647
- const delay = context.retryDelayMs ?? csrfConfig_js_1.CSRF_CONFIG.RETRY_DELAY;
648
680
  let last;
649
681
  for (const [index, url] of endpoints.entries()) {
650
- // The fallback exists for a system that HAS no
651
- // `/sap/bc/adt/core/discovery` — BASIS < 7.52 — which the server says by
652
- // answering 404 there. Trying it after a refused connection or a network
653
- // asks a host that is not answering to answer a different path, which
654
- // doubles the wait before the caller is told what is actually wrong.
682
+ // One request per endpoint, and no delay: a failed request is its own
683
+ // error, and asked again a host that refused the connection or answered
684
+ // 500 says nothing new. The second endpoint is not a retry — it exists
685
+ // for a system that HAS no `/sap/bc/adt/core/discovery` (BASIS < 7.52),
686
+ // which the server says by answering 404 there. Asked after a refused
687
+ // connection or a network error, it would ask a host that is not
688
+ // answering to answer a different path.
655
689
  if (index > 0 && !absentEndpoint(last))
656
690
  break;
657
- for (let attempt = 0; attempt <= retries; attempt++) {
658
- try {
659
- // Authorized per attempt: a provider may renew behind the call.
660
- const auth = {};
661
- await context.authorize(auth);
662
- const response = await this.send({
663
- method: 'GET',
664
- url,
665
- headers: {
666
- ...auth,
667
- ...context.extraHeaders,
668
- ...csrfConfig_js_1.CSRF_CONFIG.REQUIRED_HEADERS,
669
- },
670
- });
671
- // Handed up BEFORE the token is read: the cookies are the session,
672
- // and a fold that only happened on success would lose the session a
673
- // tokenless answer still opened. And before the fold: an answer the
674
- // connection refuses as a gone session's throws here, and nothing
675
- // of it reaches the jar.
676
- context.observe(response.headers);
677
- this.ingest(response.headers);
678
- const token = response.headers['x-csrf-token'];
679
- if (token) {
680
- this.token = token;
681
- this.logger?.debug('CSRF token obtained');
682
- return;
683
- }
684
- last = new Error(csrfConfig_js_1.CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
691
+ try {
692
+ // Authorized per request: a provider may renew behind the call.
693
+ const auth = {};
694
+ await context.authorize(auth);
695
+ const response = await this.send({
696
+ method: 'GET',
697
+ url,
698
+ headers: {
699
+ ...auth,
700
+ ...context.extraHeaders,
701
+ ...csrfConfig_js_1.CSRF_CONFIG.REQUIRED_HEADERS,
702
+ },
703
+ });
704
+ // Handed up BEFORE the token is read: the cookies are the session,
705
+ // and a fold that only happened on success would lose the session a
706
+ // tokenless answer still opened. And before the fold: an answer the
707
+ // connection refuses as a gone session's throws here, and nothing
708
+ // of it reaches the jar.
709
+ context.observe(response.headers);
710
+ this.ingest(headerFields(response.headers));
711
+ const token = csrfTokenIn(response.headers);
712
+ if (token !== undefined) {
713
+ this.token = token;
714
+ this.logger?.debug('CSRF token obtained');
715
+ return;
716
+ }
717
+ // A 200 without a token is not an absent endpoint: the fallback is
718
+ // not asked, and this is the error.
719
+ last = new Error(csrfConfig_js_1.CSRF_ERROR_MESSAGES.NOT_IN_HEADERS);
720
+ }
721
+ catch (error) {
722
+ // The provider's refusal to authorize leaves as it is: it is its
723
+ // word. So does a session verdict — the connection's own, thrown by
724
+ // `authorize` or `observe`: it carries no response, so nothing below
725
+ // folds anything of it in or reads it as an absent endpoint.
726
+ if (error instanceof authErrors_js_1.AuthRefusedError)
727
+ throw error;
728
+ last = error instanceof Error ? error : new Error(String(error));
729
+ const headers = refusalHeaders(error);
730
+ if (headers !== undefined) {
731
+ // A refusal can still carry the cookies that matter — handed up
732
+ // first, so one the connection refuses is not folded in.
733
+ context.observe(headers);
734
+ this.ingest(headers);
685
735
  }
686
- catch (error) {
687
- // Not a failed exchange: see `isFatal`. Leaves immediately, past the
688
- // retries and past the fallback endpoint. So does the provider's
689
- // refusal to authorize: it is its word, and asking again only asks
690
- // it again.
691
- if (error instanceof authErrors_js_1.AuthRefusedError || context.isFatal?.(error)) {
692
- throw error;
693
- }
694
- last = error instanceof Error ? error : new Error(String(error));
695
- const response = error.response;
696
- if (response?.headers) {
697
- // A refusal can still carry the cookies that matter — handed up
698
- // first, so one the connection refuses is not folded in.
699
- context.observe(response.headers);
700
- this.ingest(response.headers);
701
- }
702
- // A refused logon, named as one — after its cookies are in, and
703
- // without a retry: asking again with the credential just refused
704
- // tells the system nothing new. What to do about it is not the
705
- // wire's to decide.
706
- if ((0, IAdtTransport_js_1.refusalOf)(error)?.status === 401) {
707
- throw new authErrors_js_1.WireLogonError(error, 401);
708
- }
709
- if (response?.headers) {
710
- // …and the token itself. SAP answers 405 to a GET on some
711
- // endpoints and puts the token in the header anyway, and other
712
- // refusals carry one too. A retry would throw away a token the
713
- // server already handed over.
714
- const onError = response.headers['x-csrf-token'];
715
- if (onError) {
716
- this.token = onError;
717
- this.logger?.debug('CSRF token arrived on a refusal, and is kept');
718
- return;
719
- }
720
- }
736
+ // A refused logon, named as one — after its cookies are in. What to
737
+ // do about it is not the wire's to decide.
738
+ if ((0, IAdtTransport_js_1.refusalOf)(error)?.status === 401) {
739
+ throw new authErrors_js_1.WireLogonError(error, 401);
721
740
  }
722
- if (attempt < retries) {
723
- await new Promise((resolve) => setTimeout(resolve, delay));
741
+ // …and the token itself. SAP answers 405 to a GET on some endpoints
742
+ // and puts the token in the header anyway, and other refusals carry
743
+ // one too.
744
+ const onError = csrfTokenIn(headers);
745
+ if (onError !== undefined) {
746
+ this.token = onError;
747
+ this.logger?.debug('CSRF token arrived on a refusal, and is kept');
748
+ return;
724
749
  }
725
750
  }
726
751
  }
@@ -109,22 +109,13 @@ export interface IAdtEstablishContext extends IAdtSessionContext {
109
109
  *
110
110
  * Handed up BEFORE the wire folds the answer in. It may throw a session
111
111
  * verdict — the answer belongs to a session that is gone — and the wire then
112
- * folds nothing of it and ends the exchange (`isFatal`).
113
- */
114
- observe: (headers: unknown) => void;
115
- /** How many times to ask again. Absent means the transport's own default. */
116
- retries?: number;
117
- /** Milliseconds between attempts. Absent means the transport's own default. */
118
- retryDelayMs?: number;
119
- /**
120
- * Which failures must not be retried.
112
+ * folds nothing of it and ends the exchange: the verdict carries no
113
+ * response, so it is neither folded in nor read as an absent endpoint.
121
114
  *
122
- * A verdict about the session — "the one we were on is gone" — is not a
123
- * failed exchange: retrying would observe the SAME new session, read it as
124
- * unchanged, and lose the replacement for good. The wire cannot tell those
125
- * apart, so it asks.
115
+ * The exchange is one request, never repeated and never delayed; the second
116
+ * endpoint is asked only after the first answered that it does not exist.
126
117
  */
127
- isFatal?: (error: unknown) => boolean;
118
+ observe: (headers: unknown) => void;
128
119
  }
129
120
  export interface IAdtTransport {
130
121
  /** For logs, so which transport ran is never inferred from behaviour. */
@@ -1 +1 @@
1
- {"version":3,"file":"IAdtTransport.d.ts","sourceRoot":"","sources":["../../src/connection/IAdtTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,4DAA4D;AAC5D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7C;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,gEAAgE;AAChE,MAAM,WAAW,qBAAqB;IACpC,MAAM,E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AAS,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD,0EAA0E;IAC1E,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC;IAE3B;;;;;;OAMG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAE3C,oDAAoD;IACpD,aAAa,IAAI,IAAI,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC3B;AAED,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,qBAAqB,GAAG,IAAI,CAQtE"}
@@ -3,18 +3,12 @@
3
3
  *
4
4
  * Centralized constants for CSRF token fetching to ensure consistency
5
5
  * across different connection implementations.
6
+ *
7
+ * The fetch is one request per endpoint, never repeated and never delayed: a
8
+ * failed request is its own error. The fallback endpoint is asked only after
9
+ * the primary answered 404 (or 501) — a system without it — and is not a retry.
6
10
  */
7
11
  export declare const CSRF_CONFIG: {
8
- /**
9
- * Number of retry attempts for CSRF token fetch
10
- * Default: 3 attempts (total of 4 requests: initial + 3 retries)
11
- */
12
- readonly RETRY_COUNT: 3;
13
- /**
14
- * Delay between retry attempts (milliseconds)
15
- * Default: 1000ms (1 second)
16
- */
17
- readonly RETRY_DELAY: 1000;
18
12
  /**
19
13
  * CSRF token endpoint path (primary)
20
14
  * Standard SAP ADT core discovery endpoint (newer systems, returns smaller response)
@@ -1 +1 @@
1
- {"version":3,"file":"csrfConfig.d.ts","sourceRoot":"","sources":["../../src/connection/csrfConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW;IACtB;;;OAGG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;OAIG;;IAGH;;OAEG;;;;;CAKK,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB;sCACL,MAAM,SAAS,MAAM;;;CAOtC,CAAC"}
1
+ {"version":3,"file":"csrfConfig.d.ts","sourceRoot":"","sources":["../../src/connection/csrfConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IACtB;;;OAGG;;IAGH;;;;OAIG;;IAGH;;OAEG;;;;;CAKK,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB;sCACL,MAAM,SAAS,MAAM;;;CAOtC,CAAC"}
@@ -6,18 +6,12 @@ exports.CSRF_ERROR_MESSAGES = exports.CSRF_CONFIG = void 0;
6
6
  *
7
7
  * Centralized constants for CSRF token fetching to ensure consistency
8
8
  * across different connection implementations.
9
+ *
10
+ * The fetch is one request per endpoint, never repeated and never delayed: a
11
+ * failed request is its own error. The fallback endpoint is asked only after
12
+ * the primary answered 404 (or 501) — a system without it — and is not a retry.
9
13
  */
10
14
  exports.CSRF_CONFIG = {
11
- /**
12
- * Number of retry attempts for CSRF token fetch
13
- * Default: 3 attempts (total of 4 requests: initial + 3 retries)
14
- */
15
- RETRY_COUNT: 3,
16
- /**
17
- * Delay between retry attempts (milliseconds)
18
- * Default: 1000ms (1 second)
19
- */
20
- RETRY_DELAY: 1000,
21
15
  /**
22
16
  * CSRF token endpoint path (primary)
23
17
  * Standard SAP ADT core discovery endpoint (newer systems, returns smaller response)
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
@@ -1069,6 +1069,30 @@ carries it; the wire never reads `config.username` or `config.password`.
1069
1069
  enqueue lock stayed until SM12 (mcp-abap-adt#314).
1070
1070
  The logoff goes out on a connection of its own, with `Connection: close`,
1071
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.
1072
1096
  - RFC takes logon parameters (a password, or SNC settings) on every conversation
1073
1097
  it opens, the session's own and each per-call one. RFC refuses TLS material,
1074
1098
  and a provider that writes no logon parameters (a bearer token) cannot log on
@@ -1115,9 +1139,8 @@ Exported constants for consistent CSRF token handling across different connectio
1115
1139
 
1116
1140
  // CSRF_CONFIG structure:
1117
1141
  const config = {
1118
- RETRY_COUNT: 3, // Number of retry attempts
1119
- RETRY_DELAY: 1000, // Delay between retries (ms)
1120
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)
1121
1144
  REQUIRED_HEADERS: {
1122
1145
  'x-csrf-token': 'fetch',
1123
1146
  'Accept': 'application/atomsvc+xml'
@@ -1140,43 +1163,27 @@ import { executeHttpRequest } from '@sap-cloud-sdk/http-client';
1140
1163
 
1141
1164
  export class CloudSdkAbapConnection {
1142
1165
  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
- }
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);
1177
1182
  }
1178
-
1179
- 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;
1180
1187
  }
1181
1188
  }
1182
1189
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-abap-adt/connection",
3
- "version": "20.1.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",