@mcp-abap-adt/connection 15.0.1 → 16.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.
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Build a connection: the connector for the system, and the wire it travels
3
+ * over — both stated by the caller.
4
+ *
5
+ * Choosing the wire is the part consumers get wrong, so the four combinations
6
+ * that exist are named here once. Nothing is inferred: not from the config,
7
+ * not from the host name, not from `SapConfig.connectionType`. Taking a
8
+ * system and a transport is the caller stating which system it is dialling
9
+ * and what it travels over — the rule the connectors themselves follow.
10
+ *
11
+ * **A new instance on every call.** One connection instance is one SAP
12
+ * session: after its `disconnect()` (or a logoff of its own) it is spent, and
13
+ * a new session is a new call to this.
14
+ *
15
+ * Every transport option is passed through as the caller gives it; what is
16
+ * not given takes the constructor's own default, nothing more.
17
+ */
18
+ import type { AgentOptions } from 'node:https';
19
+ import type { IAuthProvider } from '@mcp-abap-adt/interfaces-auth';
20
+ import type { SapConfig } from '../config/sapConfig.js';
21
+ import type { ILogger } from '../logger.js';
22
+ import { AdtCloudConnector } from './AdtCloudConnector.js';
23
+ import { AdtOnPremConnector } from './AdtOnPremConnector.js';
24
+ import { CloudHttpTransport } from './CloudHttpTransport.js';
25
+ import { LegacyOnPremHttpTransport } from './LegacyOnPremHttpTransport.js';
26
+ import { OnPremHttpTransport } from './OnPremHttpTransport.js';
27
+ import { type IRfcTransportOptions, RfcTransport } from './RfcTransport.js';
28
+ /** What every combination takes. */
29
+ interface ConnectionSpecBase<TCredential extends IAuthProvider> {
30
+ /** The system: its URL, client and, over RFC, what the conversation needs. */
31
+ config: SapConfig;
32
+ /** The credential, handed to the connector as it is. */
33
+ credential: TCredential;
34
+ /** The connection's logger. Absent: none. */
35
+ logger?: ILogger | null | undefined;
36
+ /**
37
+ * The wire's own logger — what it logs about carrying requests. Absent:
38
+ * none, as the transport constructors default. Separate from `logger` so a
39
+ * caller can keep the wire quiet, or route it elsewhere.
40
+ */
41
+ wireLogger?: ILogger | null | undefined;
42
+ /** The client-side conversation id. Absent: a generated one. */
43
+ sessionId?: string | undefined;
44
+ }
45
+ /** What the HTTP wires take besides. */
46
+ interface HttpWireOptions {
47
+ /**
48
+ * The HTTPS agent's options — `ca`, `rejectUnauthorized` and the like, not
49
+ * the credential (its TLS material arrives at logon). Absent: none.
50
+ */
51
+ agentOptions?: (() => AgentOptions) | undefined;
52
+ }
53
+ export interface CloudHttpSpec<TCredential extends IAuthProvider = IAuthProvider> extends ConnectionSpecBase<TCredential>, HttpWireOptions {
54
+ system: 'cloud';
55
+ transport: 'http';
56
+ }
57
+ export interface OnPremHttpSpec<TCredential extends IAuthProvider = IAuthProvider> extends ConnectionSpecBase<TCredential>, HttpWireOptions {
58
+ system: 'onprem';
59
+ /** `legacy-http`: BASIS 7.40, where the stateful header must not be sent. */
60
+ transport: 'http' | 'legacy-http';
61
+ }
62
+ export interface OnPremRfcSpec<TCredential extends IAuthProvider = IAuthProvider> extends ConnectionSpecBase<TCredential> {
63
+ system: 'onprem';
64
+ transport: 'rfc';
65
+ /** The RFC wire's own options (`logWire`, `maxLoggedBodyChars`). */
66
+ rfc?: IRfcTransportOptions | undefined;
67
+ }
68
+ export type ConnectionSpec<TCredential extends IAuthProvider = IAuthProvider> = CloudHttpSpec<TCredential> | OnPremHttpSpec<TCredential> | OnPremRfcSpec<TCredential>;
69
+ /**
70
+ * What `createConnection` returns: one of the four connections that exist. A
71
+ * caller that needs the exact wire in the type narrows it (`instanceof`), or
72
+ * builds the connection with the constructors, which keep both in the type.
73
+ */
74
+ export type CreatedConnection<TCredential extends IAuthProvider = IAuthProvider> = AdtCloudConnector<TCredential, CloudHttpTransport> | AdtOnPremConnector<TCredential, OnPremHttpTransport | LegacyOnPremHttpTransport | RfcTransport>;
75
+ export declare function createConnection<TCredential extends IAuthProvider>(spec: ConnectionSpec<TCredential>): CreatedConnection<TCredential>;
76
+ export {};
77
+ //# sourceMappingURL=createConnection.d.ts.map
@@ -0,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jD,SAAQ,kBAAkB,CAAC,WAAW,CAAC,EACrC,eAAe;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc,CAC7B,WAAW,SAAS,aAAa,GAAG,aAAa,CACjD,SAAQ,kBAAkB,CAAC,WAAW,CAAC,EACrC,eAAe;IACjB,MAAM,EAAE,QAAQ,CAAC;IACjB,6EAA6E;IAC7E,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC;CACnC;AAED,MAAM,WAAW,aAAa,CAC5B,WAAW,SAAS,aAAa,GAAG,aAAa,CACjD,SAAQ,kBAAkB,CAAC,WAAW,CAAC;IACvC,MAAM,EAAE,QAAQ,CAAC;IACjB,SAAS,EAAE,KAAK,CAAC;IACjB,oEAAoE;IACpE,GAAG,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC;CACxC;AAED,MAAM,MAAM,cAAc,CAAC,WAAW,SAAS,aAAa,GAAG,aAAa,IACxE,aAAa,CAAC,WAAW,CAAC,GAC1B,cAAc,CAAC,WAAW,CAAC,GAC3B,aAAa,CAAC,WAAW,CAAC,CAAC;AAQ/B;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAC3B,WAAW,SAAS,aAAa,GAAG,aAAa,IAE/C,iBAAiB,CAAC,WAAW,EAAE,kBAAkB,CAAC,GAClD,kBAAkB,CAChB,WAAW,EACX,mBAAmB,GAAG,yBAAyB,GAAG,YAAY,CAC/D,CAAC;AAEN,wBAAgB,gBAAgB,CAAC,WAAW,SAAS,aAAa,EAChE,IAAI,EAAE,cAAc,CAAC,WAAW,CAAC,GAChC,iBAAiB,CAAC,WAAW,CAAC,CAkDhC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConnection = createConnection;
4
+ const AdtCloudConnector_js_1 = require("./AdtCloudConnector.js");
5
+ const AdtOnPremConnector_js_1 = require("./AdtOnPremConnector.js");
6
+ const CloudHttpTransport_js_1 = require("./CloudHttpTransport.js");
7
+ const LegacyOnPremHttpTransport_js_1 = require("./LegacyOnPremHttpTransport.js");
8
+ const OnPremHttpTransport_js_1 = require("./OnPremHttpTransport.js");
9
+ const RfcTransport_js_1 = require("./RfcTransport.js");
10
+ const rfcConversation_js_1 = require("./rfcConversation.js");
11
+ /** Whatever a caller passed, read as the two words that pick the wire. */
12
+ function stated(spec) {
13
+ const record = (spec ?? {});
14
+ return { system: record.system, transport: record.transport };
15
+ }
16
+ function createConnection(spec) {
17
+ const { system, transport } = stated(spec);
18
+ const logger = spec.logger ?? null;
19
+ const wireLogger = spec.wireLogger ?? null;
20
+ const address = { client: spec.config.client, baseUrl: spec.config.url };
21
+ if (system === 'cloud' && transport === 'http') {
22
+ const http = spec;
23
+ return new AdtCloudConnector_js_1.AdtCloudConnector(spec.config, spec.credential, new CloudHttpTransport_js_1.CloudHttpTransport(http.agentOptions, wireLogger, address), logger, spec.sessionId);
24
+ }
25
+ if (system === 'onprem' && transport === 'http') {
26
+ const http = spec;
27
+ return new AdtOnPremConnector_js_1.AdtOnPremConnector(spec.config, spec.credential, new OnPremHttpTransport_js_1.OnPremHttpTransport(http.agentOptions, wireLogger, address), logger, spec.sessionId);
28
+ }
29
+ if (system === 'onprem' && transport === 'legacy-http') {
30
+ const http = spec;
31
+ return new AdtOnPremConnector_js_1.AdtOnPremConnector(spec.config, spec.credential, new LegacyOnPremHttpTransport_js_1.LegacyOnPremHttpTransport(http.agentOptions, wireLogger, address), logger, spec.sessionId);
32
+ }
33
+ if (system === 'onprem' && transport === 'rfc') {
34
+ const rfc = spec;
35
+ return new AdtOnPremConnector_js_1.AdtOnPremConnector(spec.config, spec.credential, new RfcTransport_js_1.RfcTransport((0, rfcConversation_js_1.rfcConversationFrom)(spec.config), wireLogger, rfc.rfc), logger, spec.sessionId);
36
+ }
37
+ // Fixed words: nothing the caller passed is echoed back.
38
+ throw new TypeError("createConnection: no such combination of system and transport. ABAP Cloud has one wire, 'http'; on-prem takes 'http', 'legacy-http' or 'rfc'. Both are stated by the caller, never inferred.");
39
+ }
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { AdtCloudConnector } from './connection/AdtCloudConnector.js';
6
6
  export { AdtOnPremConnector } from './connection/AdtOnPremConnector.js';
7
7
  export { type AuthRefusalMoment, AuthRefusedError, WireLogonError, } from './connection/authErrors.js';
8
8
  export { CloudHttpTransport } from './connection/CloudHttpTransport.js';
9
+ export { type CloudHttpSpec, type ConnectionSpec, type CreatedConnection, createConnection, type OnPremHttpSpec, type OnPremRfcSpec, } from './connection/createConnection.js';
9
10
  export { CSRF_CONFIG, CSRF_ERROR_MESSAGES } from './connection/csrfConfig.js';
10
11
  export { GenericWebSocketTransport, type IWebSocketFactory, type IWebSocketLike, } from './connection/GenericWebSocketTransport.js';
11
12
  export { HttpTransport } from './connection/HttpTransport.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAK1C,YAAY,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,YAAY,EACV,cAAc,EACd,kBAAkB,GACnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EACL,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,cAAc,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAQxE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,4BAA4B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AAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAGxE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,kCAAkC,CAAC;AAQ1C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EACL,yBAAyB,EACzB,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,YAAY,GACb,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,KAAK,mBAAmB,EACxB,mBAAmB,EACnB,aAAa,GACd,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,KAAK,aAAa,GACnB,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Types - re-exported from the contract packages, under the names this
3
3
  // package has always published them by.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.getTimeoutConfig = exports.getTimeout = exports.rfcParamsFrom = exports.rfcConversationFrom = exports.RfcTransport = exports.OnPremHttpTransport = exports.LegacyOnPremHttpTransport = exports.HttpTransport = exports.GenericWebSocketTransport = exports.CSRF_ERROR_MESSAGES = exports.CSRF_CONFIG = exports.CloudHttpTransport = exports.WireLogonError = exports.AuthRefusedError = exports.AdtOnPremConnector = exports.AdtCloudConnector = exports.sapConfigSignature = void 0;
5
+ exports.getTimeoutConfig = exports.getTimeout = exports.rfcParamsFrom = exports.rfcConversationFrom = exports.RfcTransport = exports.OnPremHttpTransport = exports.LegacyOnPremHttpTransport = exports.HttpTransport = exports.GenericWebSocketTransport = exports.CSRF_ERROR_MESSAGES = exports.CSRF_CONFIG = exports.createConnection = exports.CloudHttpTransport = exports.WireLogonError = exports.AuthRefusedError = exports.AdtOnPremConnector = exports.AdtCloudConnector = exports.sapConfigSignature = void 0;
6
6
  // Config utilities
7
7
  var sapConfig_js_1 = require("./config/sapConfig.js");
8
8
  Object.defineProperty(exports, "sapConfigSignature", { enumerable: true, get: function () { return sapConfig_js_1.sapConfigSignature; } });
@@ -15,6 +15,10 @@ Object.defineProperty(exports, "AuthRefusedError", { enumerable: true, get: func
15
15
  Object.defineProperty(exports, "WireLogonError", { enumerable: true, get: function () { return authErrors_js_1.WireLogonError; } });
16
16
  var CloudHttpTransport_js_1 = require("./connection/CloudHttpTransport.js");
17
17
  Object.defineProperty(exports, "CloudHttpTransport", { enumerable: true, get: function () { return CloudHttpTransport_js_1.CloudHttpTransport; } });
18
+ // The recommended way to build a connection: the system and the wire stated,
19
+ // a new instance per session.
20
+ var createConnection_js_1 = require("./connection/createConnection.js");
21
+ Object.defineProperty(exports, "createConnection", { enumerable: true, get: function () { return createConnection_js_1.createConnection; } });
18
22
  // The session lifecycle vocabulary — ISessionLifecycleAware, ADT_SESSION_ERROR —
19
23
  // is deliberately NOT exported here. It lives in @mcp-abap-adt/interfaces-adt-connection, and a
20
24
  // consumer imports it from there: re-exporting a contract type gives it two
package/docs/INDEX.md CHANGED
@@ -15,6 +15,7 @@ mcp-abap-connection/
15
15
  │ ├── INSTALLATION.md # Setup and installation guide
16
16
  │ ├── USAGE.md # API documentation and examples
17
17
  │ ├── MIGRATION-2.0.md # Moving to the explicit session lifecycle
18
+ │ ├── MIGRATION-16.0.md # the request signal removed; disconnect() resolves once the logoff is written
18
19
  │ ├── MIGRATION-15.0.md # interfaces-adt-connection 2: makeAdtRequest answers unknown
19
20
  │ ├── MIGRATION-14.0.md # the sap-abap-auth CLI, open and commander are removed
20
21
  │ ├── MIGRATION-13.0.md # interfaces-auth 7, auth-errors 2, auth-providers 6.0.0; no behaviour change
@@ -25,7 +26,7 @@ mcp-abap-connection/
25
26
  │ ├── MIGRATION-8.0.md # request headers leave the stateful branch; onto interfaces 39; flushGoodbye
26
27
  │ ├── MIGRATION-6.0.md # the factory and the per-credential classes go; RFC is a transport
27
28
  │ ├── MIGRATION-4.0.md # JWT error classification: 401 refreshes, 403 propagates
28
- │ ├── SCOPE.md # What this package does and does not own
29
+ │ ├── SCOPE.md # What this package answers for, and only that
29
30
  │ └── STATEFUL_SESSION_GUIDE.md # Stateful requests and lock windows
30
31
  ├── examples/ # Working code examples
31
32
  │ ├── README.md # Examples overview
@@ -43,9 +44,10 @@ mcp-abap-connection/
43
44
  - 📦 [Installation Guide](./INSTALLATION.md) - How to install and set up the package
44
45
  - 📚 [Usage Guide](./USAGE.md) - Basic usage and comprehensive API documentation
45
46
  - 📖 [Main README](../README.md) - Package overview and quick start
46
- - 🧭 [Scope and Boundaries](./SCOPE.md) - What this package does (and does not), sibling packages, and why there is no RFC to cloud
47
+ - 🧭 [Scope](./SCOPE.md) - What this package answers for, and only that
47
48
 
48
49
  ### Upgrading
50
+ - 🚚 [Migrating to 16.0.0](./MIGRATION-16.0.md) - the per-request `signal` and `ADT_REQUEST_ABORTED` are removed; `disconnect()` resolves once the logoff is written; `flushGoodbye()` waits for the answer
49
51
  - 🚚 [Migrating to 15.0.0](./MIGRATION-15.0.md) - on `@mcp-abap-adt/interfaces-adt-connection` 2: `makeAdtRequest`'s answer is `unknown` unless its type is named
50
52
  - 🚚 [Migrating to 14.0.0](./MIGRATION-14.0.md) - the `sap-abap-auth` CLI is removed; use `@mcp-abap-adt/auth-broker-cli`
51
53
  - 🚚 [Migrating to 13.0.0](./MIGRATION-13.0.md) - interfaces-auth 7 and auth-errors 2; the connection's behaviour is unchanged, a consumer holds one interfaces-auth major and takes the providers from auth-providers 6.0.0
@@ -0,0 +1,123 @@
1
+ # Migration to 16.0
2
+
3
+ 16.0.0 makes this package answer for what [SCOPE.md](./SCOPE.md) lists, and for
4
+ nothing else. For a consumer on 15.x that means the following.
5
+
6
+ ## What changed
7
+
8
+ - **`signal` is gone from request options.** This matches
9
+ `@mcp-abap-adt/interfaces-adt-connection` 3.0.0, which drops
10
+ `IAbapRequestOptions.signal`, `ADT_REQUEST_ERROR` and `AdtRequestErrorCode`.
11
+ No request rejects with `ADT_REQUEST_ABORTED` any more. A request behaves as
12
+ it did in 15.0.1: once admitted, it runs to its answer or its `timeout`.
13
+ `IAdtTransportRequest.signal` and `IAdtEstablishContext.signal` are gone
14
+ from the transport seam. Measured on an on-premise system (BASIS 816, 2026-10-12): ABAP
15
+ neither cancels a request that reached it nor rolls back across requests,
16
+ and a logoff releases the locks — so the signal protected nothing.
17
+ - **One connection instance is one SAP session.** The instance is spent after
18
+ `disconnect()`, after a failed `connect()` that received a session cookie
19
+ (a `SAP_SESSIONID_*`; over RFC, an open conversation) — whether or not a
20
+ logoff was sent for it —, or after a lost session: `ADT_SESSION_REPLACED`, raised
21
+ exactly as in 15.0.1 for a changed `SAP_SESSIONID` or a 400 "session not
22
+ found". On a spent instance, `connect()` and every request reject
23
+ `ADT_SESSION_ERROR.NOT_CONNECTED`. The connector decides nothing beyond
24
+ that; what to do next is yours.
25
+ - On a spent instance, `connect()` rejects with
26
+ `ADT_SESSION_ERROR.NOT_CONNECTED`: "This connection's SAP session has
27
+ ended (it was disconnected, logged off or lost); one connection instance is one
28
+ session. Create a new connection for a new session."
29
+ - A failed `connect()` that received no session cookie (a 401, a network
30
+ error, a 200 with only `sap-XSRF_*`) leaves the instance usable, and
31
+ `connect()` may be retried.
32
+ - **No 401 opens a new session on the same instance.** Before 16.0.0, a
33
+ mutation refused with a 401 while a CSRF token was cached (outside a
34
+ critical section) discarded the session and retried in a new one, and a GET
35
+ refused with a 401 on a wire with no cookies fetched a token to open one,
36
+ and a GET refused with a 401 while cookies were held was resent once with
37
+ them before the provider was asked. All three are removed. The 401 goes to the provider (`rejected`); on
38
+ Ok the request is resent once in the same session, otherwise you get
39
+ `AuthRefusedError` carrying SAP's 401. The CSRF refetch for a 403 "CSRF
40
+ token validation failed" (cookies kept) and the provider's re-ask stay.
41
+ - **`disconnect()` resolves once the logoff is written.** It resolves when the
42
+ bytes are handed to the socket over HTTP, or when the close call has
43
+ returned over RFC. It does not wait for SAP's answer. The first call never
44
+ throws: a logoff that fails is logged.
45
+ - **Call it once per instance.** A second call rejects with
46
+ `ADT_SESSION_ERROR.NOT_CONNECTED` ("disconnect() was already called for
47
+ this connection; call it once per instance"), whether it comes while the
48
+ first is still writing or after it. The first call is unaffected.
49
+ - No timer bounds the write. A server that never takes the bytes holds
50
+ `disconnect()` until the socket fails. That failure is logged, not thrown.
51
+ - **"Written" means handed to the operating system.** The logoff goes out
52
+ on a connection of its own over HTTP. Over HTTPS this holds while your
53
+ `agentOptions` leave `keepAlive` off.
54
+ - **Over RFC, the close waits for a call still running on its
55
+ conversation.** In `@mcp-abap-adt/sap-rfc-lite` 0.2.2, a call holds the
56
+ client's invocation mutex until it returns, and `close()` takes the same
57
+ mutex.
58
+ - **When the logoff is sent.** It is sent if and only if the instance holds
59
+ a live `SAP_SESSIONID_*` that it received: not one deleted by a past
60
+ `expires` or `Max-Age=0`.
61
+ - A `connect()` that fails as a whole after the server opened a session (a
62
+ cloud preflight's, or a 403/404 after logon on both discovery endpoints)
63
+ logs it off, and rejects only once the logoff is written.
64
+ - A 404 on core discovery alone is not a failure: the fallback runs in the
65
+ same session.
66
+ - A 401, or a 200 with only `sap-XSRF_*`, has no session, so nothing is
67
+ sent.
68
+ - The logoff never carries `sap-contextid`. Measured on an on-premise system (2026-10-13), a
69
+ logoff carrying a stale one got 400 and closed nothing, while one without
70
+ it ended the context and released its lock.
71
+ - A redirect answering the logoff counts as its answer: it is not
72
+ followed.
73
+ - On cloud, a session the server linked no logoff resource for is logged
74
+ off through the platform's ICF logoff (`/sap/public/bc/icf/logoff`), as
75
+ on-prem, instead of being left to the server's timeout. A linked logoff
76
+ resource is used as before.
77
+ - **`flushGoodbye(timeoutMs?)` has no default bound.** Without an argument it
78
+ waits for SAP's answer to the logoff for as long as it takes. With
79
+ `timeoutMs` it waits at most that long and returns without throwing.
80
+ - **`IAdtTransport.close(context, written?)`**: a wire reports the write by
81
+ calling `written`. `disconnect()` resolves at the first of `written()` and
82
+ the close settling.
83
+
84
+ ## What a consumer must do
85
+
86
+ - **Build connections with `createConnection(spec)`** (recommended). You state
87
+ `system` and `transport` (`cloud`+`http`, or `onprem` with `http`,
88
+ `legacy-http` or `rfc`). The factory builds the matching connector and wire
89
+ and passes your transport options through. It returns a new instance on
90
+ every call. The constructors still work.
91
+ - **Drop `signal`** from the options passed to `makeAdtRequest`, and drop any
92
+ check for `ADT_REQUEST_ERROR` or `'ADT_REQUEST_ABORTED'`.
93
+ - **Call `disconnect()` once.** If more than one path in your code can end a
94
+ connection, such as a `finally` and a signal handler, let one of them own
95
+ the call, or catch the second call's rejection.
96
+ - **A process about to exit awaits `disconnect()`.** Once it resolves, the
97
+ logoff has left:
98
+ ```typescript
99
+ await connection.disconnect();
100
+ process.exit(0);
101
+ ```
102
+ - **A new session is a new instance, and creating it is yours.** Use your
103
+ own factory or `createConnection`. Anywhere you called `connect()` again on
104
+ an instance after `disconnect()`, create a new connection instead.
105
+ - **On a 401, create a new instance if you want a new session.** The
106
+ connection no longer opens one for you. Where you relied on a mutation's
107
+ 401 being retried in a fresh session, catch the `AuthRefusedError` (or the
108
+ `ADT_SESSION_REPLACED` the resend may raise), `disconnect()` the instance,
109
+ and redo the work on a new connection — under a new lock, if it held one.
110
+ - **`flushGoodbye()` no longer gives up after 5 s.** If you need a bound,
111
+ pass one: `flushGoodbye(5000)`.
112
+ - **Await `flushGoodbye()` as well if SAP's answer matters**, for example
113
+ before a new connection connects, so that the server never holds two
114
+ sessions:
115
+ ```typescript
116
+ await connection.disconnect();
117
+ await connection.flushGoodbye();
118
+ const next = createYourConnection();
119
+ await next.connect();
120
+ ```
121
+ - **A custom transport** (`IAdtTransport`) whose `close()` stays pending long
122
+ after its goodbye has left should call the new `written` argument at that
123
+ point. Otherwise `disconnect()` waits for the close to settle.
package/docs/SCOPE.md CHANGED
@@ -1,45 +1,17 @@
1
- # Scope and Boundaries
2
-
3
- This package is **one component of the `@mcp-abap-adt/*` family**. Each package owns one concern; together they form an SAP ABAP tooling stack. Keeping the boundaries clear is important — several features that look natural to add here actually belong in sibling packages, and some that look missing (like RFC-to-cloud) do not exist anywhere in the ecosystem because the underlying technology does not support them.
4
-
5
- ## What this package does
6
-
7
- - **HTTP transport to SAP ADT** — request dispatch, CSRF token fetch, cookie and session handling, stateful/stateless session control.
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
- - **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
- - **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
-
12
- ## What this package does NOT do, and where it lives instead
13
-
14
- | Concern | Belongs in |
15
- |---|---|
16
- | Token acquisition (SAML/OAuth2 flows, browser login, PKCE) | `@mcp-abap-adt/auth-broker` |
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
- | Session state persistence across processes | `@mcp-abap-adt/auth-broker` |
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` |
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.
23
-
24
- ## Why there is no RFC to SAP BTP / cloud
25
-
26
- Short answer: because SAP does not support it that way, and Eclipse ADT does not do it that way either.
27
-
28
- **1. Eclipse ADT talks to cloud over HTTP, not RFC.**
29
- The `com.sap.adt.communication.http.*` package is the only transport Eclipse ADT uses for ADT itself. Cloud login in Eclipse goes through `SamlWithReentranceTicketLogonFacade` → `IcfEndpointBasedSystemUrlInfoProvider` → `HttpLowLevelConnection.sendRequest`. This is an HTTP flow via the ABAP ICF (Internet Communication Framework) endpoint, with a browser SAML login minting a short-lived reentrance ticket, which is then exchanged for a `MYSAPSSO2` session cookie over HTTP. There is no RFC anywhere in this path. JCo/RFC calls that appear in Eclipse logs come from unrelated features (GUI integration, JCo destination tests) — not ADT.
30
-
31
- **2. NW RFC SDK has no JWT or SAML-2.0-XML logon parameter.**
32
- Inspection of `sapnwrfc.h` and the SDK's reference `sapnwrfc.ini` confirms the supported client logon parameters are: `USER`/`PASSWD`, `X509CERT`, `MYSAPSSO2` (accepts SSO2 tickets and SAP-internal "assertion tickets", *not* SAML 2.0 XML assertions), plus SNC (`SNC_QOP`, `SNC_MYNAME`, `SNC_PARTNERNAME`, `SNC_LIB`) for Kerberos/x509 over RFC. For WebSocket-RFC: `WSHOST`/`WSPORT`, `ALIAS_USER`, `TLS_CLIENT_PSE`, `TLS_CLIENT_CERTIFICATE_LOGON`. No `JWT`, no `BEARER`, no `SAML_ASSERTION`, no `OAUTH` keys exist in the SDK headers.
33
-
34
- **3. `@mcp-abap-adt/sap-rfc-lite` is a pure passthrough.**
35
- It forwards every `(name, value)` pair from the JS `Client(params)` object to `RFC_CONNECTION_PARAMETER[]` without filtering. So the wrapper is not a constraint — the constraint is the SDK itself.
36
-
37
- **4. For BTP on-prem scenarios (Cloud Connector), the JWT→x509/SNC swap happens server-side in the CC.** The client-side RFC call still carries classic credentials (x509 + SNC), not the JWT. Supporting that would be adding SNC-over-RFC for on-prem backends behind a CC tunnel — an on-prem extension, not a "cloud RFC" feature.
38
-
39
- **Conclusion:** "RFC to cloud" is not a missing feature that would be useful to add; it is a category error. ADT to cloud = HTTP (already supported here). RFC to on-prem = supported here, by handing `AdtOnPremConnector` an `RfcTransport`. Anything claiming a third combination does not map to what the SAP stack actually exposes.
40
-
41
- ## See also
42
-
43
- - [`INSTALLATION.md`](./INSTALLATION.md)
44
- - [`USAGE.md`](./USAGE.md)
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`
1
+ # Scope
2
+
3
+ `@mcp-abap-adt/connection` answers for this, and only this:
4
+
5
+ 1. **Building a connection.** `createConnection({ system, transport, … })`: cloud + HTTP,
6
+ on-prem + HTTP, on-prem + legacy HTTP (BASIS 7.40), on-prem + RFC. The caller states
7
+ the system and the transport; nothing is inferred.
8
+ 2. **One instance, one SAP session.** `connect()` logs on; the first authenticated request
9
+ opens the session. A new session is a new instance.
10
+ 3. **Requests.** Each carries the credential the `IAuthProvider` hands over, the CSRF token
11
+ and the session's cookies. A request is sent stateful (`LOCK`, `UNLOCK`, activation) or
12
+ stateless; nothing else of the session is kept between requests.
13
+ 4. **SAP's answer** reaches the caller as SAP gave it.
14
+ 5. **`disconnect()`, once.** It sends the logoff when the instance holds a live
15
+ `SAP_SESSIONID` and resolves when the logoff is written. A `connect()` that failed after
16
+ opening a session logs it off before it rejects. `flushGoodbye(ms?)` waits for SAP's
17
+ answer to the logoff.
@@ -81,7 +81,7 @@ is what every stateless call cost with `sap-rfc-lite` 0.1.x (and with 0.2.0,
81
81
  whose npm package lacks the reset), and why 9.4.2 requires 0.2.1. Direct connector users must mark
82
82
  LOCK and UNLOCK stateful to retain their conversation. If disconnect occurs
83
83
  while a temporary conversation is logging on, it is closed without sending
84
- the request; reconnect does not revive that pending request.
84
+ the request; a new connection does not revive that pending request.
85
85
 
86
86
  ## Enabling Stateful Sessions
87
87
 
@@ -172,42 +172,47 @@ Every ADT request issued through `makeAdtRequest` automatically:
172
172
 
173
173
  This logic is transparent to callers (Builders, handlers, CLI scripts).
174
174
 
175
- A 401 that survives the wire's own CSRF recovery is put to the provider (`rejected`). On Ok the
175
+ A 401 that survives the wire's own CSRF recovery (in the same session) is put to the provider (`rejected`). On Ok the
176
176
  request is sent once more, always under the same lease and generation as the attempt it repeats,
177
177
  so stale-request fencing applies. After a rejection at `'request'` that resend goes out on the
178
178
  same session; after a rejection at `'logon'` the wire logs on again before the resend.
179
- **Inside a critical section a renewal keeps the session, and the lock in it:** a mutation
179
+ **No 401 opens a new session, and the lock in the session is kept:** a mutation
180
180
  (POST / PUT / DELETE) refused with a 401 while a CSRF token is cached goes to the provider and is
181
- resent on the same session with the same token, and if SAP did replace the session the request
182
- fails with `SESSION_REPLACED` instead of carrying on in a new one. Outside a critical section
183
- that mutation takes the wire's own stale-session recovery first, which starts a new session
184
- before the provider is asked — so hold a lock inside `beginCriticalSection()` /
185
- `endCriticalSection()`.
186
- **The price of keeping the lock:** when the session is really dead but SAP answers the resend with
187
- the SAME session cookie (no `Set-Cookie`), the connection cannot tell it from a refused
188
- credential — the second 401 ends the request as `AuthRefusedError` with the refused-again
189
- verdict (`at: 'request'`), not `SESSION_REPLACED`, and the connection stays connected. Inside a
190
- critical section, treat that as a lost lock: `disconnect()`, `connect()`, and redo the work under
191
- a new lock.
181
+ resent on the same session with the same token, inside a critical section or not, and if SAP did
182
+ replace the session the request fails with `SESSION_REPLACED` instead of carrying on in a new one.
183
+ Before 16.0.0, outside a critical section, that mutation discarded the session and retried in a
184
+ new one on the same instance; that recovery is gone. One instance is one session: if you want a
185
+ new session after a 401, create a new connection.
186
+ **A dead session can look like a refused credential:** when the session is really dead but SAP
187
+ answers the resend with the SAME session cookie (no `Set-Cookie`), the connection cannot tell it
188
+ from a refused credential — the second 401 ends the request as `AuthRefusedError` with the
189
+ refused-again verdict (`at: 'request'`), not `SESSION_REPLACED`, and the connection stays
190
+ connected. Treat that as a lost session, and any lock in it as lost: `disconnect()`, create a new
191
+ connection, and redo the work under a new lock there.
192
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
193
193
  provider. See [When the credential is refused](./USAGE.md#when-the-credential-is-refused).
194
194
 
195
- A reconnect is a NEW session, so do it outside a lock window rather than inside one.
195
+ **One connection instance is one session.** After `disconnect()`, or a failed `connect()` that
196
+ received a session cookie (whether or not a logoff was sent for it), the instance is spent and `connect()` on it rejects `NOT_CONNECTED`. A new
197
+ session is a new instance, created by the consumer (its own factory, or `createConnection`), and
198
+ outside a lock window rather than inside one.
196
199
 
197
- **Wait for the goodbye before opening the next one.** `disconnect()` dispatches the logoff and does
198
- not await it, so a reconnect otherwise opens the next session while the previous one's goodbye is
199
- still being assembled, and the server keeps both:
200
+ **Wait for the goodbye before opening the next one.** `disconnect()` resolves once the logoff is
201
+ written, not answered, so a new connection otherwise opens the next session while the previous
202
+ one's goodbye is still unanswered, and the server keeps both:
200
203
 
201
204
  ```typescript
202
205
  await conn.disconnect();
203
- await conn.flushGoodbye(); // give the goodbye its budget to finish first
204
- await conn.connect();
206
+ await conn.flushGoodbye(); // wait for the goodbye's answer; flushGoodbye(ms) bounds it
207
+ const next = createYourConnection(); // a new instance for the new session
208
+ await next.connect();
205
209
  ```
206
210
 
207
211
  Measured on E19 through a harness that recycled the session after each test: a new ABAP session
208
212
  every one to two seconds for a whole run, none released, each living to its own thirty-minute idle
209
- timeout. The budget bounds the waiting, not the overlap — if the goodbye finishes in time there is
210
- none, and if it does not you proceed while it stays outstanding. Calling `disconnect()` again is not
213
+ timeout. Without an argument `flushGoodbye()` waits for the answer as long as SAP takes; a budget
214
+ you pass bounds the waiting, not the overlap — if the goodbye finishes in time there is none, and if
215
+ it does not you proceed while it stays outstanding. Calling `disconnect()` again is not
211
216
  a substitute: a repeat call does not wait either.
212
217
 
213
218
  ---
@@ -237,7 +242,7 @@ The link to the ABAP session is not guaranteed, and that is the whole problem:
237
242
  Both are reported, neither is worked around. `connect()` fails with the reason
238
243
  when no session was opened; a session lost afterwards surfaces as
239
244
  `ADT_SESSION_REPLACED` rather than a request quietly continuing somewhere it
240
- does not belong. What to do about either — wait, retry, reconnect, release
245
+ does not belong. What to do about either — wait, retry, create a new connection, release
241
246
  sessions the user still holds, carry on read-only — is the caller's decision,
242
247
  made with the cookies and the answers in hand.
243
248
 
@@ -286,9 +291,10 @@ What it promises is narrow and worth stating exactly — inside a section the
286
291
  short: the ceiling is `SAP_TIMEOUT_CRITICAL`, ten minutes by default, and a
287
292
  socket ends a request whatever a contract says.
288
293
 
289
- Since 10.0.0 a section also keeps its session through a credential renewal: a
290
- mutation refused with a 401 inside it is renewed and resent on the same
291
- session, never moved to a new one (see [Request Hooks](#request-hooks)).
294
+ A section keeps its session through a credential renewal: a mutation refused
295
+ with a 401 inside it is renewed and resent on the same session, never moved to
296
+ a new one. Since 16.0.0 that holds outside a section too: no 401 moves a
297
+ request to a new session (see [Request Hooks](#request-hooks)).
292
298
 
293
299
  ### Two sessions, and they are not the same thing
294
300
 
@@ -339,7 +345,8 @@ you get by asking — `getSessionIdentity()` for which session you are in, and
339
345
  ## Troubleshooting
340
346
 
341
347
  - **CSRF token errors**: discard the session and establish a new one. That is
342
- `disconnect()` followed by `connect()` — there is no local-only discard, because
348
+ `disconnect()`, then a NEW connection's `connect()` — one instance is one
349
+ session — and there is no local-only discard, because
343
350
  dropping the cookie leaves the ABAP session open on the server. Both live on
344
351
  the HTTP connection classes and are **not** on the `IAbapConnection` type
345
352
  a bare `IAbapConnection` carries — reach them through a connector type, or
@@ -351,9 +358,10 @@ import { BasicAuthProvider } from '@mcp-abap-adt/auth-providers';
351
358
 
352
359
  const connection = new AdtOnPremConnector(config, new BasicAuthProvider(user, pass), new OnPremHttpTransport(() => ({}), logger, { client: config.client, baseUrl: config.url }), logger);
353
360
  await connection.disconnect(); // ends the session on the server, then clears
354
- await connection.connect(); // a new session, explicitly
361
+ const next = new AdtOnPremConnector(config, new BasicAuthProvider(user, pass), new OnPremHttpTransport(() => ({}), logger, { client: config.client, baseUrl: config.url }), logger);
362
+ await next.connect(); // a new session is a new instance
355
363
  ```
356
- - **Session expired**: reauthenticate to obtain a new session.
364
+ - **Session expired**: create a new connection; a new session is a new instance.
357
365
  - **Multiple connections**: each connector holds its own wire, and the wire holds the cookie jar; share the instance if you need continuity.
358
366
 
359
367
  ---