@mcp-abap-adt/connection 9.4.1 → 10.0.1

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +187 -1
  2. package/README.md +80 -38
  3. package/dist/connection/AbstractAbapConnection.d.ts +211 -56
  4. package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
  5. package/dist/connection/AbstractAbapConnection.js +622 -255
  6. package/dist/connection/CloudHttpTransport.d.ts.map +1 -1
  7. package/dist/connection/CloudHttpTransport.js +15 -5
  8. package/dist/connection/CredentialAbapConnection.d.ts +21 -20
  9. package/dist/connection/CredentialAbapConnection.d.ts.map +1 -1
  10. package/dist/connection/CredentialAbapConnection.js +39 -46
  11. package/dist/connection/HttpTransport.d.ts +30 -14
  12. package/dist/connection/HttpTransport.d.ts.map +1 -1
  13. package/dist/connection/HttpTransport.js +99 -19
  14. package/dist/connection/IAdtTransport.d.ts +19 -2
  15. package/dist/connection/IAdtTransport.d.ts.map +1 -1
  16. package/dist/connection/OnPremHttpTransport.d.ts.map +1 -1
  17. package/dist/connection/OnPremHttpTransport.js +4 -3
  18. package/dist/connection/RfcTransport.d.ts +23 -3
  19. package/dist/connection/RfcTransport.d.ts.map +1 -1
  20. package/dist/connection/RfcTransport.js +48 -15
  21. package/dist/connection/authErrors.d.ts +61 -0
  22. package/dist/connection/authErrors.d.ts.map +1 -0
  23. package/dist/connection/authErrors.js +78 -0
  24. package/dist/connection/requestTarget.d.ts +12 -0
  25. package/dist/connection/requestTarget.d.ts.map +1 -0
  26. package/dist/connection/requestTarget.js +23 -0
  27. package/dist/connection/rfcConversation.d.ts +10 -5
  28. package/dist/connection/rfcConversation.d.ts.map +1 -1
  29. package/dist/connection/rfcConversation.js +6 -8
  30. package/dist/index.d.ts +1 -2
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +4 -12
  33. package/dist/session/SessionLifecycle.d.ts +1 -1
  34. package/dist/session/SessionLifecycle.d.ts.map +1 -1
  35. package/docs/INDEX.md +4 -1
  36. package/docs/INSTALLATION.md +12 -5
  37. package/docs/JWT_AUTH_TOOLS.md +2 -2
  38. package/docs/MIGRATION-10.0.md +284 -0
  39. package/docs/SCOPE.md +2 -2
  40. package/docs/STATEFUL_SESSION_GUIDE.md +34 -13
  41. package/docs/USAGE.md +118 -35
  42. package/examples/README.md +5 -4
  43. package/examples/basic-connection.js +1 -1
  44. package/examples/jwt-with-token-refresh.js +14 -15
  45. package/examples/saml-connection.js +1 -1
  46. package/package.json +5 -4
  47. package/dist/auth/FileCertificateMaterialLoader.d.ts +0 -6
  48. package/dist/auth/FileCertificateMaterialLoader.d.ts.map +0 -1
  49. package/dist/auth/FileCertificateMaterialLoader.js +0 -28
  50. package/dist/auth/ntlm.d.ts +0 -26
  51. package/dist/auth/ntlm.d.ts.map +0 -1
  52. package/dist/auth/ntlm.js +0 -72
  53. package/dist/auth/providers.d.ts +0 -125
  54. package/dist/auth/providers.d.ts.map +0 -1
  55. package/dist/auth/providers.js +0 -183
  56. package/dist/utils/tokenRefresh.d.ts +0 -15
  57. package/dist/utils/tokenRefresh.d.ts.map +0 -1
  58. package/dist/utils/tokenRefresh.js +0 -55
package/CHANGELOG.md CHANGED
@@ -7,6 +7,189 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [10.0.1] - 2026-09-30
11
+
12
+ ### Fixed
13
+
14
+ - **A `close()` that throws synchronously is absorbed like one that rejects.**
15
+ A custom wire's non-async `close()` that threw escaped before any `.catch` was
16
+ attached: after a failed establishment it replaced the establishment error and
17
+ skipped the clearing behind it, so the failed attempt's cookies survived into
18
+ the next `connect()`; in `disconnect()` it made the method that never throws,
19
+ throw. Every goodbye now goes through one path that absorbs both. `close()` is
20
+ still called synchronously — the wires snapshot the cookie jar and the
21
+ affinity headers on their first line, before the teardown clears them.
22
+ - **A request's own token fetch sends nothing once its session is gone.** The
23
+ upfront token fetch before a mutation, a CSRF recovery fetch and the fetch
24
+ after a refused logon awaited the provider's `authorize` before sending; a
25
+ `disconnect()` and `connect()` in that window let one discovery request go out
26
+ on the new session's cookies (no work request ever did). The request's lease
27
+ is now checked after the provider has written, and the request ends
28
+ `NOT_CONNECTED` with nothing sent. `connect()`'s own establishment is unchanged.
29
+ - **A resend answered "session not found" is `SESSION_REPLACED`, like the first
30
+ attempt.** Only the first attempt's `400` went through the dead-session check;
31
+ a resend — the one more attempt after a renewal (inside a critical section
32
+ too), the CSRF resend, a GET resent with the session's cookies — surfaced the
33
+ raw `400` and left the connection connected to a dead session. Every attempt
34
+ now goes through the same check: the session is lost and the caller gets
35
+ `SESSION_REPLACED`.
36
+ - **An answer to a request's token fetch that arrives after a reconnect is not
37
+ folded into the new session.** The wire ingested an establishment answer's
38
+ cookies and token itself, after the connection's fenced `observe`, so an old
39
+ session's answer could overwrite the new session's jar. The connection now
40
+ refuses such an answer from `observe` with a session verdict, which the wire
41
+ hands up before folding anything in; the request ends `NOT_CONNECTED`.
42
+ `connect()`'s own establishment is unchanged.
43
+ - **A resend refused after its session went away is `NOT_CONNECTED`**, not
44
+ `AuthRefusedError` (refused again): the session the request was admitted to
45
+ is gone, so the refusal says nothing about the credential.
46
+ - **A stale request ends `NOT_CONNECTED`, whatever stopped it.** When the
47
+ session a request was admitted to goes away while the provider authorizes
48
+ its first attempt, while it readies its wire, while the provider renews, or
49
+ during one of the wire's resends (the CSRF resend, a GET resent with its
50
+ cookies or after a token fetch), the caller gets `NOT_CONNECTED` — never the
51
+ wire's `WireLogonError`, a network error, or the provider's
52
+ `AuthRefusedError` about a session the request no longer holds. A session
53
+ verdict (`SESSION_REPLACED`) still comes through as it is. What the server
54
+ answered to an attempt sent while the session was current, other than a
55
+ credential refusal, still reaches the caller as it is.
56
+
57
+ ### Changed
58
+
59
+ - **`fetchCsrfToken`'s protected fourth parameter accepts a request lease as
60
+ well as a session generation number.** A number keeps its 10.0.0 meaning: it
61
+ fences what the connection does with the answer, not the wire's own ingest,
62
+ and never stops the fetch being sent. Only a lease fences the send.
63
+ - **For custom-wire authors: `IAdtEstablishContext.observe` may throw.** For an
64
+ answer that belongs to a session that is gone, it throws a `NOT_CONNECTED`
65
+ session verdict. Call `observe` BEFORE your wire folds that answer into its
66
+ own state, and fold nothing when it throws; `HttpTransport` already does. A
67
+ wire that ingests first would write a gone session's cookies into the new
68
+ session's jar.
69
+
70
+ ### Documentation
71
+
72
+ - **A dead session inside a critical section.** `docs/USAGE.md` and
73
+ `docs/STATEFUL_SESSION_GUIDE.md` now state the price of keeping a lock through
74
+ a renewal: when SAP answers the resend with the same session cookie, a session
75
+ it really lost ends the request as `AuthRefusedError` (refused again), not
76
+ `SESSION_REPLACED`, and the connection stays connected. Treat the lock as lost
77
+ and reconnect.
78
+ - **Renewal sharing.** `docs/USAGE.md` "Concurrency" no longer says providers
79
+ that renew share one renewal in flight: requests share one only if the provider
80
+ (for `TokenAuthProvider.from`, its refresher) does; the connection adds no
81
+ single-flight.
82
+
83
+ ## [10.0.0] - 2026-09-30
84
+
85
+ **The connection is the process on the `IAuthProvider` 3.0 contract.** It no
86
+ longer knows what a credential is: it asks the provider before every attempt,
87
+ puts a refusal the wire could not cure to the provider, and gives the caller the
88
+ provider's own words when the answer is no. The credential providers left with
89
+ it. See [`docs/MIGRATION-10.0.md`](docs/MIGRATION-10.0.md).
90
+
91
+ ### Breaking
92
+
93
+ - **`@mcp-abap-adt/interfaces-auth` `^3.0.0`.** The connection calls `prepare`
94
+ once, before the wire opens (it used to run after `transport.open()`);
95
+ `establish` at each logon; `authorize` before every attempt of every request,
96
+ including the CSRF fetch, the cloud preflight, the logoff and each resend; and
97
+ `rejected` when the system said no. A provider written against 2.x does not
98
+ type-check.
99
+ - **`IAdtSessionContext.authHeaders` is replaced by `authorize(headers)` and
100
+ `logon(target)`.** A custom `IAdtTransport` fills a request it originates with
101
+ `context.authorize(headers)` and calls `context.logon(target)` at each of its
102
+ logons.
103
+ - **A refusal reaches the caller as `AuthRefusedError { refusal, at, cause }`,
104
+ in the provider's words.** A 401 that survives the wire's own session recovery,
105
+ or a logon the system refused, goes to `rejected()`; on Ok the request is sent
106
+ exactly once more, and a second refusal is the verdict (the fixed reason "the
107
+ credential was refused again after the provider renewed it"). A 403 never goes
108
+ to the provider. A provider that throws is a refusal with the reason "the
109
+ credential provider failed".
110
+ - **Inside a critical section a renewal keeps the session.** A mutation refused
111
+ with a 401 while a CSRF token is cached used to drop the session and resend on
112
+ a new one, losing the lock the section held. Inside `beginCriticalSection()`
113
+ it now goes to `rejected({ at: 'request' })` and, on Ok, is resent on the same
114
+ session with the same token; a session SAP replaced surfaces as
115
+ `SESSION_REPLACED`. Outside a critical section the wire's recovery runs first,
116
+ as before.
117
+ - **RFC: the factory takes the logon parameters.** `RfcTransport`'s first
118
+ argument is `(logon) => IRfcConversation`, and every conversation it opens —
119
+ the session's own and each per-call one — gets the parameters the provider
120
+ wrote. `rfcConversationFrom(config)` returns such a factory. `rfcParamsFrom`
121
+ returns the address only and no longer reads `username` / `password`;
122
+ `RfcConnectionParams` loses `user` and `passwd`. A provider that writes no
123
+ logon parameters (a bearer token) cannot log on over RFC.
124
+ - **HTTP takes TLS material at logon.** The agent is built from
125
+ `{ rejectUnauthorized, ...agentOptions(), ...material }`, `material` being
126
+ only the defined `cert`, `key`, `pfx` and `passphrase` the provider offered;
127
+ the constructor's `agentOptions` stays for `ca` and `rejectUnauthorized`. A later logon offering
128
+ different material replaces the client; the cookie jar and CSRF token stay.
129
+ HTTP refuses logon parameters.
130
+ - **A failed RFC open is thrown as `WireLogonError`** carrying the raw
131
+ `sap-rfc-lite` error as `cause`, not wrapped in `Failed to open RFC
132
+ connection: …`.
133
+ - **An RFC open that fails for any reason, a network one included**
134
+ (`RFC_COMMUNICATION_FAILURE`, say), goes to the provider and reaches the
135
+ caller as `AuthRefusedError` at `'logon'` — the provider's words, or the fixed
136
+ "refused again" reason after its Ok — with the SDK error only in `cause`.
137
+ - **A 401 while HTTP establishes its session** is thrown at once as
138
+ `WireLogonError { status: 401 }` and is not retried by the establishment's own
139
+ retry loop.
140
+
141
+ ### Added
142
+
143
+ - `AuthRefusedError` and `WireLogonError`, exported. `WireLogonError { cause,
144
+ status? }` is the mark a wire puts on a failure that is a refused logon, so a
145
+ consumer's own wire can say the same thing; it decides nothing.
146
+ - `AuthRefusalMoment` (`'prepare' | 'logon' | 'request'`), exported.
147
+ - `docs/MIGRATION-10.0.md`.
148
+
149
+ ### Removed
150
+
151
+ - **`BasicAuthProvider`, `TokenAuthProvider`, `SamlAuthProvider`,
152
+ `CertificateAuthProvider` and `FileCertificateMaterialLoader`** — they are in
153
+ `@mcp-abap-adt/auth-providers` ^5.0.1, which this package depends on for
154
+ tests only. `TokenAuthProvider` is built with `.fixed(token)` or
155
+ `.from(refresher)`; `new TokenAuthProvider(x)` is gone.
156
+ - `CredentialAbapConnection.getHttpsAgentOptions`, `buildAuthorizationHeader`
157
+ and `isUnauthorized`; `AbstractAbapConnection.recoverSession` and
158
+ `discardSession`; `src/utils/tokenRefresh.ts` and `src/auth/ntlm.ts` — nothing
159
+ read them.
160
+
161
+ ### Fixed
162
+
163
+ - **A stale CSRF token under Basic is no longer read as a refused password.**
164
+ The wire's session recovery runs first; only a 401 that survives it reaches
165
+ the provider.
166
+ - **Every resend is re-authorized.** The recovery resends used the
167
+ `Authorization` read once before the first attempt; a renewed token was never
168
+ on them.
169
+ - **The wire's recovery no longer hides a credential failure.** A failed retry
170
+ of a CSRF recovery, a swallowed token fetch, and the upfront token fetch
171
+ before a mutation used to throw the original error or send the mutation
172
+ anyway; an `AuthRefusedError`, a `WireLogonError` or a surviving 401 goes on
173
+ to the provider instead. One credential retry per request, whichever comes
174
+ first.
175
+ - **Documentation.** The README, `docs/USAGE.md` and the other guides no longer
176
+ import providers from this package, and no longer say that a 401 surfaces with
177
+ nothing renewing behind it or that `renew()` on an `IRenewableCredential` is
178
+ the seam. Concurrent requests meeting one expired token each call
179
+ `rejected()`; a provider that renews may share one renewal in flight
180
+ (`TokenAuthProvider.from` only if its refresher does).
181
+
182
+ ## [9.4.2] - 2026-09-27
183
+
184
+ ### Changed
185
+
186
+ - **`@mcp-abap-adt/sap-rfc-lite` `^0.2.1`** (was `^0.2.0`). 0.2.0 on npm was
187
+ packed with a stale `lib/`: its JS client has no `resetServerContext`, so
188
+ this connector found no reset and fell back to a new RFC connection per
189
+ stateless call — correct, but a full RFC run took about 1010 s instead of
190
+ about 684 s. 0.2.1 is packed from `src/`. Raising the minimum makes npm
191
+ replace a locked 0.2.0 too, since it no longer satisfies the range.
192
+
10
193
  ## [9.4.1] - 2026-09-27
11
194
 
12
195
  ### Fixed
@@ -1912,7 +2095,10 @@ const connection = createAbapConnection(config, logger);
1912
2095
  - JWT token refresh now properly handles connection errors (401/403 during initial connect)
1913
2096
  - Permission errors (403 with "ExceptionResourceNoAccess") no longer trigger JWT refresh loops
1914
2097
  - Proper separation: base class handles HTTP/session, concrete classes handle auth-specific errors
1915
- [Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v9.4.1...HEAD
2098
+ [Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v10.0.1...HEAD
2099
+ [10.0.1]: https://github.com/fr0ster/mcp-abap-connection/compare/v10.0.0...v10.0.1
2100
+ [10.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v9.4.2...v10.0.0
2101
+ [9.4.2]: https://github.com/fr0ster/mcp-abap-connection/compare/v9.4.1...v9.4.2
1916
2102
  [9.4.1]: https://github.com/fr0ster/mcp-abap-connection/compare/v9.4.0...v9.4.1
1917
2103
  [9.4.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v9.3.4...v9.4.0
1918
2104
  [9.3.4]: https://github.com/fr0ster/mcp-abap-connection/compare/v9.3.3...v9.3.4
package/README.md CHANGED
@@ -56,16 +56,17 @@ The package uses a clean separation of concerns:
56
56
  session open while the logoff removes it — so asking the server would pick the
57
57
  mechanism that releases nothing.
58
58
 
59
- - **Auth providers** (`BasicAuthProvider`, `TokenAuthProvider`, `SamlAuthProvider`,
60
- `CertificateAuthProvider`):
61
- - What a connection authenticates with, passed in
62
- - A token provider renews on its own, and the connector asks it per request — which
63
- is how a token that expired between two requests is replaced with nobody
64
- deciding to replace it
65
- - A `401` **surfaces**. Whether a refusal meant "the token is stale" or "these
66
- credentials are refused" is a judgement made with what you know, so the
67
- connector does not answer it for you. A credential that can be told to get a
68
- new one says so through `IRenewableCredential`, which you narrow to
59
+ - **Auth providers** (an `IAuthProvider` from `@mcp-abap-adt/interfaces-auth`; the
60
+ ready-made ones — `BasicAuthProvider`, `TokenAuthProvider`, `SamlAuthProvider`,
61
+ `CertificateAuthProvider` — are in `@mcp-abap-adt/auth-providers`, not here):
62
+ - What a connection authenticates with, passed in. The connection never asks
63
+ what kind of provider it was given; it calls the same four methods on all of
64
+ them: `prepare` once before the wire opens, `establish` at each logon,
65
+ `authorize` before every attempt, `rejected` when the system refused
66
+ - A `401` that survives the wire's own session recovery, or a refused logon, is
67
+ put to the provider through `rejected`. If it answers Ok (a renewed token, say)
68
+ the request gets exactly one more attempt; if it says no, or the retry is
69
+ refused too, you get an `AuthRefusedError` carrying the provider's own words
69
70
 
70
71
  - **Transports** (`OnPremHttpTransport`, `CloudHttpTransport`, `RfcTransport`):
71
72
  - What a request travels over, and everything that is true of that wire.
@@ -75,7 +76,8 @@ The package uses a clean separation of concerns:
75
76
  - On-prem is where this is a real choice; ABAP Cloud has one wire and its
76
77
  connector takes no such parameter
77
78
  - `rfcConversationFrom(config)` builds what `RfcTransport` needs, deriving
78
- `ashost` and `sysnr` and loading the SDK only when a conversation opens
79
+ `ashost` and `sysnr` and loading the SDK only when a conversation opens. It
80
+ reads no user or password: the provider writes the logon parameters
79
81
 
80
82
  - **`GenericWebSocketTransport`** (concrete, exported):
81
83
  - Transport abstraction for realtime WS message flows
@@ -137,7 +139,7 @@ dependencies of this one besides `axios`, `commander` and `open`:
137
139
  | Package | What this package takes from it |
138
140
  |---|---|
139
141
  | `@mcp-abap-adt/interfaces-adt-connection` | `IAbapConnection`, `IAbapRequestOptions`, `IAdtWireResponse`, `ITimeoutConfig`, the capability atoms, `ADT_SESSION_ERROR` |
140
- | `@mcp-abap-adt/interfaces-auth` | `IAuthProvider`, `IRenewableCredential`, `ICertificateMaterial`, `ITokenRefresher`, `ITokenRefreshResult` |
142
+ | `@mcp-abap-adt/interfaces-auth` | `IAuthProvider`, `AuthOutcome`, `IAuthRefusal`, `IAuthRejection`, `ILogonTarget`, `IRequestTarget`, `ICertificateMaterial`, `ITokenRefresher`, `ITokenRefreshResult` |
141
143
  | `@mcp-abap-adt/interfaces-auth-sap` | `ISapConfig`, `SapAuthType`, `SapConnectionType`, `ICertificateMaterialLoader` |
142
144
  | `@mcp-abap-adt/interfaces-network` | `NETWORK_ERROR_CODES`, the WebSocket contracts |
143
145
  | `@mcp-abap-adt/interfaces-utils` | `ILogger` |
@@ -152,6 +154,7 @@ the packages above. See [Migration to 9.0.0](./docs/MIGRATION-9.0.md).
152
154
 
153
155
  - 📦 **[Installation Guide](./docs/INSTALLATION.md)** - Setup and installation instructions
154
156
  - 📚 **[Usage Guide](./docs/USAGE.md)** - Detailed usage examples and API documentation
157
+ - 🚚 **[Migration to 10.0.0](./docs/MIGRATION-10.0.md)** - the credential providers moved to `@mcp-abap-adt/auth-providers`; the connection speaks `IAuthProvider` 3.0; `AuthRefusedError`; the RFC factory takes the logon parameters
155
158
  - 🚚 **[Migration to 9.0.0](./docs/MIGRATION-9.0.md)** - the contracts split out of `@mcp-abap-adt/interfaces`; which package each one moved to
156
159
  - 🚚 **[Migration to 7.0.0 and 8.0.0](./docs/MIGRATION-8.0.md)** - request headers leave the stateful branch, the contracts floor moves, and `flushGoodbye()`
157
160
  - 🚚 **[Migration to 6.0.0](./docs/MIGRATION-6.0.md)** - the factory and the per-credential classes are removed; RFC is a transport, not a class
@@ -183,6 +186,14 @@ longer brings them along:
183
186
  npm install @mcp-abap-adt/interfaces-adt-connection @mcp-abap-adt/interfaces-auth @mcp-abap-adt/interfaces-auth-sap
184
187
  ```
185
188
 
189
+ The credential providers (`BasicAuthProvider`, `TokenAuthProvider`,
190
+ `SamlAuthProvider`, `CertificateAuthProvider`) are not part of this package
191
+ since 10.0.0. Install them from where they live:
192
+
193
+ ```bash
194
+ npm install @mcp-abap-adt/auth-providers
195
+ ```
196
+
186
197
  For detailed installation instructions, see [Installation Guide](./docs/INSTALLATION.md).
187
198
 
188
199
  ## Quick Start
@@ -192,11 +203,11 @@ For detailed installation instructions, see [Installation Guide](./docs/INSTALLA
192
203
  ```typescript
193
204
  import {
194
205
  AdtOnPremConnector,
195
- BasicAuthProvider,
196
206
  OnPremHttpTransport,
197
207
  SapConfig,
198
208
  getTimeout,
199
209
  } from "@mcp-abap-adt/connection";
210
+ import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
200
211
 
201
212
  const config: SapConfig = {
202
213
  url: "https://your-sap-system.com",
@@ -242,9 +253,9 @@ import {
242
253
  AdtCloudConnector,
243
254
  CloudHttpTransport,
244
255
  SapConfig,
245
- TokenAuthProvider,
246
256
  getTimeout,
247
257
  } from "@mcp-abap-adt/connection";
258
+ import { TokenAuthProvider } from "@mcp-abap-adt/auth-providers";
248
259
 
249
260
  // JWT configuration
250
261
  const config: SapConfig = {
@@ -262,12 +273,12 @@ const logger = {
262
273
  };
263
274
 
264
275
  // Logger is optional - if not provided, no logging output.
265
- // A bare string is a token with nothing behind it. Hand `TokenAuthProvider` an
266
- // `ITokenRefresher` instead and it checks expiry and renews on its own, which
276
+ // `.fixed` is a token with nothing behind it. `TokenAuthProvider.from` takes an
277
+ // `ITokenRefresher` instead and renews when the system refuses the token, which
267
278
  // is what you want in anything long-lived.
268
279
  const connection = new AdtCloudConnector(
269
280
  config,
270
- new TokenAuthProvider(config.jwtToken!),
281
+ TokenAuthProvider.fixed(config.jwtToken!),
271
282
  new CloudHttpTransport(() => ({}), logger, {
272
283
  client: config.client,
273
284
  baseUrl: config.url,
@@ -294,8 +305,9 @@ on BASIS < 7.50.
294
305
 
295
306
  Since 9.3.2, LOCK and UNLOCK in stateful mode share the persistent RFC
296
307
  conversation; stateless requests use a separate ABAP context. With
297
- `sap-rfc-lite` 0.2.0 or newer, that context is reset between calls on a kept
298
- conversation; older clients open one conversation per call. This prevents stale
308
+ `sap-rfc-lite` 0.2.1 or newer (required since 9.4.2), that context is reset
309
+ between calls on a kept conversation; older clients open one conversation per
310
+ call. 0.2.0 on npm lacks the reset in its JS client and behaves like an older one. This prevents stale
299
311
  package state from causing PAK/058 on later writes or SADT_RESOURCE/007 on a
300
312
  read after create. Concurrent calls use a separate conversation. See
301
313
  [RFC conversation isolation](./docs/STATEFUL_SESSION_GUIDE.md#rfc-conversation-isolation-932-and-933).
@@ -305,10 +317,10 @@ Needs the SAP NW RFC SDK on the machine and `npm install @mcp-abap-adt/sap-rfc-l
305
317
  ```typescript
306
318
  import {
307
319
  AdtOnPremConnector,
308
- BasicAuthProvider,
309
320
  RfcTransport,
310
321
  rfcConversationFrom,
311
322
  } from "@mcp-abap-adt/connection";
323
+ import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
312
324
 
313
325
  const connection = new AdtOnPremConnector(
314
326
  config,
@@ -336,10 +348,10 @@ takes no transport parameter at all.
336
348
  import {
337
349
  AdtOnPremConnector,
338
350
  OnPremHttpTransport,
339
- SamlAuthProvider,
340
351
  SapConfig,
341
352
  getTimeout,
342
353
  } from "@mcp-abap-adt/connection";
354
+ import { SamlAuthProvider } from "@mcp-abap-adt/auth-providers";
343
355
 
344
356
  const config: SapConfig = {
345
357
  url: "https://your-sap-system.com",
@@ -368,19 +380,20 @@ const response = await connection.makeAdtRequest({
368
380
 
369
381
  ### Cloud Usage with Automatic Token Refresh
370
382
 
371
- Give `TokenAuthProvider` an `ITokenRefresher` and the provider replaces an
372
- **expired** token on its own — it is asked per request and checks expiry before
373
- answering, so nobody decides to renew. A token the source still believes in and
374
- the server refuses is the other half, and that one **surfaces**:
383
+ Build `TokenAuthProvider.from` over an `ITokenRefresher` and the provider
384
+ replaces a token the system refused: the connection puts the `401` to
385
+ `rejected`, the provider fetches a new token, and the request is sent once more.
386
+ A token the source still believes in and the server refuses again is the
387
+ verdict, and that one **surfaces** as an `AuthRefusedError`:
375
388
 
376
389
  ```typescript
377
390
  import {
378
391
  AdtCloudConnector,
379
392
  CloudHttpTransport,
380
393
  SapConfig,
381
- TokenAuthProvider,
382
394
  getTimeout,
383
395
  } from "@mcp-abap-adt/connection";
396
+ import { TokenAuthProvider } from "@mcp-abap-adt/auth-providers";
384
397
  import type { ITokenRefresher } from "@mcp-abap-adt/interfaces-auth";
385
398
 
386
399
  // Token refresher provides token acquisition and refresh
@@ -401,7 +414,7 @@ const config: SapConfig = {
401
414
  // authenticate. Neither decides the other.
402
415
  const connection = new AdtCloudConnector(
403
416
  config,
404
- new TokenAuthProvider(tokenRefresher),
417
+ TokenAuthProvider.from(tokenRefresher),
405
418
  new CloudHttpTransport(() => ({}), logger, {
406
419
  client: config.client,
407
420
  baseUrl: config.url,
@@ -410,12 +423,15 @@ const connection = new AdtCloudConnector(
410
423
  );
411
424
  await connection.connect();
412
425
 
413
- // On a 401 nothing here decides to get a new credential: the refusal reaches
414
- // you. Whether it meant "stale" is a judgement made with what you know, and
415
- // `renew()` is the seam you make it with. The session is untouched — a refused
416
- // reaches you. A refresh replaces the SAP session, so if a lock window is open
417
- // the request fails with ADT_SESSION_REPLACED rather than continuing on a
418
- // session your lock is not in.
426
+ // On a 401 the connection asks the provider (`rejected`); on Ok it sends the
427
+ // request once more with the renewed token, otherwise you get an
428
+ // AuthRefusedError. The resend always runs under the same lease and generation
429
+ // as the attempt it repeats, so stale-request fencing applies. After a rejection
430
+ // at 'request' it goes out on the same session; after one at 'logon' the wire
431
+ // logs on again first. Inside a critical section a renewal keeps the session —
432
+ // or the request fails with SESSION_REPLACED if SAP replaced it. Outside one, a
433
+ // mutation refused with a 401 while a CSRF token is cached takes the wire's
434
+ // stale-session recovery first, which starts a new session.
419
435
  const response = await connection.makeAdtRequest({
420
436
  method: "GET",
421
437
  url: "/sap/bc/adt/programs/programs/your-program",
@@ -435,6 +451,29 @@ error. Code matching on that message must branch on `error.response.status`
435
451
  instead — which it can now do, since the status is no longer thrown away.
436
452
  See [MIGRATION-4.0.md](./docs/MIGRATION-4.0.md).
437
453
 
454
+ ### When the credential is refused
455
+
456
+ Every request asks the provider first (`authorize`). A `401` that survives the
457
+ wire's own session recovery, or a logon the system refused, is put to the
458
+ provider (`rejected`); on Ok the request is sent once more, otherwise it fails
459
+ with an `AuthRefusedError` carrying the provider's own words. A `403` is never
460
+ put to the provider.
461
+
462
+ ```typescript
463
+ import { AuthRefusedError } from "@mcp-abap-adt/connection";
464
+
465
+ try {
466
+ await connection.connect();
467
+ } catch (error) {
468
+ if (error instanceof AuthRefusedError) {
469
+ console.error(error.refusal.reason, error.refusal.hint, error.at);
470
+ }
471
+ throw error;
472
+ }
473
+ ```
474
+
475
+ See [USAGE.md](./docs/USAGE.md#when-the-credential-is-refused).
476
+
438
477
  ### Stateful Sessions
439
478
 
440
479
  Enable stateful mode for requests that need the ABAP context, such as LOCK and
@@ -446,10 +485,10 @@ cookies and the CSRF token remain available in both modes. See the
446
485
  ```typescript
447
486
  import {
448
487
  AdtOnPremConnector,
449
- BasicAuthProvider,
450
488
  OnPremHttpTransport,
451
489
  getTimeout,
452
490
  } from "@mcp-abap-adt/connection";
491
+ import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
453
492
 
454
493
  const connection = new AdtOnPremConnector(
455
494
  config,
@@ -479,7 +518,8 @@ connection.setSessionType("stateless");
479
518
  ### Custom Logger
480
519
 
481
520
  ```typescript
482
- import { AdtOnPremConnector, BasicAuthProvider, ILogger, OnPremHttpTransport } from "@mcp-abap-adt/connection";
521
+ import { AdtOnPremConnector, ILogger, OnPremHttpTransport } from "@mcp-abap-adt/connection";
522
+ import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
483
523
 
484
524
  class MyLogger implements ILogger {
485
525
  info(message: string, meta?: any): void {
@@ -676,17 +716,19 @@ so a machine without it fails at `connect()` with a message saying what to
676
716
  install rather than at construction.
677
717
 
678
718
  ```text
679
- function rfcConversationFrom(config: SapConfig): () => IRfcConversation;
680
- function rfcParamsFrom(config: SapConfig): RfcConnectionParams;
719
+ function rfcConversationFrom(
720
+ config: SapConfig,
721
+ ): (logon: Readonly<Record<string, string>>) => IRfcConversation;
722
+ function rfcParamsFrom(config: SapConfig): RfcConnectionParams; // the address only
681
723
  ```
682
724
 
683
725
  ```typescript
684
726
  import {
685
727
  AdtOnPremConnector,
686
- BasicAuthProvider,
687
728
  RfcTransport,
688
729
  rfcConversationFrom,
689
730
  } from "@mcp-abap-adt/connection";
731
+ import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
690
732
 
691
733
  const connection = new AdtOnPremConnector(
692
734
  config,