@mcp-abap-adt/connection 25.0.1 → 25.1.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,111 @@
1
+ "use strict";
2
+ /**
3
+ * The one line a `noLog` request may write: the method, the path without its
4
+ * query, the integer status and the byte count — nothing of the request's
5
+ * query, headers or body, nothing of the answer's headers, status text or body.
6
+ *
7
+ * Shared by the connection and both wires, so a `noLog` line reads the same
8
+ * whichever of them wrote it.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.UNPARSABLE_URL = void 0;
12
+ exports.pathOf = pathOf;
13
+ exports.byteCount = byteCount;
14
+ exports.quietLine = quietLine;
15
+ /** What a quiet line names for a URL that does not parse: nothing of it. */
16
+ exports.UNPARSABLE_URL = '<unparsable url>';
17
+ /**
18
+ * The path of a request URL. A path (`/…`, not `//…`) is cut at its query or
19
+ * fragment; anything else is parsed as an absolute URL and gives its pathname
20
+ * alone — never its user, password, host, query or fragment, which the WHATWG
21
+ * parser separates. One with a scheme and no authority (`user:pass@host/x`)
22
+ * names nothing; one that does not parse (a bad port, `//host/x`) names the
23
+ * fixed placeholder, never any part of the input.
24
+ */
25
+ function pathOf(url) {
26
+ if (!url.startsWith('/') || url.startsWith('//')) {
27
+ let parsed;
28
+ try {
29
+ parsed = new URL(url);
30
+ }
31
+ catch {
32
+ return exports.UNPARSABLE_URL;
33
+ }
34
+ return parsed.host ? parsed.pathname : '';
35
+ }
36
+ let end = url.length;
37
+ const query = url.indexOf('?');
38
+ if (query !== -1)
39
+ end = query;
40
+ const fragment = url.indexOf('#');
41
+ if (fragment !== -1 && fragment < end)
42
+ end = fragment;
43
+ return escapedControls(url.slice(0, end));
44
+ }
45
+ /**
46
+ * Whether a code point can end or break a line: C0, DEL, C1 (U+0080–U+009F,
47
+ * NEL among them), and the line and paragraph separators.
48
+ */
49
+ function breaksLines(code) {
50
+ return (code < 0x20 ||
51
+ (code >= 0x7f && code <= 0x9f) ||
52
+ code === 0x2028 ||
53
+ code === 0x2029);
54
+ }
55
+ /**
56
+ * The text with every code point that can break a line written as a fixed
57
+ * escape — `\xNN` up to U+00FF, `\uNNNN` beyond: neither a path nor a method
58
+ * can split the quiet line into two, or forge a second one. Plain string code.
59
+ */
60
+ function escapedControls(text) {
61
+ let out = '';
62
+ for (const char of text) {
63
+ const code = char.codePointAt(0) ?? 0;
64
+ if (!breaksLines(code))
65
+ out += char;
66
+ else if (code <= 0xff)
67
+ out += `\\x${code.toString(16).padStart(2, '0')}`;
68
+ else
69
+ out += `\\u${code.toString(16).padStart(4, '0')}`;
70
+ }
71
+ return out;
72
+ }
73
+ /**
74
+ * The size of an answer's body in bytes. A body is the wire's, from outside the
75
+ * type system: a string or bytes as they are, anything else as it serialises;
76
+ * one that will not serialise counts as none.
77
+ */
78
+ function byteCount(data) {
79
+ if (data === undefined || data === null)
80
+ return 0;
81
+ if (typeof data === 'string')
82
+ return Buffer.byteLength(data, 'utf8');
83
+ if (ArrayBuffer.isView(data))
84
+ return data.byteLength;
85
+ if (data instanceof ArrayBuffer)
86
+ return data.byteLength;
87
+ try {
88
+ const text = JSON.stringify(data);
89
+ return text === undefined ? 0 : Buffer.byteLength(text, 'utf8');
90
+ }
91
+ catch {
92
+ return 0;
93
+ }
94
+ }
95
+ /**
96
+ * The quiet line: `METHOD /path → STATUS (N bytes)` for an answer, and
97
+ * `METHOD /path → no answer` for a request that got none.
98
+ */
99
+ function quietLine(rawMethod, url, answer) {
100
+ const path = pathOf(url);
101
+ // The caller's method, as written: escaped as the path is.
102
+ const method = escapedControls(rawMethod);
103
+ if (answer === undefined || !Number.isInteger(answer.status)) {
104
+ return { line: `${method} ${path} → no answer`, facts: { method, path } };
105
+ }
106
+ const bytes = byteCount(answer.data);
107
+ return {
108
+ line: `${method} ${path} → ${answer.status} (${bytes} bytes)`,
109
+ facts: { method, path, status: answer.status, bytes },
110
+ };
111
+ }
@@ -10,10 +10,23 @@
10
10
  import type { IAdtTransportRequest } from './IAdtTransport.js';
11
11
  /** The header that asks SAP for the stateful session over HTTP. */
12
12
  export declare const SESSION_TYPE_HEADER = "x-sap-adt-sessiontype";
13
+ /** The cookie that names a stateful ABAP context. */
14
+ export declare const CONTEXT_COOKIE = "sap-contextid";
13
15
  /**
14
16
  * Marked so by the connection, or — kept for callers that still write it
15
17
  * themselves — carrying the session header already. Taken on the request as
16
18
  * the caller made it, before a wire rewrites it.
19
+ *
20
+ * A request marked `stateless` is not stateful, whatever else it says: the
21
+ * caller's `stateless: true` wins over the flag and over its own header.
17
22
  */
18
23
  export declare function isStatefulRequest(request: IAdtTransportRequest): boolean;
24
+ /** Whether a header's name is the session header, in any letter case. */
25
+ export declare function isSessionTypeHeader(name: string): boolean;
26
+ /**
27
+ * A `Cookie` header's value without `sap-contextid`, or `undefined` when
28
+ * nothing is left. Plain string code: the pairs split at `;`, each read
29
+ * without its leading whitespace.
30
+ */
31
+ export declare function cookieWithoutContext(cookie: string): string | undefined;
19
32
  //# sourceMappingURL=statefulRequest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"statefulRequest.d.ts","sourceRoot":"","sources":["../../src/connection/statefulRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,mEAAmE;AACnE,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAaxE"}
1
+ {"version":3,"file":"statefulRequest.d.ts","sourceRoot":"","sources":["../../src/connection/statefulRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,mEAAmE;AACnE,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAE3D,qDAAqD;AACrD,eAAO,MAAM,cAAc,kBAAkB,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAcxE;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOvE"}
@@ -1,15 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SESSION_TYPE_HEADER = void 0;
3
+ exports.CONTEXT_COOKIE = exports.SESSION_TYPE_HEADER = void 0;
4
4
  exports.isStatefulRequest = isStatefulRequest;
5
+ exports.isSessionTypeHeader = isSessionTypeHeader;
6
+ exports.cookieWithoutContext = cookieWithoutContext;
5
7
  /** The header that asks SAP for the stateful session over HTTP. */
6
8
  exports.SESSION_TYPE_HEADER = 'x-sap-adt-sessiontype';
9
+ /** The cookie that names a stateful ABAP context. */
10
+ exports.CONTEXT_COOKIE = 'sap-contextid';
7
11
  /**
8
12
  * Marked so by the connection, or — kept for callers that still write it
9
13
  * themselves — carrying the session header already. Taken on the request as
10
14
  * the caller made it, before a wire rewrites it.
15
+ *
16
+ * A request marked `stateless` is not stateful, whatever else it says: the
17
+ * caller's `stateless: true` wins over the flag and over its own header.
11
18
  */
12
19
  function isStatefulRequest(request) {
20
+ if (request.stateless)
21
+ return false;
13
22
  if (request.stateful)
14
23
  return true;
15
24
  const headers = request.headers;
@@ -23,3 +32,20 @@ function isStatefulRequest(request) {
23
32
  }
24
33
  return false;
25
34
  }
35
+ /** Whether a header's name is the session header, in any letter case. */
36
+ function isSessionTypeHeader(name) {
37
+ return name.trim().toLowerCase() === exports.SESSION_TYPE_HEADER;
38
+ }
39
+ /**
40
+ * A `Cookie` header's value without `sap-contextid`, or `undefined` when
41
+ * nothing is left. Plain string code: the pairs split at `;`, each read
42
+ * without its leading whitespace.
43
+ */
44
+ function cookieWithoutContext(cookie) {
45
+ const kept = cookie
46
+ .split(';')
47
+ .map((pair) => pair.trimStart())
48
+ .filter((pair) => pair && pair.split('=')[0]?.trim() !== exports.CONTEXT_COOKIE)
49
+ .join('; ');
50
+ return kept || undefined;
51
+ }
@@ -4,5 +4,11 @@ import type { CreatedConnection } from './createConnection.js';
4
4
  * means SAP did not run it. Retry on a separate session only when that same
5
5
  * response proved the original session gone.
6
6
  */
7
- export declare function withCheckRelogon<TConnection extends CreatedConnection>(connection: TConnection, fresh: () => TConnection): TConnection;
7
+ export declare function withCheckRelogon<TConnection extends CreatedConnection>(connection: TConnection,
8
+ /**
9
+ * A new connection for the replay. `quiet`: the call is a `noLog` one, so
10
+ * the connection writes no line — its logon, the replay and its logoff
11
+ * included; the call's one quiet line is the original request's.
12
+ */
13
+ fresh: (quiet: boolean) => TConnection): TConnection;
8
14
  //# sourceMappingURL=withCheckRelogon.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withCheckRelogon.d.ts","sourceRoot":"","sources":["../../src/connection/withCheckRelogon.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI/D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,SAAS,iBAAiB,EACpE,UAAU,EAAE,WAAW,EACvB,KAAK,EAAE,MAAM,WAAW,GACvB,WAAW,CA0Db"}
1
+ {"version":3,"file":"withCheckRelogon.d.ts","sourceRoot":"","sources":["../../src/connection/withCheckRelogon.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI/D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,SAAS,iBAAiB,EACpE,UAAU,EAAE,WAAW;AACvB;;;;GAIG;AACH,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,WAAW,GACrC,WAAW,CA4Db"}
@@ -10,7 +10,13 @@ const statefulRequest_js_1 = require("./statefulRequest.js");
10
10
  * means SAP did not run it. Retry on a separate session only when that same
11
11
  * response proved the original session gone.
12
12
  */
13
- function withCheckRelogon(connection, fresh) {
13
+ function withCheckRelogon(connection,
14
+ /**
15
+ * A new connection for the replay. `quiet`: the call is a `noLog` one, so
16
+ * the connection writes no line — its logon, the replay and its logoff
17
+ * included; the call's one quiet line is the original request's.
18
+ */
19
+ fresh) {
14
20
  const send = connection.makeAdtRequest.bind(connection);
15
21
  const disconnect = connection.disconnect.bind(connection);
16
22
  const pending = new Set();
@@ -20,7 +26,10 @@ function withCheckRelogon(connection, fresh) {
20
26
  await Promise.all([disconnect(), ...Array.from(pending, (stop) => stop())]);
21
27
  };
22
28
  connection.makeAdtRequest = async (request) => {
23
- const eligible = request.method.toUpperCase() === 'POST' &&
29
+ const eligible =
30
+ // `noResend`: the refusal is the caller's answer, never replayed.
31
+ !request.noResend &&
32
+ request.method.toUpperCase() === 'POST' &&
24
33
  request.url.split('?', 1)[0] === '/sap/bc/adt/checkruns' &&
25
34
  typeof request.data === 'string' &&
26
35
  connection.getSessionMode() === 'stateless' &&
@@ -41,7 +50,7 @@ function withCheckRelogon(connection, fresh) {
41
50
  typeof refusal.data !== 'string' ||
42
51
  !refusal.data.includes('CSRF token validation failed'))
43
52
  throw error;
44
- const replacement = fresh();
53
+ const replacement = fresh(request.noLog === true);
45
54
  let stopped;
46
55
  const stop = () => (stopped ??= replacement.disconnect());
47
56
  pending.add(stop);
@@ -169,7 +169,11 @@ Every ADT request issued through `makeAdtRequest` automatically:
169
169
  3. Updates stored cookies if SAP returns `set-cookie`.
170
170
  4. Retries once when CSRF token is invalid/expired.
171
171
 
172
- This logic is transparent to callers (Builders, handlers, CLI scripts).
172
+ This logic is transparent to callers (Builders, handlers, CLI scripts). A
173
+ request sent with `noResend: true` (25.1.0) skips step 4 and every other
174
+ resend: its token fetch (step 1) goes once, and the first failure — of the
175
+ fetch or of the request — is the caller's answer. See the README's
176
+ [Request options](../README.md#request-options-noresend-nolog-stateless).
173
177
 
174
178
  A 401 that survives the wire's own CSRF recovery (in the same session) is put to the provider (`rejected`). On Ok the
175
179
  request is sent once more, always under the same lease and generation as the attempt it repeats,
package/docs/USAGE.md CHANGED
@@ -850,7 +850,30 @@ connection remains spent. A successful retry still carries
850
850
  original session.
851
851
 
852
852
  This applies to stateless checks outside a critical section. Stateful requests
853
- and operations under an existing lock retain their session-bound behavior.
853
+ and operations under an existing lock retain their session-bound behavior. A
854
+ check sent with `noResend: true` is not retried: the refusal is its answer.
855
+
856
+ ### Request options: `noResend`, `noLog`, `stateless`
857
+
858
+ Three optional flags of `IAbapRequestOptions` (25.1.0) change one request and
859
+ nothing else; a request without them behaves as before. In short:
860
+
861
+ - `noResend: true` — sent once: no CSRF recovery, no resend after the
862
+ credential's renewal (the provider is not asked), no resend on a dead pooled
863
+ socket, no syntax-check replay; the CSRF token fetch before a mutation still
864
+ happens, once — no fallback endpoint, a token only from a `2xx` (its failure
865
+ is the answer and the request is not sent); a
866
+ `3xx` from SAP's endpoint is the answer, not followed.
867
+ - `noLog: true` — the connection writes exactly one line about the request,
868
+ `METHOD /path → STATUS (N bytes)` (or `→ no answer`), the path without its
869
+ query, host or user; the wires write none of their own, two fixed-word lines
870
+ aside (`CSRF token obtained`, and the cloud wire's
871
+ `The server published no logoff resource; sending the platform logoff`); the thrown error keeps SAP's answer.
872
+ - `stateless: true` — stateless on HTTP and RFC whatever the session mode, over
873
+ the caller's own `x-sap-adt-sessiontype` header in any letter case; the header
874
+ and the `sap-contextid` cookie are stripped; the session mode stays.
875
+
876
+ The whole contract, and why `noResend` exists: [README — Request options](../README.md#request-options-noresend-nolog-stateless).
854
877
 
855
878
  ### Starting Over
856
879
 
@@ -1172,7 +1195,9 @@ carries it; the wire never reads `config.username` or `config.password`.
1172
1195
  the provider.
1173
1196
 
1174
1197
  Nothing else is sent again: a failed request — the CSRF token fetch included
1175
- (21.0.0) — is its own error.
1198
+ (21.0.0) — is its own error. A request with `noResend: true` (25.1.0) gets none
1199
+ of these three resends, and follows no redirect: see
1200
+ [Request options](#request-options-noresend-nolog-stateless).
1176
1201
  - RFC takes logon parameters (a password, or SNC settings) on every conversation
1177
1202
  it opens, the session's own and each per-call one. RFC refuses TLS material,
1178
1203
  and a provider that writes no logon parameters (a bearer token) cannot log on
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-abap-adt/connection",
3
- "version": "25.0.1",
3
+ "version": "25.1.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",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@mcp-abap-adt/auth-errors": "^2.2.1",
55
- "@mcp-abap-adt/interfaces-adt-connection": "^5.0.0",
55
+ "@mcp-abap-adt/interfaces-adt-connection": "^5.2.0",
56
56
  "@mcp-abap-adt/interfaces-auth": "^7.5.0",
57
57
  "@mcp-abap-adt/interfaces-auth-sap": "^4.0.0",
58
58
  "@mcp-abap-adt/interfaces-network": "^2.0.1",