@mcp-abap-adt/connection 11.0.0 → 12.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +125 -1
  2. package/README.md +39 -5
  3. package/dist/connection/AbstractAbapConnection.d.ts +7 -2
  4. package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
  5. package/dist/connection/AbstractAbapConnection.js +17 -16
  6. package/dist/connection/CloudHttpTransport.d.ts.map +1 -1
  7. package/dist/connection/CloudHttpTransport.js +3 -0
  8. package/dist/connection/CredentialAbapConnection.d.ts.map +1 -1
  9. package/dist/connection/CredentialAbapConnection.js +4 -4
  10. package/dist/connection/HttpTransport.d.ts +54 -8
  11. package/dist/connection/HttpTransport.d.ts.map +1 -1
  12. package/dist/connection/HttpTransport.js +168 -8
  13. package/dist/connection/OnPremHttpTransport.d.ts.map +1 -1
  14. package/dist/connection/OnPremHttpTransport.js +3 -0
  15. package/dist/connection/RfcTransport.d.ts +1 -1
  16. package/dist/connection/RfcTransport.d.ts.map +1 -1
  17. package/dist/connection/RfcTransport.js +32 -12
  18. package/dist/connection/authErrors.d.ts +20 -7
  19. package/dist/connection/authErrors.d.ts.map +1 -1
  20. package/dist/connection/authErrors.js +50 -19
  21. package/dist/connection/rfcConversation.d.ts.map +1 -1
  22. package/dist/connection/rfcConversation.js +0 -1
  23. package/docs/INDEX.md +3 -1
  24. package/docs/INSTALLATION.md +6 -3
  25. package/docs/MIGRATION-10.0.md +8 -1
  26. package/docs/MIGRATION-12.0.md +159 -0
  27. package/docs/SCOPE.md +2 -1
  28. package/docs/STATEFUL_SESSION_GUIDE.md +2 -1
  29. package/docs/USAGE.md +28 -4
  30. package/examples/README.md +1 -1
  31. package/examples/jwt-with-token-refresh.js +2 -1
  32. package/package.json +6 -5
@@ -0,0 +1,159 @@
1
+ # Migration to 12.0
2
+
3
+ 12.0.0 moves the connection onto the **authentication error contract**:
4
+ `@mcp-abap-adt/interfaces-auth` 6.0.0, which declares the types, and
5
+ `@mcp-abap-adt/auth-errors` 1.0.0, which mints them. Every refusal a provider,
6
+ a logon target or the connection itself gives is now an `IAuthProviderError`: a
7
+ frozen object with a `kind`, `facts` drawn from closed allowlists, and the
8
+ `reason` / `hint` words rendered from them. Free text no longer travels as a
9
+ refusal.
10
+
11
+ The lifecycle didn't change. `prepare`, `establish`, `authorize` and `rejected`
12
+ are called when and as often as in 11.x. One `rejected` Ok still buys exactly
13
+ one more attempt, and a second refusal is still the verdict. The client guard
14
+ of 11.0.1 is unchanged: a request naming another SAP client is still refused
15
+ before anything is sent.
16
+
17
+ ## Dependencies
18
+
19
+ | Package | 11.x | 12.0 |
20
+ |---|---|---|
21
+ | `@mcp-abap-adt/interfaces-auth` | `^3.0.0` | `^6.0.0` |
22
+ | `@mcp-abap-adt/interfaces-auth-sap` | `^2.0.0` | `^3.2.0` |
23
+ | `@mcp-abap-adt/auth-errors` | — | `^1.0.0` (new) |
24
+
25
+ A process should hold **one** interfaces-auth major. Check it with
26
+ `npm ls @mcp-abap-adt/interfaces-auth`.
27
+
28
+ **The providers of `@mcp-abap-adt/auth-providers` 5.x do not fit.** They answer
29
+ unbranded `{ reason, hint }` refusals of interfaces-auth 3–5, and those are not
30
+ an `AuthOutcome` of 6.0.0, so handing a 5.x `BasicAuthProvider` (or any other
31
+ 5.x provider) to a connector no longer compiles. Move to
32
+ `@mcp-abap-adt/auth-providers` 6.0.0, the release that adopts the same
33
+ contract, when it is published. Until then, stay on connection 11.x.
34
+
35
+ ## Reading an `AuthRefusedError`
36
+
37
+ `AuthRefusedError` keeps its shape: `refusal`, `at` (`'prepare' | 'logon' |
38
+ 'request'`), `cause`. Its `message` is still `reason — hint`, or the reason
39
+ alone. What changed is `refusal`. It is an `IAuthProviderError`, so decide on
40
+ its `kind` and `facts`, never on its words:
41
+
42
+ ```typescript
43
+ import { AuthRefusedError } from '@mcp-abap-adt/connection';
44
+
45
+ function explain(error: unknown): string | undefined {
46
+ if (!(error instanceof AuthRefusedError)) return undefined;
47
+ const refusal = error.refusal;
48
+ if (refusal.kind === 'credential-refused') {
49
+ return `the ${refusal.facts.credential} was refused at ${error.at}`;
50
+ }
51
+ if (refusal.kind === 'connection' && refusal.facts.problem === 'provider-threw') {
52
+ return 'the credential provider is broken; see error.cause';
53
+ }
54
+ return error.message; // reason — hint, as in 11.x
55
+ }
56
+ ```
57
+
58
+ `refusal.reason` and `refusal.hint` read as before. For a switch over every
59
+ kind that stops compiling when a kind is added, use `matchKind` from
60
+ `@mcp-abap-adt/auth-errors` (see its README).
61
+
62
+ **A refusal is frozen.** It is deep-frozen, so don't write to it. Relay it as
63
+ the object it is. Don't spread it into a new object (`{ ...refusal }`), because
64
+ a copy is no longer a minted error. A `structuredClone` of a refusal (sent to
65
+ a worker, say) is no longer minted either: `isMinted` answers false. Classify
66
+ it again with `classify` from `auth-errors` before deciding on it.
67
+
68
+ **`AuthRefusedError` classifies the refusal it is given.** Its constructor
69
+ reads none of its words as given:
70
+ - A refusal minted by this copy of `auth-errors` is kept as the same object.
71
+ - A clone or another copy's refusal is rebuilt from its `kind` and `facts`.
72
+ Its words are rendered anew, and its diagnostics are dropped.
73
+ - Anything else is `provider-threw` at the error's moment.
74
+
75
+ So an `AuthRefusedError` built over a clone still reads `reason — hint`, and
76
+ text written into a clone's `reason`, `hint` or `diagnostics` reaches neither
77
+ `refusal` nor `message`.
78
+
79
+ ## The connection's own refusals
80
+
81
+ The words are unchanged. Each now has a kind and facts:
82
+
83
+ | When | `kind` | `facts` | `reason` |
84
+ |---|---|---|---|
85
+ | the RFC wire is offered TLS material | `logon-target` | `{ wire: 'rfc', refused: 'tls-material' }` | `this wire carries no TLS material (RFC)` |
86
+ | the HTTP wire is offered logon parameters | `logon-target` | `{ wire: 'http', refused: 'logon-parameters' }` | `this wire takes no logon parameters (HTTP)` |
87
+ | the provider threw, or answered something that is not an outcome | `connection` | `{ problem: 'provider-threw', at }` | `the credential provider failed` |
88
+ | refused again after the provider renewed | `connection` | `{ problem: 'refused-after-renewal', at }` | `the credential was refused again after the provider renewed it` |
89
+ | a connection without a credential is asked to renew | `connection` | `{ problem: 'no-credential' }` | `this connection has no credential to renew` |
90
+
91
+ `at` in `facts` is the moment of the `AuthRefusedError` that carries it.
92
+
93
+ **The connection re-checks what a provider answers.** Every answer passes
94
+ through `classifyOutcome`:
95
+ - A refusal minted by the same `auth-errors` passes as the same object.
96
+ - A refusal minted by another copy is rebuilt from its kind and facts.
97
+ - Anything else (a plain `{ reason: '…' }` from a provider written in
98
+ JavaScript, a non-outcome) becomes `provider-threw`, and its text reaches no
99
+ message.
100
+
101
+ A provider that throws is `provider-threw` too, with the throw as `cause`, as
102
+ in 11.x.
103
+
104
+ ## A logon target of your own
105
+
106
+ A wire of your own hands the provider an `ILogonTarget`. Its refusals must be
107
+ minted now, because an object literal is not an `IAuthProviderError` and does
108
+ not compile:
109
+
110
+ ```typescript
111
+ import { authError } from '@mcp-abap-adt/auth-errors';
112
+ import type { AuthOutcome, ILogonTarget } from '@mcp-abap-adt/interfaces-auth';
113
+
114
+ function logonTarget(parameters: Record<string, string>): ILogonTarget {
115
+ return {
116
+ // A wire of your own is neither of connection's two, so it is `unknown`:
117
+ // "the logon target did not take the TLS material".
118
+ tlsMaterial: (): AuthOutcome => ({
119
+ ok: false,
120
+ refusal: authError['logon-target']({
121
+ wire: 'unknown',
122
+ refused: 'tls-material',
123
+ }),
124
+ }),
125
+ logonParameters: (offered): AuthOutcome => {
126
+ Object.assign(parameters, offered);
127
+ return { ok: true };
128
+ },
129
+ };
130
+ }
131
+ ```
132
+
133
+ `wire` is one of `http`, `rfc` or `unknown`. `http` and `rfc` carry the words
134
+ of connection's own wires (`this wire takes no logon parameters (HTTP)`, …), so
135
+ a target of your own uses `unknown` unless it really is one of those.
136
+
137
+ ## A provider of your own
138
+
139
+ An `IAuthProvider` you wrote answers minted refusals: `authError[kind](facts)`
140
+ from `@mcp-abap-adt/auth-errors`. Its `guard(operation, body)` runs one
141
+ moment so that a throw becomes a refusal and the answer is classified. A
142
+ provider that still answers `{ ok: false, refusal: { reason } }` compiles no
143
+ more in TypeScript. In JavaScript, the connection answers `provider-threw` for
144
+ it, as described above. `@mcp-abap-adt/auth-providers` 6.0.0 ships
145
+ `AuthProviderBase`, which owns the four moments for you.
146
+
147
+ ## Deep imports
148
+
149
+ 11.0.1's index exported none of the refusal constants: only
150
+ `AuthRefusedError`, `AuthRefusalMoment` and `WireLogonError`, all unchanged.
151
+ There is no `exports` map, though, so a deep import of
152
+ `dist/connection/authErrors.js` was possible. If you did that:
153
+
154
+ - `PROVIDER_FAILED` and `REFUSED_AGAIN` are gone. They are internal functions
155
+ of the moment now, `providerFailed(at)` and `refusedAgain(at)`.
156
+ - `NO_CREDENTIAL_TO_RENEW` is a minted error.
157
+ - `guarded(call, at)` takes the moment.
158
+
159
+ None of these is an API. Read the refusal's `kind` and `facts` instead.
package/docs/SCOPE.md CHANGED
@@ -17,6 +17,7 @@ This package is **one component of the `@mcp-abap-adt/*` family**. Each package
17
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
+ | Minting and classifying an auth refusal (`IAuthProviderError`) | `@mcp-abap-adt/auth-errors` |
20
21
 
21
22
  The rule: **if it is about *acquiring* or *refreshing* credentials, it is not our job.** We receive credentials that are valid at call time and use them. The consumer is responsible for handing us fresh ones — they know their IdP, their refresh cadence, their re-auth UX.
22
23
 
@@ -41,4 +42,4 @@ It forwards every `(name, value)` pair from the JS `Client(params)` object to `R
41
42
 
42
43
  - [`INSTALLATION.md`](./INSTALLATION.md)
43
44
  - [`USAGE.md`](./USAGE.md)
44
- - Sibling packages: `@mcp-abap-adt/interfaces-adt-connection`, `@mcp-abap-adt/interfaces-auth`, `@mcp-abap-adt/interfaces-auth-sap`, `@mcp-abap-adt/interfaces-network`, `@mcp-abap-adt/interfaces-utils`, `@mcp-abap-adt/sap-rfc-lite`, `@mcp-abap-adt/auth-broker`
45
+ - Sibling packages: `@mcp-abap-adt/interfaces-adt-connection`, `@mcp-abap-adt/interfaces-auth`, `@mcp-abap-adt/interfaces-auth-sap`, `@mcp-abap-adt/interfaces-network`, `@mcp-abap-adt/interfaces-utils`, `@mcp-abap-adt/auth-errors` (mints and classifies every auth refusal), `@mcp-abap-adt/sap-rfc-lite`, `@mcp-abap-adt/auth-broker`
@@ -18,6 +18,7 @@ This document explains how `@mcp-abap-adt/connection` manages HTTP-level session
18
18
 
19
19
  - Fetch and cache CSRF token (per connection instance)
20
20
  - Store/reuse SAP cookies (`SAP_SESSIONID`, `sap-usercontext`, etc.)
21
+ - Address the configured SAP client from the first request on (`sap-client` header and `sap-usercontext` cookie)
21
22
  - Track WHICH SAP session a connection is in, and refuse to work once it is lost
22
23
 
23
24
  The connection layer **does not** decide when to lock/unlock objects—that logic lives in the ADT clients. Instead it ensures every request shares the same HTTP session when desired.
@@ -188,7 +189,7 @@ credential — the second 401 ends the request as `AuthRefusedError` with the re
188
189
  verdict (`at: 'request'`), not `SESSION_REPLACED`, and the connection stays connected. Inside a
189
190
  critical section, treat that as a lost lock: `disconnect()`, `connect()`, and redo the work under
190
191
  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
+ If the provider says no, or the retry is refused too, the caller gets an `AuthRefusedError` (the refused-again verdict is `refusal.kind === 'connection'`, `facts.problem === 'refused-after-renewal'`). A 403 is an authorization answer, not a credential one: it never goes to the
192
193
  provider. See [When the credential is refused](./USAGE.md#when-the-credential-is-refused).
193
194
 
194
195
  A reconnect is a NEW session, so do it outside a lock window rather than inside one.
package/docs/USAGE.md CHANGED
@@ -928,7 +928,7 @@ export class CloudSdkAbapConnection {
928
928
  ### The credential, and how a refusal is classified
929
929
 
930
930
  For SAP BTP cloud systems, hand `AdtCloudConnector` a token provider from
931
- `@mcp-abap-adt/auth-providers`: `TokenAuthProvider.fixed(token)` is a token with
931
+ `@mcp-abap-adt/auth-providers` (6.0.0 or later with connection 12.x): `TokenAuthProvider.fixed(token)` is a token with
932
932
  nothing behind it, `TokenAuthProvider.from(refresher)` takes an `ITokenRefresher`
933
933
  and renews a token the system refused. Obtaining tokens in the first place is
934
934
  `@mcp-abap-adt/auth-broker`'s job, not this package's.
@@ -997,9 +997,13 @@ try {
997
997
  await connection.connect();
998
998
  } catch (error) {
999
999
  if (error instanceof AuthRefusedError) {
1000
- // error.refusal.reason / .hint are the provider's words;
1000
+ // error.refusal is an IAuthProviderError: decide on its kind and facts;
1001
+ // .reason / .hint are the words to show (the message is `reason — hint`).
1001
1002
  // error.at is 'prepare' | 'logon' | 'request'; error.cause is the provider's
1002
1003
  // throw when it threw, else the wire's error.
1004
+ if (error.refusal.kind === 'credential-refused') {
1005
+ // the credential itself was refused
1006
+ }
1003
1007
  console.error(error.message);
1004
1008
  }
1005
1009
  throw error;
@@ -1008,8 +1012,28 @@ try {
1008
1012
 
1009
1013
  `refusal` is the provider's, `cause` is the error the wire raised as it arrived,
1010
1014
  so a network failure stays visible even when a provider words it as a credential
1011
- problem. A provider that throws is treated as refusing with the reason "the
1012
- credential provider failed" and the throw as the cause.
1015
+ problem. A refusal is an `IAuthProviderError` minted by `@mcp-abap-adt/auth-errors`
1016
+ — frozen, with a `kind` and `facts` from closed allowlists; relay it, never copy
1017
+ it. Every provider answer is re-checked with `classifyOutcome`: a minted refusal
1018
+ passes as the same object, one from another copy of `auth-errors` is rebuilt,
1019
+ and anything else — a plain `{ reason }` from a JavaScript provider, a value that
1020
+ is no outcome — becomes `connection` / `provider-threw`, "the credential provider
1021
+ failed", its text in no message. A provider that throws is the same refusal,
1022
+ with the throw as the cause.
1023
+
1024
+ The connection's own refusals:
1025
+
1026
+ | `kind` | `facts` | words |
1027
+ |---|---|---|
1028
+ | `logon-target` | `{ wire: 'rfc', refused: 'tls-material' }` | this wire carries no TLS material (RFC) |
1029
+ | `logon-target` | `{ wire: 'http', refused: 'logon-parameters' }` | this wire takes no logon parameters (HTTP) |
1030
+ | `connection` | `{ problem: 'provider-threw', at }` | the credential provider failed |
1031
+ | `connection` | `{ problem: 'refused-after-renewal', at }` | the credential was refused again after the provider renewed it |
1032
+ | `connection` | `{ problem: 'no-credential' }` | this connection has no credential to renew |
1033
+
1034
+ A wire of your own mints its target's refusals the same way
1035
+ (`authError['logon-target']({ wire: 'unknown', refused })`); see
1036
+ [MIGRATION-12.0.md](./MIGRATION-12.0.md).
1013
1037
 
1014
1038
  **Concurrency.** Many requests meeting the same expired token each call
1015
1039
  `rejected()`; the connection adds no single-flight of its own. They share one
@@ -8,7 +8,7 @@ This directory contains example code demonstrating how to use the `@mcp-abap-adt
8
8
  # Install dependencies
9
9
  cd packages/connection
10
10
  npm install
11
- npm install @mcp-abap-adt/auth-providers # the credential providers the examples use
11
+ npm install @mcp-abap-adt/auth-providers # the credential providers the examples use (6.0.0 or later with connection 12.x)
12
12
 
13
13
  # Build the package
14
14
  npm run build
@@ -9,7 +9,8 @@
9
9
  * 1. Calls tokenRefresher.refreshToken() to get a new token
10
10
  * 2. Answers Ok, so the connection authorizes the request again
11
11
  * 3. The request is sent exactly once more; a second refusal is an
12
- * AuthRefusedError carrying the provider's words
12
+ * AuthRefusedError with the connection's verdict, `refusal.kind`
13
+ * 'connection' / `facts.problem` 'refused-after-renewal'
13
14
  *
14
15
  * A **403** is left alone. It means the server authenticated you and refused
15
16
  * the action anyway — an authorization gap, not an expired credential — so it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-abap-adt/connection",
3
- "version": "11.0.0",
3
+ "version": "12.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",
@@ -39,12 +39,12 @@
39
39
  "chrono": "node scripts/version-stats.mjs",
40
40
  "clean": "node scripts/clean.mjs",
41
41
  "lint": "npx biome check --write src scripts",
42
- "lint:check": "npx biome check src scripts",
42
+ "lint:check": "npx biome check src scripts --error-on-warnings && node tools/check-provider-shape.mjs --rules 4,5,6",
43
43
  "format": "npx biome format --write src scripts",
44
44
  "build": "npm run --silent clean && npx biome check src scripts --diagnostic-level=error && npx tsc -p tsconfig.json && npm run --silent typecheck:scripts",
45
45
  "build:fast": "npx tsc -p tsconfig.json",
46
46
  "test": "npm run --silent check:docs && jest",
47
- "prepublishOnly": "npm run build && npm run check:docs && npm run --silent check:pack",
47
+ "prepublishOnly": "npm run build && npm run lint:check && npm run check:docs && npm run --silent check:pack",
48
48
  "check:docs": "node scripts/check-docs.mjs",
49
49
  "typecheck:scripts": "npx tsc -p tsconfig.scripts.json",
50
50
  "check:pack": "node scripts/check-pack.mjs"
@@ -53,9 +53,10 @@
53
53
  "node": "^22 || ^24 || ^26"
54
54
  },
55
55
  "dependencies": {
56
+ "@mcp-abap-adt/auth-errors": "^1.0.0",
56
57
  "@mcp-abap-adt/interfaces-adt-connection": "^1.0.0",
57
- "@mcp-abap-adt/interfaces-auth": "^3.0.0",
58
- "@mcp-abap-adt/interfaces-auth-sap": "^2.0.0",
58
+ "@mcp-abap-adt/interfaces-auth": "^6.0.0",
59
+ "@mcp-abap-adt/interfaces-auth-sap": "^3.2.0",
59
60
  "@mcp-abap-adt/interfaces-network": "^2.0.0",
60
61
  "@mcp-abap-adt/interfaces-utils": "^1.1.0",
61
62
  "axios": "^1.16.0",