@mcp-abap-adt/connection 15.1.0 → 17.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 +187 -1
- package/README.md +137 -33
- package/dist/connection/AbstractAbapConnection.d.ts +140 -58
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +349 -255
- package/dist/connection/AdtCloudConnector.d.ts +6 -1
- package/dist/connection/AdtCloudConnector.d.ts.map +1 -1
- package/dist/connection/AdtCloudConnector.js +7 -2
- package/dist/connection/AdtOnPremConnector.d.ts +6 -1
- package/dist/connection/AdtOnPremConnector.d.ts.map +1 -1
- package/dist/connection/AdtOnPremConnector.js +7 -2
- package/dist/connection/CloudHttpTransport.d.ts +8 -1
- package/dist/connection/CloudHttpTransport.d.ts.map +1 -1
- package/dist/connection/CloudHttpTransport.js +30 -18
- package/dist/connection/CredentialAbapConnection.d.ts +3 -1
- package/dist/connection/CredentialAbapConnection.d.ts.map +1 -1
- package/dist/connection/CredentialAbapConnection.js +4 -2
- package/dist/connection/GenericWebSocketTransport.d.ts.map +1 -1
- package/dist/connection/GenericWebSocketTransport.js +7 -4
- package/dist/connection/HttpTransport.d.ts +80 -6
- package/dist/connection/HttpTransport.d.ts.map +1 -1
- package/dist/connection/HttpTransport.js +258 -25
- package/dist/connection/IAdtTransport.d.ts +46 -22
- package/dist/connection/IAdtTransport.d.ts.map +1 -1
- package/dist/connection/OnPremHttpTransport.d.ts +2 -13
- package/dist/connection/OnPremHttpTransport.d.ts.map +1 -1
- package/dist/connection/OnPremHttpTransport.js +16 -32
- package/dist/connection/RfcTransport.d.ts +7 -6
- package/dist/connection/RfcTransport.d.ts.map +1 -1
- package/dist/connection/RfcTransport.js +27 -49
- package/dist/connection/createConnection.d.ts +95 -0
- package/dist/connection/createConnection.d.ts.map +1 -0
- package/dist/connection/createConnection.js +44 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/docs/INDEX.md +6 -2
- package/docs/MIGRATION-16.0.md +123 -0
- package/docs/MIGRATION-17.0.md +119 -0
- package/docs/SCOPE.md +22 -45
- package/docs/STATEFUL_SESSION_GUIDE.md +49 -49
- package/docs/USAGE.md +244 -120
- package/package.json +2 -2
- package/dist/connection/requestAbort.d.ts +0 -32
- package/dist/connection/requestAbort.d.ts.map +0 -1
- package/dist/connection/requestAbort.js +0 -69
- package/dist/utils/timeouts.d.ts +0 -18
- package/dist/utils/timeouts.d.ts.map +0 -1
- package/dist/utils/timeouts.js +0 -37
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,190 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [17.0.0] - 2026-10-13
|
|
11
|
+
|
|
12
|
+
What this package answers for is listed in [docs/SCOPE.md](./docs/SCOPE.md).
|
|
13
|
+
See [docs/MIGRATION-17.0.md](./docs/MIGRATION-17.0.md).
|
|
14
|
+
|
|
15
|
+
### Breaking
|
|
16
|
+
- **No deadline of the package's own.** A client deadline closes the socket,
|
|
17
|
+
and SAP then ends the synchronous request running on it — a write in it is
|
|
18
|
+
lost. So:
|
|
19
|
+
- `getTimeout`, `getTimeoutConfig` and `TimeoutConfig` are no longer
|
|
20
|
+
exported (`src/utils/timeouts.ts` is gone), and no `SAP_TIMEOUT_*`
|
|
21
|
+
variable is read;
|
|
22
|
+
- a request carries the caller's `timeout`, unchanged, and nothing else;
|
|
23
|
+
the CSRF fetch and the cloud preflight carry none (they were bounded by
|
|
24
|
+
`SAP_TIMEOUT_CSRF`);
|
|
25
|
+
- inside a critical section a request carries no deadline at all, not even
|
|
26
|
+
the caller's (it was raised to `SAP_TIMEOUT_CRITICAL`, 600 s); the
|
|
27
|
+
critical section itself is unchanged;
|
|
28
|
+
- `GenericWebSocketTransport.connect()` sets no timer unless the caller
|
|
29
|
+
passes `connectTimeoutMs` (the default was 15 s);
|
|
30
|
+
- `IAdtEstablishContext.timeoutMs` is removed.
|
|
31
|
+
- **`IAdtTransport` has two new required members**, `resume(context, session)`
|
|
32
|
+
and `sessionCookies()`. `HttpTransport` and its subclasses implement them;
|
|
33
|
+
`RfcTransport` refuses `resume` and answers `null`. A custom wire adds both.
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
- **An instance on an existing session.** `createConnection({ …, session })`
|
|
37
|
+
(and a sixth constructor argument, `session`, on `AdtOnPremConnector` /
|
|
38
|
+
`AdtCloudConnector`) takes the cookies of a session that already exists.
|
|
39
|
+
`connect()` then does not log on: it makes one request in that session
|
|
40
|
+
without the credential — the CSRF fetch; on cloud with
|
|
41
|
+
`x-sap-security-session: use` — and SAP's answer says whether the session
|
|
42
|
+
is alive. Alive (a token, and the `SAP_SESSIONID` handed over, unchanged):
|
|
43
|
+
the session is the instance's, a stateful request reaches its
|
|
44
|
+
`sap-contextid`, and `disconnect()` logs it off as for any instance. Gone (a
|
|
45
|
+
`401`, or any answer that is not the session's): `connect()` rejects with
|
|
46
|
+
SAP's answer as it is, nothing is logged off, and the instance is spent.
|
|
47
|
+
HTTP wires only: over RFC `session` is refused at construction.
|
|
48
|
+
- **`sessionCookies()`**: the instance's session cookies as the string
|
|
49
|
+
`session` takes — the wire's jar without `sap-XSRF_*`; `null` before a
|
|
50
|
+
session, after it ended, and over RFC. Never logged.
|
|
51
|
+
|
|
52
|
+
## [16.0.0] - 2026-10-13
|
|
53
|
+
|
|
54
|
+
What this package answers for is listed in [docs/SCOPE.md](./docs/SCOPE.md).
|
|
55
|
+
|
|
56
|
+
### Added
|
|
57
|
+
- **`createConnection(spec)`**, the recommended way to build a connection.
|
|
58
|
+
The caller states `system` (`'cloud'` | `'onprem'`) and `transport`
|
|
59
|
+
(`'http'` | `'legacy-http'` | `'rfc'`); the factory builds the matching
|
|
60
|
+
connector and wire:
|
|
61
|
+
- cloud+http → `AdtCloudConnector` + `CloudHttpTransport`;
|
|
62
|
+
- onprem+http → `AdtOnPremConnector` + `OnPremHttpTransport`;
|
|
63
|
+
- onprem+legacy-http → `AdtOnPremConnector` + `LegacyOnPremHttpTransport`;
|
|
64
|
+
- onprem+rfc → `AdtOnPremConnector` + `RfcTransport(rfcConversationFrom(config))`.
|
|
65
|
+
|
|
66
|
+
Nothing is inferred, `config.connectionType` included. Any other
|
|
67
|
+
combination is refused at construction in fixed words. `client` and
|
|
68
|
+
`baseUrl` come from `config`. `agentOptions`, `rfc`, `wireLogger`, `logger`
|
|
69
|
+
and `sessionId` pass through as given. A new instance on every call: one
|
|
70
|
+
instance is one session.
|
|
71
|
+
|
|
72
|
+
### Breaking
|
|
73
|
+
- **The per-request signal is removed** (added in 15.1.0), on
|
|
74
|
+
`@mcp-abap-adt/interfaces-adt-connection` `^3.0.0` (was `^2.1.0`), which
|
|
75
|
+
drops `IAbapRequestOptions.signal`, `ADT_REQUEST_ERROR` and
|
|
76
|
+
`AdtRequestErrorCode`. No request rejects with `ADT_REQUEST_ABORTED`, and
|
|
77
|
+
`IAdtTransportRequest.signal` and `IAdtEstablishContext.signal` are gone
|
|
78
|
+
from the transport seam. Requests behave as in 15.0.1. Measured on an on-premise system
|
|
79
|
+
(BASIS 816, 2026-10-12): ABAP neither cancels a request that reached it nor
|
|
80
|
+
rolls back across requests, a connection is never shared between threads,
|
|
81
|
+
and a logoff releases the locks — so the signal protected nothing.
|
|
82
|
+
- **One connection instance is one SAP session.** After `disconnect()`, after
|
|
83
|
+
a failed `connect()` that received a session cookie (a `SAP_SESSIONID_*`;
|
|
84
|
+
over RFC, an open conversation) — whether or not a logoff was sent for it —,
|
|
85
|
+
or after
|
|
86
|
+
a lost session (`ADT_SESSION_REPLACED`, detected and raised exactly as in
|
|
87
|
+
15.0.1), the instance is spent. On a spent instance, `connect()` rejects
|
|
88
|
+
with `ADT_SESSION_ERROR.NOT_CONNECTED` in fixed words, telling the caller to
|
|
89
|
+
create a new connection, and asks the credential nothing; every request
|
|
90
|
+
rejects `NOT_CONNECTED` too. After a lost session `disconnect()` is still
|
|
91
|
+
owed once, and sends nothing: the loss already cleared the cookies. Every
|
|
92
|
+
establishment attempt checks this, `connect()`'s internal logon retry
|
|
93
|
+
included. A failed `connect()` that received no session cookie (401,
|
|
94
|
+
network, a 200 with only `sap-XSRF_*`) may be retried. A new session is a new instance, created by the
|
|
95
|
+
consumer (its own factory, or `createConnection`). Before 16.0.0 a
|
|
96
|
+
disconnected instance could `connect()` again.
|
|
97
|
+
- **No 401 opens a new session on the same instance, and none is resent
|
|
98
|
+
before the provider is asked.** Three recoveries are removed:
|
|
99
|
+
- a mutation (POST / PUT / DELETE) refused with a 401 while a CSRF token
|
|
100
|
+
was cached, outside a critical section, discarded the session's cookies
|
|
101
|
+
and token and retried in a new session;
|
|
102
|
+
- a GET refused with a 401 on a wire holding no cookies fetched a CSRF
|
|
103
|
+
token to earn some, opening a session on an empty jar;
|
|
104
|
+
- a GET refused with a 401 while the wire held cookies was resent once with
|
|
105
|
+
them, before the provider was asked.
|
|
106
|
+
|
|
107
|
+
All three now reach the provider like any other 401 (`rejected`); on Ok the
|
|
108
|
+
request is resent once in the same session, and otherwise the caller gets
|
|
109
|
+
`AuthRefusedError` carrying SAP's 401. What stays: the CSRF refetch for a
|
|
110
|
+
403 "CSRF token validation failed" or a 401 to a mutation holding no token
|
|
111
|
+
(cookies kept, one resend), and the provider's re-ask — both in the same
|
|
112
|
+
session. A consumer that wants
|
|
113
|
+
a new session after a 401 creates a new instance.
|
|
114
|
+
- **`disconnect()`, once.**
|
|
115
|
+
- **It resolves once the logoff is WRITTEN**: its bytes handed to the
|
|
116
|
+
socket (the node request's `finish`), or over RFC, once the close call
|
|
117
|
+
has returned. It does not wait for SAP's answer, and it no longer
|
|
118
|
+
returns at once as before.
|
|
119
|
+
- Measured on an on-premise system (2026-10-12): with a long request running in the same
|
|
120
|
+
stateful session, SAP queues the logoff behind it (answered ~96 s later
|
|
121
|
+
through the connector; no answer in six minutes raw from a second
|
|
122
|
+
thread). The lock is still gone afterwards, even when the client was
|
|
123
|
+
killed with the answer pending. A connection dropped without a logoff
|
|
124
|
+
keeps its locks.
|
|
125
|
+
- Checked against this build on an on-premise system (2026-10-13): LOCK, then a long
|
|
126
|
+
where-used in the same stateful session, then `await disconnect()` and
|
|
127
|
+
an immediate process exit. The lock was still held 1 s later and free
|
|
128
|
+
~70 s after the exit, long before the 30-min idle timeout.
|
|
129
|
+
- So a caller about to exit awaits `disconnect()`. No timer bounds the
|
|
130
|
+
write: a server that never takes the bytes holds `disconnect()` until the
|
|
131
|
+
socket fails, and that failure is logged, not thrown.
|
|
132
|
+
- **A second call rejects** with `ADT_SESSION_ERROR.NOT_CONNECTED` in fixed
|
|
133
|
+
words, whether it comes while the first is still writing or after it.
|
|
134
|
+
It used to resolve. The first call is unaffected.
|
|
135
|
+
- **The logoff is sent if and only if the instance holds a live
|
|
136
|
+
`SAP_SESSIONID_*`** it received, whatever the status of the answer that
|
|
137
|
+
brought it. This applies on-prem and on cloud (`HttpTransport.holdsSessionCookie`).
|
|
138
|
+
- A `connect()` that fails as a whole after the server opened a session —
|
|
139
|
+
a cloud preflight's, or a 403/404 after logon, on core discovery and the
|
|
140
|
+
fallback alike — logs that session off, and rejects only once the
|
|
141
|
+
logoff is written.
|
|
142
|
+
- A 404 on core discovery alone is not a failure: the fallback runs in the
|
|
143
|
+
same session.
|
|
144
|
+
- A 401 or a 200 with only `sap-XSRF_*` carries no session, and nothing is
|
|
145
|
+
sent.
|
|
146
|
+
- The on-prem rule used to be "established and holding any cookie".
|
|
147
|
+
- On cloud, a session whose server linked no logoff resource is logged off
|
|
148
|
+
through the platform's ICF logoff (`/sap/public/bc/icf/logoff`), sent
|
|
149
|
+
exactly as on-prem: the session's cookies without `sap-contextid`, no
|
|
150
|
+
session header, the write reported the same way. It used to be left to
|
|
151
|
+
the server's timeout. Measured on a BTP trial with bare HTTP
|
|
152
|
+
(2026-10-13): a preflight answered without a logoff link yet set a live
|
|
153
|
+
`SAP_SESSIONID`; after the ICF logoff the same cookies got `401`, before
|
|
154
|
+
it `200`. A linked logoff resource is used as before.
|
|
155
|
+
- Evidence (on-premise ABAP code and measurement): `CL_HTTP_SERVER_NET->send_response`
|
|
156
|
+
sets `SAP_SESSIONID` only when a security session was created, whatever
|
|
157
|
+
the status, and the ICF logoff ends a session only when that cookie is
|
|
158
|
+
present.
|
|
159
|
+
- **The cookie jar honours deletions.** A `Set-Cookie` with a past `expires`
|
|
160
|
+
or `Max-Age=0` removes the cookie, so a deleted `SAP_SESSIONID` is no
|
|
161
|
+
session. SAP's logoff deletes with a one-character value and
|
|
162
|
+
`expires=Tue, 01-Jan-1980 00:00:01 GMT` (on-premise trace, 2026-10-13). An empty
|
|
163
|
+
`SAP_SESSIONID` names no session either.
|
|
164
|
+
- **The logoff never carries `sap-contextid`**: only `SAP_SESSIONID_*`,
|
|
165
|
+
`sap-usercontext` and the affinity it needs (`HttpTransport.logoffCookies`).
|
|
166
|
+
Measured on an on-premise system with bare HTTP (2026-10-13):
|
|
167
|
+
- A logoff without the context cookie ended the context and released its
|
|
168
|
+
lock.
|
|
169
|
+
- A logoff carrying a stale (deleted) `sap-contextid` got 400 and closed
|
|
170
|
+
nothing.
|
|
171
|
+
- **The logoff goes out on a connection of its own** (`agent: false` over
|
|
172
|
+
plain HTTP; the wire's TLS agent or a proxy's is kept). A 3xx answering it
|
|
173
|
+
is its answer: it is not followed and not logged as a failure.
|
|
174
|
+
- **`flushGoodbye(timeoutMs?)` has no default bound.** Without an argument it
|
|
175
|
+
waits for SAP's answer to the logoff for as long as it takes, and creates
|
|
176
|
+
no timer; the library's own 5 s default is gone. With `timeoutMs` it waits
|
|
177
|
+
at most that long and returns without throwing, as before.
|
|
178
|
+
- **`IAdtTransport.close(context, written?)`**: a wire calls `written` once
|
|
179
|
+
its goodbye has left; `disconnect()` resolves at the first of that and the
|
|
180
|
+
close settling. A custom wire whose close stays pending after its goodbye
|
|
181
|
+
has left should call it.
|
|
182
|
+
- **Over RFC the close waits for a running call**: sap-rfc-lite 0.2.2's
|
|
183
|
+
`close()` takes the invocation mutex a call holds until it returns.
|
|
184
|
+
See [MIGRATION-16.0.md](./docs/MIGRATION-16.0.md).
|
|
185
|
+
|
|
186
|
+
### Changed
|
|
187
|
+
- `docs/SCOPE.md` lists what this package answers for; CLAUDE.md points to it.
|
|
188
|
+
- Docs: README (Quick Start starts with `createConnection`), USAGE,
|
|
189
|
+
STATEFUL_SESSION_GUIDE, CLAUDE.md.
|
|
190
|
+
- Tests: "nothing is left unhandled" is proven under plain node
|
|
191
|
+
(`src/__tests__/helpers/plainNode`), where the real process reports it —
|
|
192
|
+
Jest's sandboxed `process` never does; `dispatchedGoodbye` runs there.
|
|
193
|
+
|
|
10
194
|
## [15.1.0] - 2026-10-12
|
|
11
195
|
|
|
12
196
|
### Added
|
|
@@ -2446,7 +2630,9 @@ const connection = createAbapConnection(config, logger);
|
|
|
2446
2630
|
- JWT token refresh now properly handles connection errors (401/403 during initial connect)
|
|
2447
2631
|
- Permission errors (403 with "ExceptionResourceNoAccess") no longer trigger JWT refresh loops
|
|
2448
2632
|
- Proper separation: base class handles HTTP/session, concrete classes handle auth-specific errors
|
|
2449
|
-
[Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/
|
|
2633
|
+
[Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v17.0.0...HEAD
|
|
2634
|
+
[17.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v16.0.0...v17.0.0
|
|
2635
|
+
[16.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v15.1.0...v16.0.0
|
|
2450
2636
|
[15.1.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v15.0.1...v15.1.0
|
|
2451
2637
|
[15.0.1]: https://github.com/fr0ster/mcp-abap-connection/compare/v15.0.0...v15.0.1
|
|
2452
2638
|
[15.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v14.1.0...v15.0.0
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ ABAP connection layer for MCP ABAP ADT server. Provides a unified interface for
|
|
|
25
25
|
- Reusable for debugger/traces and other event-driven flows
|
|
26
26
|
- 📝 **Custom Logging**: Pluggable logger interface for integration with any logging system
|
|
27
27
|
- 📦 **TypeScript**: Full TypeScript support with type definitions included
|
|
28
|
-
-
|
|
28
|
+
- ⏱️ **No built-in deadline**: a request carries the caller's own `timeout` and nothing else — inside a critical section, none at all
|
|
29
29
|
|
|
30
30
|
## Architecture
|
|
31
31
|
|
|
@@ -48,7 +48,8 @@ The package uses a clean separation of concerns:
|
|
|
48
48
|
- **`AdtCloudConnector`** (concrete, exported):
|
|
49
49
|
- An ABAP Cloud system: a session is a resource, opened at
|
|
50
50
|
`/sap/bc/adt/core/http/sessions` and given back through the logoff resource its answer
|
|
51
|
-
links to
|
|
51
|
+
links to, or the platform's ICF logoff when it links none (a `DELETE` on the
|
|
52
|
+
session's own address answers `200` and ends nothing)
|
|
52
53
|
- Takes an auth provider, same as above
|
|
53
54
|
|
|
54
55
|
**Which one you take is how you say where you are dialling.** Nothing is probed:
|
|
@@ -62,7 +63,7 @@ The package uses a clean separation of concerns:
|
|
|
62
63
|
what kind of provider it was given; it calls the same four methods on all of
|
|
63
64
|
them: `prepare` once before the wire opens, `establish` at each logon,
|
|
64
65
|
`authorize` before every attempt, `rejected` when the system refused
|
|
65
|
-
- A `401` that survives the wire's own
|
|
66
|
+
- A `401` that survives the wire's own CSRF recovery, or a refused logon, is
|
|
66
67
|
put to the provider through `rejected`. If it answers Ok (a renewed token, say)
|
|
67
68
|
the request gets exactly one more attempt; if it says no, or the retry is
|
|
68
69
|
refused too, you get an `AuthRefusedError` carrying the provider's refusal —
|
|
@@ -160,6 +161,8 @@ the packages above. See [Migration to 9.0.0](./docs/MIGRATION-9.0.md).
|
|
|
160
161
|
|
|
161
162
|
- 📦 **[Installation Guide](./docs/INSTALLATION.md)** - Setup and installation instructions
|
|
162
163
|
- 📚 **[Usage Guide](./docs/USAGE.md)** - Detailed usage examples and API documentation
|
|
164
|
+
- 🚚 **[Migration to 17.0.0](./docs/MIGRATION-17.0.md)** - no deadline of the package's own: `getTimeout`, `getTimeoutConfig` and `SAP_TIMEOUT_*` are gone, and a request inside a critical section carries none at all; an instance can be built on an existing session (`session`, `sessionCookies()`)
|
|
165
|
+
- 🚚 **[Migration to 16.0.0](./docs/MIGRATION-16.0.md)** - the per-request `signal` (15.1.0) and `ADT_REQUEST_ABORTED` are removed; `disconnect()` resolves once the logoff is written, not answered — a process about to exit awaits it; `flushGoodbye()` when the answer matters
|
|
163
166
|
- 🚚 **[Migration to 15.0.0](./docs/MIGRATION-15.0.md)** - on `@mcp-abap-adt/interfaces-adt-connection` 2: `makeAdtRequest`'s answer is `unknown` unless its type is named; nothing changes at run time
|
|
164
167
|
- 🚚 **[Migration to 14.0.0](./docs/MIGRATION-14.0.md)** - the `sap-abap-auth` CLI is removed, with its `open` and `commander` dependencies; use `@mcp-abap-adt/auth-broker-cli`; the library's API is unchanged
|
|
165
168
|
- 🚚 **[Migration to 13.0.0](./docs/MIGRATION-13.0.md)** - interfaces-auth 7 and auth-errors 2, and the providers from auth-providers 6.0.0; no behaviour change, one interfaces-auth major per process
|
|
@@ -179,7 +182,7 @@ the packages above. See [Migration to 9.0.0](./docs/MIGRATION-9.0.md).
|
|
|
179
182
|
- 💾 **Session Management**: Session headers management (cookies, CSRF tokens) for HTTP communication
|
|
180
183
|
- 📝 **Custom Logging**: Pluggable logger interface for integration with any logging system (optional)
|
|
181
184
|
- 📦 **TypeScript**: Full TypeScript support with type definitions included
|
|
182
|
-
-
|
|
185
|
+
- ⏱️ **No built-in deadline**: a request carries the caller's own `timeout` and nothing else — inside a critical section, none at all
|
|
183
186
|
- 🌐 **Network Error Detection**: Automatic detection and proper handling of network-level errors (connection refused, timeout, DNS failures)
|
|
184
187
|
|
|
185
188
|
## Installation
|
|
@@ -220,14 +223,118 @@ For detailed installation instructions, see [Installation Guide](./docs/INSTALLA
|
|
|
220
223
|
|
|
221
224
|
## Quick Start
|
|
222
225
|
|
|
223
|
-
###
|
|
226
|
+
### The recommended way: `createConnection`
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { createConnection } from "@mcp-abap-adt/connection";
|
|
230
|
+
import type { SapConfig } from "@mcp-abap-adt/connection";
|
|
231
|
+
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
|
|
232
|
+
|
|
233
|
+
const config: SapConfig = {
|
|
234
|
+
url: "https://your-sap-system.com",
|
|
235
|
+
client: "100",
|
|
236
|
+
authType: "basic",
|
|
237
|
+
username: "your-username",
|
|
238
|
+
password: "your-password",
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// Which system, and which wire: both stated, never inferred.
|
|
242
|
+
// cloud + http → AdtCloudConnector + CloudHttpTransport
|
|
243
|
+
// onprem + http → AdtOnPremConnector + OnPremHttpTransport
|
|
244
|
+
// onprem + legacy-http → AdtOnPremConnector + LegacyOnPremHttpTransport (BASIS 7.40)
|
|
245
|
+
// onprem + rfc → AdtOnPremConnector + RfcTransport
|
|
246
|
+
const connection = createConnection({
|
|
247
|
+
system: "onprem",
|
|
248
|
+
transport: "http",
|
|
249
|
+
config,
|
|
250
|
+
credential: new BasicAuthProvider(config.username!, config.password!),
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
await connection.connect();
|
|
254
|
+
try {
|
|
255
|
+
await connection.makeAdtRequest({
|
|
256
|
+
method: "GET",
|
|
257
|
+
url: "/sap/bc/adt/discovery",
|
|
258
|
+
timeout: 0,
|
|
259
|
+
});
|
|
260
|
+
} finally {
|
|
261
|
+
await connection.disconnect(); // resolves once the logoff is written
|
|
262
|
+
}
|
|
263
|
+
// One instance is one SAP session: a new session is a new createConnection().
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
`createConnection` returns a **new instance on every call**. Any other
|
|
267
|
+
combination of system and wire (cloud over RFC, say) is refused at
|
|
268
|
+
construction. The transport options are passed through as you give them:
|
|
269
|
+
`agentOptions` for the HTTP wires, `rfc` for the RFC wire, `wireLogger` for
|
|
270
|
+
what the wire logs about itself, `logger` and `sessionId` for the connection.
|
|
271
|
+
The constructors below remain available; the factory only names the four
|
|
272
|
+
combinations that exist.
|
|
273
|
+
|
|
274
|
+
**No deadline but yours.** A request carries the `timeout` you pass and
|
|
275
|
+
nothing else: no wire sets one of its own, because a client deadline closes
|
|
276
|
+
the socket and SAP then ends the request running on it — a write in it lost.
|
|
277
|
+
`IAbapRequestOptions` still requires the field; `0` is none over HTTP. Inside
|
|
278
|
+
a critical section (`beginCriticalSection()`) a request carries none at all,
|
|
279
|
+
not even yours.
|
|
280
|
+
|
|
281
|
+
### An instance on an existing session
|
|
282
|
+
|
|
283
|
+
An instance may be built on a session that already exists, instead of logging
|
|
284
|
+
on: `session` takes the cookies an earlier instance's `sessionCookies()`
|
|
285
|
+
returned. `connect()` then sends no logon. It makes one request in that
|
|
286
|
+
session **without the credential** — so a session that is gone cannot quietly
|
|
287
|
+
become a new one — and SAP's answer says whether the session is alive: if it
|
|
288
|
+
is, the instance is on it (a stateful request reaches the same ABAP context,
|
|
289
|
+
and `disconnect()` logs it off); if not, `connect()` rejects with SAP's answer
|
|
290
|
+
as it is (a `401`), nothing is logged off, and the instance is spent. HTTP
|
|
291
|
+
wires only; over RFC `session` is refused at construction.
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { createConnection } from "@mcp-abap-adt/connection";
|
|
295
|
+
import type { SapConfig } from "@mcp-abap-adt/connection";
|
|
296
|
+
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
|
|
297
|
+
|
|
298
|
+
const system: SapConfig = {
|
|
299
|
+
url: "https://your-sap-system.com",
|
|
300
|
+
client: "100",
|
|
301
|
+
authType: "basic",
|
|
302
|
+
username: "your-username",
|
|
303
|
+
password: "your-password",
|
|
304
|
+
};
|
|
305
|
+
const credential = new BasicAuthProvider(system.username!, system.password!);
|
|
306
|
+
|
|
307
|
+
const first = createConnection({ system: "onprem", transport: "http", config: system, credential });
|
|
308
|
+
await first.connect();
|
|
309
|
+
// The session's cookies, for you to keep — they act as the user while the
|
|
310
|
+
// session lives, so keep them as a secret. null before a session, and over RFC.
|
|
311
|
+
const kept = first.sessionCookies();
|
|
312
|
+
|
|
313
|
+
// Later — another process, say: the same SAP session, no new logon.
|
|
314
|
+
if (kept !== null) {
|
|
315
|
+
const resumed = createConnection({
|
|
316
|
+
system: "onprem",
|
|
317
|
+
transport: "http",
|
|
318
|
+
config: system,
|
|
319
|
+
credential,
|
|
320
|
+
session: kept,
|
|
321
|
+
});
|
|
322
|
+
await resumed.connect(); // rejects with SAP's 401 when the session is gone
|
|
323
|
+
try {
|
|
324
|
+
await resumed.makeAdtRequest({ method: "GET", url: "/sap/bc/adt/discovery", timeout: 0 });
|
|
325
|
+
} finally {
|
|
326
|
+
await resumed.disconnect(); // logs the session off, as for any instance
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Basic Usage (On-Premise), with the constructors
|
|
224
332
|
|
|
225
333
|
```typescript
|
|
226
334
|
import {
|
|
227
335
|
AdtOnPremConnector,
|
|
228
336
|
OnPremHttpTransport,
|
|
229
337
|
SapConfig,
|
|
230
|
-
getTimeout,
|
|
231
338
|
} from "@mcp-abap-adt/connection";
|
|
232
339
|
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
|
|
233
340
|
|
|
@@ -264,7 +371,7 @@ await connection.connect(); // required before any request
|
|
|
264
371
|
const response = await connection.makeAdtRequest({
|
|
265
372
|
method: "GET",
|
|
266
373
|
url: "/sap/bc/adt/programs/programs/your-program",
|
|
267
|
-
timeout:
|
|
374
|
+
timeout: 0,
|
|
268
375
|
});
|
|
269
376
|
```
|
|
270
377
|
|
|
@@ -287,7 +394,6 @@ import {
|
|
|
287
394
|
AdtCloudConnector,
|
|
288
395
|
CloudHttpTransport,
|
|
289
396
|
SapConfig,
|
|
290
|
-
getTimeout,
|
|
291
397
|
} from "@mcp-abap-adt/connection";
|
|
292
398
|
import { TokenAuthProvider } from "@mcp-abap-adt/auth-providers";
|
|
293
399
|
|
|
@@ -325,7 +431,7 @@ await connection.connect();
|
|
|
325
431
|
const response = await connection.makeAdtRequest({
|
|
326
432
|
method: "GET",
|
|
327
433
|
url: "/sap/bc/adt/programs/programs/your-program",
|
|
328
|
-
timeout:
|
|
434
|
+
timeout: 0,
|
|
329
435
|
});
|
|
330
436
|
```
|
|
331
437
|
|
|
@@ -383,7 +489,6 @@ import {
|
|
|
383
489
|
AdtOnPremConnector,
|
|
384
490
|
OnPremHttpTransport,
|
|
385
491
|
SapConfig,
|
|
386
|
-
getTimeout,
|
|
387
492
|
} from "@mcp-abap-adt/connection";
|
|
388
493
|
import { SamlAuthProvider } from "@mcp-abap-adt/auth-providers";
|
|
389
494
|
|
|
@@ -408,7 +513,7 @@ await connection.connect();
|
|
|
408
513
|
const response = await connection.makeAdtRequest({
|
|
409
514
|
method: "GET",
|
|
410
515
|
url: "/sap/bc/adt/programs/programs/your-program",
|
|
411
|
-
timeout:
|
|
516
|
+
timeout: 0,
|
|
412
517
|
});
|
|
413
518
|
```
|
|
414
519
|
|
|
@@ -425,7 +530,6 @@ import {
|
|
|
425
530
|
AdtCloudConnector,
|
|
426
531
|
CloudHttpTransport,
|
|
427
532
|
SapConfig,
|
|
428
|
-
getTimeout,
|
|
429
533
|
} from "@mcp-abap-adt/connection";
|
|
430
534
|
import { TokenAuthProvider } from "@mcp-abap-adt/auth-providers";
|
|
431
535
|
import type { ITokenRefresher } from "@mcp-abap-adt/interfaces-auth";
|
|
@@ -462,14 +566,13 @@ await connection.connect();
|
|
|
462
566
|
// AuthRefusedError. The resend always runs under the same lease and generation
|
|
463
567
|
// as the attempt it repeats, so stale-request fencing applies. After a rejection
|
|
464
568
|
// at 'request' it goes out on the same session; after one at 'logon' the wire
|
|
465
|
-
// logs on again first.
|
|
466
|
-
// or
|
|
467
|
-
//
|
|
468
|
-
// stale-session recovery first, which starts a new session.
|
|
569
|
+
// logs on again first. No 401 opens a new session: the resend stays in this
|
|
570
|
+
// one, or fails with SESSION_REPLACED if SAP replaced it. For a new session,
|
|
571
|
+
// create a new connection.
|
|
469
572
|
const response = await connection.makeAdtRequest({
|
|
470
573
|
method: "GET",
|
|
471
574
|
url: "/sap/bc/adt/programs/programs/your-program",
|
|
472
|
-
timeout:
|
|
575
|
+
timeout: 0,
|
|
473
576
|
});
|
|
474
577
|
```
|
|
475
578
|
|
|
@@ -488,7 +591,7 @@ See [MIGRATION-4.0.md](./docs/MIGRATION-4.0.md).
|
|
|
488
591
|
### When the credential is refused
|
|
489
592
|
|
|
490
593
|
Every request asks the provider first (`authorize`). A `401` that survives the
|
|
491
|
-
wire's own
|
|
594
|
+
wire's own CSRF recovery (in the same session), or a logon the system refused, is put to the
|
|
492
595
|
provider (`rejected`); on Ok the request is sent once more, otherwise it fails
|
|
493
596
|
with an `AuthRefusedError` carrying the provider's refusal. A `403` is never
|
|
494
597
|
put to the provider. The refusal is an `IAuthProviderError`: decide on its
|
|
@@ -547,7 +650,6 @@ cookies and the CSRF token remain available in both modes. See the
|
|
|
547
650
|
import {
|
|
548
651
|
AdtOnPremConnector,
|
|
549
652
|
OnPremHttpTransport,
|
|
550
|
-
getTimeout,
|
|
551
653
|
} from "@mcp-abap-adt/connection";
|
|
552
654
|
import { BasicAuthProvider } from "@mcp-abap-adt/auth-providers";
|
|
553
655
|
|
|
@@ -664,7 +766,7 @@ by address, which is an empty mechanism, not an absent lifecycle:
|
|
|
664
766
|
|
|
665
767
|
```typescript
|
|
666
768
|
// ISessionLifecycleAware
|
|
667
|
-
disconnect(): Promise<void>; //
|
|
769
|
+
disconnect(): Promise<void>; // resolves once the logoff is written; call it once (a second call rejects)
|
|
668
770
|
isConnected(): boolean;
|
|
669
771
|
getSessionIdentity(): string | null; // WHICH SAP session; null is not "disconnected"
|
|
670
772
|
```
|
|
@@ -675,26 +777,16 @@ contract type re-exported under a second name is a contract type that can drift.
|
|
|
675
777
|
**The connection does not track locks.** Deciding when to disconnect, and
|
|
676
778
|
preparing for it, belongs to the caller; pairing every LOCK with its UNLOCK
|
|
677
779
|
belongs to `@mcp-abap-adt/adt-clients`, which holds the handles. What this layer
|
|
678
|
-
owns is not being interrupted by a
|
|
679
|
-
`beginCriticalSection()`
|
|
780
|
+
owns is not being interrupted by a deadline mid-operation: inside
|
|
781
|
+
`beginCriticalSection()` a request carries none, not even the caller's.
|
|
680
782
|
|
|
681
783
|
See [docs/USAGE.md — Session Lifecycle](./docs/USAGE.md#session-lifecycle).
|
|
682
784
|
|
|
683
|
-
**Cancelling a request.** `makeAdtRequest({ …, signal })` takes the caller's
|
|
684
|
-
`AbortSignal`. Once it aborts, nothing more of the request is sent — not the
|
|
685
|
-
first send, not a resend, not the CSRF recovery, not a renewal — and the call
|
|
686
|
-
rejects at once with `code: 'ADT_REQUEST_ABORTED'` (`ADT_REQUEST_ERROR.ABORTED`
|
|
687
|
-
from `@mcp-abap-adt/interfaces-adt-connection`), over HTTP and RFC alike. A
|
|
688
|
-
request already sent is not recalled, and a provider's renewal it was waiting
|
|
689
|
-
on runs on for the other requests. A token exchange the request started makes
|
|
690
|
-
no further attempt; the one already on the wire is not recalled, and the token
|
|
691
|
-
it earns is the session's. See
|
|
692
|
-
[docs/USAGE.md — Cancelling a request](./docs/USAGE.md#cancelling-a-request).
|
|
693
|
-
|
|
694
785
|
**Session Management:**
|
|
695
786
|
- `setSessionType(type)`: Programmatically switch between stateful and stateless modes *(on the contract)*
|
|
696
787
|
- `getSessionId()`: Returns the client-side conversation id, an auto-generated UUID *(on the contract)*
|
|
697
788
|
- `getSessionMode()`: Returns current session mode *(HTTP classes only)*
|
|
789
|
+
- `sessionCookies()`: The cookies of the instance's SAP session, as `createConnection({ …, session })` takes them — `null` before a session, after it ended, and over RFC. They act as the user while the session lives: keep them as a secret; the package never logs them *(this package's connectors)*
|
|
698
790
|
|
|
699
791
|
#### `ILogger`
|
|
700
792
|
|
|
@@ -711,6 +803,18 @@ interface ILogger {
|
|
|
711
803
|
|
|
712
804
|
### Functions
|
|
713
805
|
|
|
806
|
+
#### `createConnection(spec)`
|
|
807
|
+
|
|
808
|
+
Builds a NEW connection from what the caller states: `system` (`'cloud'` or
|
|
809
|
+
`'onprem'`) and `transport` (`'http'`, `'legacy-http'` or `'rfc'`), plus
|
|
810
|
+
`config`, `credential` and, optionally, `logger`, `wireLogger`, `sessionId`,
|
|
811
|
+
`agentOptions` and `session` (HTTP) or `rfc` (`IRfcTransportOptions`). Nothing is inferred,
|
|
812
|
+
not even from `config.connectionType`. A combination that does not exist is
|
|
813
|
+
refused with a `TypeError`, and so is `session` over RFC. One instance is one
|
|
814
|
+
SAP session: call it again for a new one — or pass `session` (the string an
|
|
815
|
+
instance's `sessionCookies()` returned) to build it on an existing session,
|
|
816
|
+
which `connect()` then takes over instead of logging on.
|
|
817
|
+
|
|
714
818
|
#### `rfcConversationFrom(config)`
|
|
715
819
|
|
|
716
820
|
What `RfcTransport` is constructed with. Derives `ashost` from the url and
|