@mcp-abap-adt/connection 9.4.2 → 10.0.2
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 +182 -1
- package/README.md +78 -37
- package/dist/connection/AbstractAbapConnection.d.ts +211 -56
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +622 -255
- package/dist/connection/CloudHttpTransport.d.ts.map +1 -1
- package/dist/connection/CloudHttpTransport.js +15 -5
- package/dist/connection/CredentialAbapConnection.d.ts +21 -20
- package/dist/connection/CredentialAbapConnection.d.ts.map +1 -1
- package/dist/connection/CredentialAbapConnection.js +39 -46
- package/dist/connection/HttpTransport.d.ts +30 -14
- package/dist/connection/HttpTransport.d.ts.map +1 -1
- package/dist/connection/HttpTransport.js +99 -19
- package/dist/connection/IAdtTransport.d.ts +19 -2
- package/dist/connection/IAdtTransport.d.ts.map +1 -1
- package/dist/connection/OnPremHttpTransport.d.ts.map +1 -1
- package/dist/connection/OnPremHttpTransport.js +4 -3
- package/dist/connection/RfcTransport.d.ts +23 -3
- package/dist/connection/RfcTransport.d.ts.map +1 -1
- package/dist/connection/RfcTransport.js +48 -15
- package/dist/connection/authErrors.d.ts +61 -0
- package/dist/connection/authErrors.d.ts.map +1 -0
- package/dist/connection/authErrors.js +78 -0
- package/dist/connection/requestTarget.d.ts +12 -0
- package/dist/connection/requestTarget.d.ts.map +1 -0
- package/dist/connection/requestTarget.js +23 -0
- package/dist/connection/rfcConversation.d.ts +10 -5
- package/dist/connection/rfcConversation.d.ts.map +1 -1
- package/dist/connection/rfcConversation.js +6 -8
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -12
- package/dist/session/SessionLifecycle.d.ts +1 -1
- package/dist/session/SessionLifecycle.d.ts.map +1 -1
- package/docs/INDEX.md +4 -1
- package/docs/INSTALLATION.md +15 -7
- package/docs/JWT_AUTH_TOOLS.md +2 -2
- package/docs/MIGRATION-10.0.md +284 -0
- package/docs/SCOPE.md +2 -2
- package/docs/STATEFUL_SESSION_GUIDE.md +30 -10
- package/docs/USAGE.md +118 -35
- package/examples/README.md +5 -4
- package/examples/basic-connection.js +1 -1
- package/examples/jwt-with-token-refresh.js +14 -15
- package/examples/saml-connection.js +1 -1
- package/package.json +5 -4
- package/dist/auth/FileCertificateMaterialLoader.d.ts +0 -6
- package/dist/auth/FileCertificateMaterialLoader.d.ts.map +0 -1
- package/dist/auth/FileCertificateMaterialLoader.js +0 -28
- package/dist/auth/ntlm.d.ts +0 -26
- package/dist/auth/ntlm.d.ts.map +0 -1
- package/dist/auth/ntlm.js +0 -72
- package/dist/auth/providers.d.ts +0 -125
- package/dist/auth/providers.d.ts.map +0 -1
- package/dist/auth/providers.js +0 -183
- package/dist/utils/tokenRefresh.d.ts +0 -15
- package/dist/utils/tokenRefresh.d.ts.map +0 -1
- package/dist/utils/tokenRefresh.js +0 -55
package/docs/JWT_AUTH_TOOLS.md
CHANGED
|
@@ -126,8 +126,8 @@ Or configure `SapConfig` directly:
|
|
|
126
126
|
import {
|
|
127
127
|
AdtCloudConnector,
|
|
128
128
|
CloudHttpTransport,
|
|
129
|
-
TokenAuthProvider,
|
|
130
129
|
} from "@mcp-abap-adt/connection";
|
|
130
|
+
import { TokenAuthProvider } from "@mcp-abap-adt/auth-providers";
|
|
131
131
|
import type { SapConfig } from "@mcp-abap-adt/connection";
|
|
132
132
|
|
|
133
133
|
const config: SapConfig = {
|
|
@@ -139,7 +139,7 @@ const logger = console;
|
|
|
139
139
|
|
|
140
140
|
const connection = new AdtCloudConnector(
|
|
141
141
|
config,
|
|
142
|
-
|
|
142
|
+
TokenAuthProvider.fixed(config.jwtToken!),
|
|
143
143
|
new CloudHttpTransport(() => ({}), logger, {
|
|
144
144
|
client: config.client,
|
|
145
145
|
baseUrl: config.url,
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Migration to 10.0
|
|
2
|
+
|
|
3
|
+
The connection now speaks `IAuthProvider` 3.0 (`@mcp-abap-adt/interfaces-auth`
|
|
4
|
+
^3.0.0), and the credential providers left this package for
|
|
5
|
+
`@mcp-abap-adt/auth-providers`.
|
|
6
|
+
|
|
7
|
+
What changed in behaviour is who decides. The connection asks the provider
|
|
8
|
+
before every attempt (`authorize`), at every logon (`establish`) and when the
|
|
9
|
+
system refuses (`rejected`); it never asks what kind of provider it holds. The
|
|
10
|
+
wire offers what it can carry, the provider writes the credential into it, and
|
|
11
|
+
the connection decides the lifecycle: exactly one more attempt after the provider
|
|
12
|
+
says Ok, never a loop.
|
|
13
|
+
|
|
14
|
+
**What you do**, in the order it usually bites:
|
|
15
|
+
|
|
16
|
+
1. [Import the providers from `@mcp-abap-adt/auth-providers`](#1-the-providers-moved).
|
|
17
|
+
2. [Build a token provider with `.fixed` or `.from`](#2-tokenauthprovider-has-two-constructors-now).
|
|
18
|
+
3. [Drop the hand-wired TLS material](#3-tls-material-is-taken-at-logon).
|
|
19
|
+
4. [If you take the RFC wire and wrote your own factory, pass the logon parameters through](#4-rfc-the-factory-takes-the-logon-parameters).
|
|
20
|
+
5. [Catch `AuthRefusedError` where you matched a 401](#5-catch-authrefusederror).
|
|
21
|
+
6. [If you wrote a wire, use `authorize` and `logon`](#6-a-custom-wire).
|
|
22
|
+
|
|
23
|
+
If you use none of these — you hold a provider you wrote yourself against
|
|
24
|
+
`IAuthProvider` 3.0 and take the HTTP wire — only step 5 can concern you.
|
|
25
|
+
|
|
26
|
+
## 1. The providers moved
|
|
27
|
+
|
|
28
|
+
`BasicAuthProvider`, `TokenAuthProvider`, `SamlAuthProvider`,
|
|
29
|
+
`CertificateAuthProvider` and `FileCertificateMaterialLoader` are no longer
|
|
30
|
+
exported here. They are in `@mcp-abap-adt/auth-providers` ^5.0.1 with the same
|
|
31
|
+
names.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @mcp-abap-adt/auth-providers
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```diff
|
|
38
|
+
-import {
|
|
39
|
+
- AdtOnPremConnector,
|
|
40
|
+
- BasicAuthProvider,
|
|
41
|
+
- OnPremHttpTransport,
|
|
42
|
+
-} from '@mcp-abap-adt/connection';
|
|
43
|
+
+import { AdtOnPremConnector, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
44
|
+
+import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This package has no runtime dependency on `auth-providers`; you install it
|
|
48
|
+
because you use it. `IAuthProvider` itself is still not re-exported: import the
|
|
49
|
+
type from `@mcp-abap-adt/interfaces-auth`, which is where the ^3.0.0 contract
|
|
50
|
+
lives — an older `interfaces-auth` makes a provider of yours a type error.
|
|
51
|
+
|
|
52
|
+
## 2. `TokenAuthProvider` has two constructors now
|
|
53
|
+
|
|
54
|
+
`new TokenAuthProvider(x)` is gone. A fixed token and a renewing one are different
|
|
55
|
+
objects, and the name says which.
|
|
56
|
+
|
|
57
|
+
```diff
|
|
58
|
+
-new TokenAuthProvider('eyJhbGciOiJSUzI1NiIs...')
|
|
59
|
+
+TokenAuthProvider.fixed('eyJhbGciOiJSUzI1NiIs...')
|
|
60
|
+
|
|
61
|
+
-new TokenAuthProvider(refresher)
|
|
62
|
+
+TokenAuthProvider.from(refresher)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`.from` renews when the system refuses the token — not by checking expiry before
|
|
66
|
+
each request, as the old class did. Many requests meeting one expired token each
|
|
67
|
+
call `rejected()`; the connection adds no single-flight of its own. Whether they
|
|
68
|
+
share one renewal in flight is the refresher's: `.from` asks it on each
|
|
69
|
+
rejection, so they share one only if your refresher shares one.
|
|
70
|
+
|
|
71
|
+
## 3. TLS material is taken at logon
|
|
72
|
+
|
|
73
|
+
Before, a certificate credential's `cert` / `key` / `pfx` / `passphrase` reached
|
|
74
|
+
the HTTPS agent only because you passed them in `agentOptions`:
|
|
75
|
+
|
|
76
|
+
```diff
|
|
77
|
+
-const material = await loader.load(config);
|
|
78
|
+
new OnPremHttpTransport(
|
|
79
|
+
- () => ({ cert: material.cert, key: material.key, ca: myCa }),
|
|
80
|
+
+ () => ({ ca: myCa }),
|
|
81
|
+
logger,
|
|
82
|
+
{ client: config.client, baseUrl: config.url },
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Now the HTTP wire offers a logon target to the provider at every logon; a
|
|
87
|
+
provider such as `CertificateAuthProvider` hands over its material there, and the
|
|
88
|
+
wire builds the agent from `{ rejectUnauthorized, ...agentOptions(), ...material }`
|
|
89
|
+
on the first request, where `material` is only the `cert`, `key`, `pfx` and
|
|
90
|
+
`passphrase` the provider offered with a value — any other key it passes is
|
|
91
|
+
ignored, and a field offered as `undefined` erases nothing. A later logon offering different material replaces the
|
|
92
|
+
client; the cookie jar and CSRF token are the session's and stay.
|
|
93
|
+
|
|
94
|
+
`agentOptions` stays for what is not the credential: `ca` and
|
|
95
|
+
`rejectUnauthorized`. Material you leave in it still works for a provider that
|
|
96
|
+
offers none, but nothing depends on that.
|
|
97
|
+
|
|
98
|
+
## 4. RFC: the factory takes the logon parameters
|
|
99
|
+
|
|
100
|
+
`RfcTransport` opens a conversation for the session and one per non-stateful
|
|
101
|
+
call, and each open now takes the logon parameters the provider wrote for it —
|
|
102
|
+
a password, or SNC settings.
|
|
103
|
+
|
|
104
|
+
- `RfcTransport`'s first argument is
|
|
105
|
+
`(logon: Readonly<Record<string, string>>) => IRfcConversation`; it was
|
|
106
|
+
`() => IRfcConversation`.
|
|
107
|
+
- `rfcConversationFrom(config)` returns such a factory. If you only ever passed
|
|
108
|
+
its result to `RfcTransport`, nothing changes for you.
|
|
109
|
+
- `rfcParamsFrom(config)` returns the address only — `ashost`, `sysnr`,
|
|
110
|
+
`client` (default `'000'`), `lang` (`'EN'`). It no longer reads
|
|
111
|
+
`config.username` / `config.password`, and `RfcConnectionParams` lost `user`
|
|
112
|
+
and `passwd`. The credential comes from the provider, and only from it.
|
|
113
|
+
|
|
114
|
+
If you wrote your own factory:
|
|
115
|
+
|
|
116
|
+
```diff
|
|
117
|
+
-const factory = () => new Client(rfcParamsFrom(config));
|
|
118
|
+
+const factory = (logon: Readonly<Record<string, string>>) =>
|
|
119
|
+
+ new Client({ ...rfcParamsFrom(config), ...logon });
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
A provider that writes no logon parameters — a bearer token — cannot log on over
|
|
123
|
+
RFC. The open fails, the provider is asked, and you get its refusal; RFC cannot
|
|
124
|
+
carry a bearer token.
|
|
125
|
+
|
|
126
|
+
A failed open is thrown as a `WireLogonError` whose `cause` is the raw
|
|
127
|
+
`sap-rfc-lite` error. The old `Failed to open RFC connection: …` wrapping is
|
|
128
|
+
gone, so a provider can read the SDK's `key` and message and, say, tell an SNC
|
|
129
|
+
failure from a network one.
|
|
130
|
+
|
|
131
|
+
**Every failed open, a network one included.** An open that fails because the
|
|
132
|
+
host cannot be reached (`RFC_COMMUNICATION_FAILURE`, say) is put to the provider
|
|
133
|
+
like a refused logon, and reaches you as an `AuthRefusedError` at `'logon'` — in
|
|
134
|
+
the provider's words, or the fixed "refused again" reason after its Ok — with the
|
|
135
|
+
SDK's error only in `cause`. A caller that matched the SDK error to tell an
|
|
136
|
+
unreachable system from a refused one reads `cause` now.
|
|
137
|
+
|
|
138
|
+
## 5. Catch `AuthRefusedError`
|
|
139
|
+
|
|
140
|
+
Before, a refused credential arrived as whatever the wire threw — an axios error
|
|
141
|
+
with `response.status === 401`, an RFC logon failure — and a caller matching on
|
|
142
|
+
the status had to guess what it meant.
|
|
143
|
+
|
|
144
|
+
Now a 401 that survives the wire's own session recovery, and any refused logon, is put to
|
|
145
|
+
`provider.rejected(...)`. On Ok the request is authorized again and sent once
|
|
146
|
+
more; if the provider says no, or the retry is refused too, the caller gets an
|
|
147
|
+
`AuthRefusedError`:
|
|
148
|
+
|
|
149
|
+
```diff
|
|
150
|
+
try {
|
|
151
|
+
await connection.connect();
|
|
152
|
+
} catch (error) {
|
|
153
|
+
- if ((error as any).response?.status === 401) {
|
|
154
|
+
- console.error('bad credentials');
|
|
155
|
+
- }
|
|
156
|
+
+ if (error instanceof AuthRefusedError) {
|
|
157
|
+
+ // The provider's words, not ours: it knows whether it was a password, a
|
|
158
|
+
+ // token, or an SNC library that was missing.
|
|
159
|
+
+ console.error(error.refusal.reason, error.refusal.hint);
|
|
160
|
+
+ }
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```text
|
|
165
|
+
class AuthRefusedError extends Error {
|
|
166
|
+
readonly refusal: { reason: string; hint?: string }; // the provider's words
|
|
167
|
+
readonly at: 'prepare' | 'logon' | 'request'; // when it refused
|
|
168
|
+
readonly cause?: unknown; // the provider's throw when it threw, else the wire's error
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
- `at: 'prepare'` — the provider refused before the wire opened; nothing was sent.
|
|
173
|
+
- `at: 'logon'` — the system refused a logon, or the provider refused to offer one.
|
|
174
|
+
- `at: 'request'` — the provider refused to authorize a request, or the system
|
|
175
|
+
refused it again after a renewal.
|
|
176
|
+
- After an Ok, a second refusal is the verdict: the provider is not asked again
|
|
177
|
+
and `refusal` is `{ reason: 'the credential was refused again after the
|
|
178
|
+
provider renewed it' }`, with the second wire error as `cause`.
|
|
179
|
+
- A provider that throws is treated as refusing with the reason "the credential
|
|
180
|
+
provider failed" and the throw as `cause`.
|
|
181
|
+
- A `403` is never put to the provider and never becomes an `AuthRefusedError`; it
|
|
182
|
+
reaches you unchanged, as before.
|
|
183
|
+
|
|
184
|
+
Inside a critical section (`beginCriticalSection()`), a mutation refused with a
|
|
185
|
+
401 while a CSRF token is cached is no longer moved to a new session: it goes to
|
|
186
|
+
the provider and is resent on the same one, so the lock survives — or it fails
|
|
187
|
+
with `SESSION_REPLACED` if SAP replaced the session. Outside a critical section
|
|
188
|
+
the wire's stale-session recovery still runs first.
|
|
189
|
+
|
|
190
|
+
`prepare()` now runs once at the start of `connect()`, before the wire opens; it
|
|
191
|
+
used to come after `transport.open()`.
|
|
192
|
+
|
|
193
|
+
## 6. A custom wire
|
|
194
|
+
|
|
195
|
+
If you implement `IAdtTransport` yourself, `IAdtSessionContext.authHeaders` is
|
|
196
|
+
gone. Two methods replace it:
|
|
197
|
+
|
|
198
|
+
- `authorize(headers)` — fill the credential into a request the wire itself
|
|
199
|
+
originates (the CSRF fetch, a preflight, a logoff), per request, never held.
|
|
200
|
+
- `logon(target)` — call it at each of your logons, before any request. Pass a
|
|
201
|
+
`target` (an `ILogonTarget`) that says what your wire can carry: `tlsMaterial`
|
|
202
|
+
and `logonParameters` each answer Ok or `{ ok: false, refusal }`.
|
|
203
|
+
|
|
204
|
+
```diff
|
|
205
|
+
async close(context: IAdtSessionContext): Promise<void> {
|
|
206
|
+
const headers: Record<string, string> = {};
|
|
207
|
+
- Object.assign(headers, await context.authHeaders());
|
|
208
|
+
- await this.client.post('/logoff', undefined, { headers });
|
|
209
|
+
+ // A goodbye never throws: `authorize` throws AuthRefusedError when the
|
|
210
|
+
+ // provider refuses, and the connection does not await every close.
|
|
211
|
+
+ try {
|
|
212
|
+
+ await context.authorize(headers);
|
|
213
|
+
+ await this.client.post('/logoff', undefined, { headers });
|
|
214
|
+
+ } catch {
|
|
215
|
+
+ // Nothing to tell anyone: the session falls to its idle timeout.
|
|
216
|
+
+ }
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`close()` must not throw. `context.authorize` throws `AuthRefusedError` when the
|
|
221
|
+
provider refuses, so a goodbye that authorizes catches it; the connection absorbs
|
|
222
|
+
a rejected close it dispatched, but a close that never throws is the contract.
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
import type {
|
|
226
|
+
AuthOutcome,
|
|
227
|
+
ILogonTarget,
|
|
228
|
+
} from '@mcp-abap-adt/interfaces-auth';
|
|
229
|
+
import {
|
|
230
|
+
type IAdtSessionContext,
|
|
231
|
+
WireLogonError,
|
|
232
|
+
} from '@mcp-abap-adt/connection';
|
|
233
|
+
|
|
234
|
+
async function logOn(
|
|
235
|
+
context: IAdtSessionContext,
|
|
236
|
+
open: (parameters: Record<string, string>) => Promise<void>,
|
|
237
|
+
): Promise<void> {
|
|
238
|
+
let parameters: Record<string, string> = {};
|
|
239
|
+
const target: ILogonTarget = {
|
|
240
|
+
tlsMaterial: (): AuthOutcome => ({
|
|
241
|
+
ok: false,
|
|
242
|
+
refusal: { reason: 'this wire carries no TLS material (example wire)' },
|
|
243
|
+
}),
|
|
244
|
+
logonParameters: (offered): AuthOutcome => {
|
|
245
|
+
parameters = { ...offered };
|
|
246
|
+
return { ok: true };
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
// Throws AuthRefusedError(at 'logon') if the provider refuses the logon.
|
|
250
|
+
await context.logon(target);
|
|
251
|
+
try {
|
|
252
|
+
await open(parameters);
|
|
253
|
+
} catch (cause) {
|
|
254
|
+
// Mark the failure as a refused logon; the connection asks the provider
|
|
255
|
+
// what to do about it. The wire decides nothing, and passes the raw error.
|
|
256
|
+
throw new WireLogonError(cause);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
`WireLogonError { cause, status? }` is the mark a wire puts on a failure that is
|
|
262
|
+
a refused logon. `cause` is the raw error, never re-wrapped; `status` is the HTTP
|
|
263
|
+
status when there is one (the HTTP wire marks a 401 while establishing its
|
|
264
|
+
session this way). A `WireLogonError` reaches `rejected()` with `at: 'logon'`; a
|
|
265
|
+
401 on a request that survived the wire's own recovery reaches it with
|
|
266
|
+
`at: 'request'`.
|
|
267
|
+
|
|
268
|
+
## Removed with no replacement
|
|
269
|
+
|
|
270
|
+
Nothing read them:
|
|
271
|
+
|
|
272
|
+
- `CredentialAbapConnection.getHttpsAgentOptions`, `buildAuthorizationHeader`, `isUnauthorized`
|
|
273
|
+
- `AbstractAbapConnection.recoverSession`, `discardSession`
|
|
274
|
+
- `src/utils/tokenRefresh.ts` and `src/auth/ntlm.ts` (neither was exported)
|
|
275
|
+
|
|
276
|
+
## Why
|
|
277
|
+
|
|
278
|
+
Until 9.x the connection read the credential itself: which header it produced,
|
|
279
|
+
whether it could be renewed, whether it carried TLS material, and it wrapped or
|
|
280
|
+
dropped what the wire said about a refusal. Each new kind of credential — a
|
|
281
|
+
token, a certificate, SNC — was a change in the connection, and a refusal reached
|
|
282
|
+
the caller as a bare 401 nobody could word. With `IAuthProvider` 3.0 the provider
|
|
283
|
+
writes the credential and words its own refusal, the wire only carries it, and
|
|
284
|
+
the connection keeps to the lifecycle: one more attempt, never a loop.
|
package/docs/SCOPE.md
CHANGED
|
@@ -7,14 +7,14 @@ This package is **one component of the `@mcp-abap-adt/*` family**. Each package
|
|
|
7
7
|
- **HTTP transport to SAP ADT** — request dispatch, CSRF token fetch, cookie and session handling, stateful/stateless session control.
|
|
8
8
|
- **The session lifecycle** — establishing a session and refusing to work without one, tearing it down without cutting in-flight requests, tracking which SAP session it is talking to, and telling the caller when that session is lost while a lock is held. See [USAGE.md — Session Lifecycle](./USAGE.md#session-lifecycle).
|
|
9
9
|
- **RFC transport to on-premise SAP** — via `@mcp-abap-adt/sap-rfc-lite` + NW RFC SDK, calling `SADT_REST_RFC_ENDPOINT` (the same FM Eclipse ADT uses on on-prem).
|
|
10
|
-
- **
|
|
10
|
+
- **Carrying what an `IAuthProvider` hands it** (Basic user/password, Bearer JWT, SAML session cookies, TLS material, RFC logon parameters), and asking the provider again once when the system refuses it. The providers themselves are in `@mcp-abap-adt/auth-providers`.
|
|
11
11
|
|
|
12
12
|
## What this package does NOT do, and where it lives instead
|
|
13
13
|
|
|
14
14
|
| Concern | Belongs in |
|
|
15
15
|
|---|---|
|
|
16
16
|
| Token acquisition (SAML/OAuth2 flows, browser login, PKCE) | `@mcp-abap-adt/auth-broker` |
|
|
17
|
-
| Token validation, refresh, re-authentication, expiry tracking |
|
|
17
|
+
| Token validation, refresh, re-authentication, expiry tracking | the `IAuthProvider` the consumer hands in (`@mcp-abap-adt/interfaces-auth`; ready-made ones in `@mcp-abap-adt/auth-providers`) |
|
|
18
18
|
| Session state persistence across processes | `@mcp-abap-adt/auth-broker` |
|
|
19
19
|
| Auth-type constants, provider error codes, auth lifecycle contracts | `@mcp-abap-adt/interfaces-auth`, `@mcp-abap-adt/interfaces-auth-sap` |
|
|
20
20
|
|
|
@@ -104,10 +104,10 @@ const logger = console;
|
|
|
104
104
|
```ts
|
|
105
105
|
import {
|
|
106
106
|
AdtOnPremConnector,
|
|
107
|
-
BasicAuthProvider,
|
|
108
107
|
OnPremHttpTransport,
|
|
109
108
|
getTimeout,
|
|
110
109
|
} from '@mcp-abap-adt/connection';
|
|
110
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
111
111
|
|
|
112
112
|
const connection = new AdtOnPremConnector(
|
|
113
113
|
config,
|
|
@@ -135,7 +135,8 @@ connection.setSessionType('stateless');
|
|
|
135
135
|
## Knowing Which Session You Are In
|
|
136
136
|
|
|
137
137
|
```ts
|
|
138
|
-
import { AdtOnPremConnector,
|
|
138
|
+
import { AdtOnPremConnector, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
139
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
139
140
|
|
|
140
141
|
// getSessionIdentity() is on the HTTP connection classes, NOT on the
|
|
141
142
|
// bare IAbapConnection type a caller may hand you.
|
|
@@ -170,13 +171,27 @@ Every ADT request issued through `makeAdtRequest` automatically:
|
|
|
170
171
|
|
|
171
172
|
This logic is transparent to callers (Builders, handlers, CLI scripts).
|
|
172
173
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
174
|
+
A 401 that survives the wire's own CSRF recovery is put to the provider (`rejected`). On Ok the
|
|
175
|
+
request is sent once more, always under the same lease and generation as the attempt it repeats,
|
|
176
|
+
so stale-request fencing applies. After a rejection at `'request'` that resend goes out on the
|
|
177
|
+
same session; after a rejection at `'logon'` the wire logs on again before the resend.
|
|
178
|
+
**Inside a critical section a renewal keeps the session, and the lock in it:** a mutation
|
|
179
|
+
(POST / PUT / DELETE) refused with a 401 while a CSRF token is cached goes to the provider and is
|
|
180
|
+
resent on the same session with the same token, and if SAP did replace the session the request
|
|
181
|
+
fails with `SESSION_REPLACED` instead of carrying on in a new one. Outside a critical section
|
|
182
|
+
that mutation takes the wire's own stale-session recovery first, which starts a new session
|
|
183
|
+
before the provider is asked — so hold a lock inside `beginCriticalSection()` /
|
|
184
|
+
`endCriticalSection()`.
|
|
185
|
+
**The price of keeping the lock:** when the session is really dead but SAP answers the resend with
|
|
186
|
+
the SAME session cookie (no `Set-Cookie`), the connection cannot tell it from a refused
|
|
187
|
+
credential — the second 401 ends the request as `AuthRefusedError` with the refused-again
|
|
188
|
+
verdict (`at: 'request'`), not `SESSION_REPLACED`, and the connection stays connected. Inside a
|
|
189
|
+
critical section, treat that as a lost lock: `disconnect()`, `connect()`, and redo the work under
|
|
190
|
+
a new lock.
|
|
191
|
+
If the provider says no, or the retry is refused too, the caller gets an `AuthRefusedError`. A 403 is an authorization answer, not a credential one: it never goes to the
|
|
192
|
+
provider. See [When the credential is refused](./USAGE.md#when-the-credential-is-refused).
|
|
193
|
+
|
|
194
|
+
A reconnect is a NEW session, so do it outside a lock window rather than inside one.
|
|
180
195
|
|
|
181
196
|
**Wait for the goodbye before opening the next one.** `disconnect()` dispatches the logoff and does
|
|
182
197
|
not await it, so a reconnect otherwise opens the next session while the previous one's goodbye is
|
|
@@ -270,6 +285,10 @@ What it promises is narrow and worth stating exactly — inside a section the
|
|
|
270
285
|
short: the ceiling is `SAP_TIMEOUT_CRITICAL`, ten minutes by default, and a
|
|
271
286
|
socket ends a request whatever a contract says.
|
|
272
287
|
|
|
288
|
+
Since 10.0.0 a section also keeps its session through a credential renewal: a
|
|
289
|
+
mutation refused with a 401 inside it is renewed and resent on the same
|
|
290
|
+
session, never moved to a new one (see [Request Hooks](#request-hooks)).
|
|
291
|
+
|
|
273
292
|
### Two sessions, and they are not the same thing
|
|
274
293
|
|
|
275
294
|
There are two sessions here, and they are not the same thing:
|
|
@@ -326,7 +345,8 @@ you get by asking — `getSessionIdentity()` for which session you are in, and
|
|
|
326
345
|
through the `ISessionLifecycleAware` atom:
|
|
327
346
|
|
|
328
347
|
```ts
|
|
329
|
-
import { AdtOnPremConnector,
|
|
348
|
+
import { AdtOnPremConnector, OnPremHttpTransport } from '@mcp-abap-adt/connection';
|
|
349
|
+
import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
|
|
330
350
|
|
|
331
351
|
const connection = new AdtOnPremConnector(config, new BasicAuthProvider(user, pass), new OnPremHttpTransport(() => ({}), logger, { client: config.client, baseUrl: config.url }), logger);
|
|
332
352
|
await connection.disconnect(); // ends the session on the server, then clears
|