@mcp-abap-adt/connection 25.0.1 → 25.2.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 (35) hide show
  1. package/CHANGELOG.md +104 -1
  2. package/README.md +97 -1
  3. package/dist/connection/AbstractAbapConnection.d.ts +12 -4
  4. package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
  5. package/dist/connection/AbstractAbapConnection.js +256 -81
  6. package/dist/connection/HttpTransport.d.ts +3 -1
  7. package/dist/connection/HttpTransport.d.ts.map +1 -1
  8. package/dist/connection/HttpTransport.js +76 -17
  9. package/dist/connection/IAdtTransport.d.ts +38 -1
  10. package/dist/connection/IAdtTransport.d.ts.map +1 -1
  11. package/dist/connection/RfcTransport.d.ts.map +1 -1
  12. package/dist/connection/RfcTransport.js +67 -24
  13. package/dist/connection/createConnection.d.ts.map +1 -1
  14. package/dist/connection/createConnection.js +6 -1
  15. package/dist/connection/csrfRetry.d.ts +10 -0
  16. package/dist/connection/csrfRetry.d.ts.map +1 -0
  17. package/dist/connection/csrfRetry.js +43 -0
  18. package/dist/connection/exactText.d.ts +43 -0
  19. package/dist/connection/exactText.d.ts.map +1 -0
  20. package/dist/connection/exactText.js +168 -0
  21. package/dist/connection/failureFacts.d.ts +3 -1
  22. package/dist/connection/failureFacts.d.ts.map +1 -1
  23. package/dist/connection/failureFacts.js +33 -3
  24. package/dist/connection/quietLine.d.ts +44 -0
  25. package/dist/connection/quietLine.d.ts.map +1 -0
  26. package/dist/connection/quietLine.js +113 -0
  27. package/dist/connection/statefulRequest.d.ts +13 -0
  28. package/dist/connection/statefulRequest.d.ts.map +1 -1
  29. package/dist/connection/statefulRequest.js +27 -1
  30. package/dist/connection/withCheckRelogon.d.ts +7 -1
  31. package/dist/connection/withCheckRelogon.d.ts.map +1 -1
  32. package/dist/connection/withCheckRelogon.js +18 -5
  33. package/docs/STATEFUL_SESSION_GUIDE.md +5 -1
  34. package/docs/USAGE.md +38 -2
  35. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exactText.d.ts","sourceRoot":"","sources":["../../src/connection/exactText.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AA0HhE;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,qBAAqB,GAC5B,qBAAqB,CAWvB;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAGzD;AAED,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEhE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAG5D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAGnE"}
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rawTextAnswer = rawTextAnswer;
4
+ exports.carryExact = carryExact;
5
+ exports.rawByteLength = rawByteLength;
6
+ exports.toCallerView = toCallerView;
7
+ exports.internalBody = internalBody;
8
+ const EXACT = new WeakMap();
9
+ /** The body's bytes: a Buffer, any other view, or a plain `ArrayBuffer`. */
10
+ function bytesOf(body) {
11
+ if (body instanceof Uint8Array)
12
+ return body;
13
+ if (ArrayBuffer.isView(body)) {
14
+ return new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
15
+ }
16
+ if (body instanceof ArrayBuffer)
17
+ return new Uint8Array(body);
18
+ return undefined;
19
+ }
20
+ /**
21
+ * What the unflagged path makes of these bytes, step for step as axios does:
22
+ * UTF-8 (`Buffer#toString`), a leading BOM dropped, then its default
23
+ * `transformResponse` — a non-empty string parsed as JSON when it parses.
24
+ */
25
+ function unflaggedBody(bytes) {
26
+ const decoded = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('utf8');
27
+ const text = decoded.charCodeAt(0) === 0xfeff ? decoded.slice(1) : decoded;
28
+ if (text === '')
29
+ return text;
30
+ try {
31
+ return JSON.parse(text);
32
+ }
33
+ catch {
34
+ return text;
35
+ }
36
+ }
37
+ /**
38
+ * The first `charset` parameter of the answer's `Content-Type`, unquoted, or
39
+ * `undefined`. Parameters are split on `;` outside quoted strings. Headers
40
+ * are the wire's, from outside the type system. Plain string code.
41
+ */
42
+ function charsetOf(headers) {
43
+ if (typeof headers !== 'object' || headers === null)
44
+ return undefined;
45
+ let type;
46
+ for (const [name, value] of Object.entries(headers)) {
47
+ if (name.toLowerCase() === 'content-type' && typeof value === 'string') {
48
+ type = value;
49
+ }
50
+ }
51
+ if (type === undefined)
52
+ return undefined;
53
+ for (const parameter of parametersOf(type)) {
54
+ const at = parameter.indexOf('=');
55
+ if (at < 0)
56
+ continue;
57
+ if (parameter.slice(0, at).trim().toLowerCase() !== 'charset')
58
+ continue;
59
+ return unquoted(parameter.slice(at + 1).trim());
60
+ }
61
+ return undefined;
62
+ }
63
+ /** A media type's parameters: split on `;` outside quoted strings. */
64
+ function parametersOf(type) {
65
+ const parts = [];
66
+ let current = '';
67
+ let quoted = false;
68
+ let escaped = false;
69
+ for (const char of type) {
70
+ if (escaped) {
71
+ escaped = false;
72
+ }
73
+ else if (quoted && char === '\\') {
74
+ escaped = true;
75
+ }
76
+ else if (char === '"') {
77
+ quoted = !quoted;
78
+ }
79
+ else if (char === ';' && !quoted) {
80
+ parts.push(current);
81
+ current = '';
82
+ continue;
83
+ }
84
+ current += char;
85
+ }
86
+ parts.push(current);
87
+ return parts.slice(1);
88
+ }
89
+ /** A parameter value without its quotes and escapes, when it is quoted. */
90
+ function unquoted(value) {
91
+ if (!(value.length >= 2 && value.startsWith('"') && value.endsWith('"'))) {
92
+ return value;
93
+ }
94
+ let out = '';
95
+ let escaped = false;
96
+ for (const char of value.slice(1, -1)) {
97
+ if (escaped) {
98
+ out += char;
99
+ escaped = false;
100
+ }
101
+ else if (char === '\\') {
102
+ escaped = true;
103
+ }
104
+ else {
105
+ out += char;
106
+ }
107
+ }
108
+ return out;
109
+ }
110
+ /** The declared charset's decoder when `TextDecoder` knows it, else UTF-8. */
111
+ function decoderFor(charset) {
112
+ if (charset !== undefined) {
113
+ try {
114
+ return new TextDecoder(charset, { ignoreBOM: true });
115
+ }
116
+ catch {
117
+ // A label `TextDecoder` does not know: UTF-8.
118
+ }
119
+ }
120
+ return new TextDecoder('utf-8', { ignoreBOM: true });
121
+ }
122
+ /**
123
+ * A `rawText` answer as the connection reads it: `data` is what the
124
+ * unflagged path has, and the exact text and raw byte length are kept beside
125
+ * it. A body that is not bytes (a client that made something else of it) is
126
+ * left as it is.
127
+ */
128
+ function rawTextAnswer(answer) {
129
+ const bytes = bytesOf(answer.data);
130
+ if (bytes === undefined)
131
+ return answer;
132
+ const internal = unflaggedBody(bytes);
133
+ const read = { ...answer, data: internal };
134
+ EXACT.set(read, {
135
+ text: decoderFor(charsetOf(answer.headers)).decode(bytes),
136
+ bytes: bytes.byteLength,
137
+ internal,
138
+ });
139
+ return read;
140
+ }
141
+ /** The same exact text on another object carrying the same answer. */
142
+ function carryExact(from, to) {
143
+ const exact = EXACT.get(from);
144
+ if (exact !== undefined)
145
+ EXACT.set(to, exact);
146
+ }
147
+ /** A `rawText` answer's raw byte length, else `undefined`. */
148
+ function rawByteLength(answer) {
149
+ return EXACT.get(answer)?.bytes;
150
+ }
151
+ /**
152
+ * The caller's view, at the connection's door: a `rawText` answer's `data`
153
+ * becomes its exact text. Every consumer inside has read it by then.
154
+ */
155
+ function toCallerView(answer) {
156
+ const exact = EXACT.get(answer);
157
+ if (exact !== undefined)
158
+ answer.data = exact.text;
159
+ }
160
+ /**
161
+ * The body as consumers inside read it, for one that sits outside the
162
+ * connection's door (the check replay of `createConnection`): what the
163
+ * unflagged path has, whether or not the caller's view was applied.
164
+ */
165
+ function internalBody(answer) {
166
+ const exact = EXACT.get(answer);
167
+ return exact === undefined ? answer.data : exact.internal;
168
+ }
@@ -91,7 +91,9 @@ export type HttpFailure = Error & IAbapConnectionError & {
91
91
  * `Request failed with status code <n>`, built from the status), else the
92
92
  * code (`ECONNREFUSED`, `ECONNABORTED`, …) and `The request failed: <code>`.
93
93
  */
94
- export declare function httpFailure(thrown: unknown): HttpFailure;
94
+ export declare function httpFailure(thrown: unknown,
95
+ /** The request's `rawText`: SAP's answer as bytes, read as `rawTextAnswer`. */
96
+ rawText?: boolean): HttpFailure;
95
97
  /**
96
98
  * The wire's error as it arrived: the value an `httpFailure` was made from,
97
99
  * or `value` itself. For `IAuthRejection.error` only — never for a consumer.
@@ -1 +1 @@
1
- {"version":3,"file":"failureFacts.d.ts","sourceRoot":"","sources":["../../src/connection/failureFacts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAEnB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,uEAAuE;AACvE,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAK7D;AAMD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAkBrE;AAcD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAa1D;AAKD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAa/D;AAsBD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAY5D;AAED,2CAA2C;A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C,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAC3C,CAAC;AA+CJ;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO;AACf,+EAA+E;AAC/E,OAAO,UAAQ,GACd,WAAW,CAoBb;AASD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIjD"}
@@ -27,6 +27,7 @@ exports.failureCopy = failureCopy;
27
27
  exports.httpFailure = httpFailure;
28
28
  exports.asArrived = asArrived;
29
29
  const interfaces_adt_connection_1 = require("@mcp-abap-adt/interfaces-adt-connection");
30
+ const exactText_js_1 = require("./exactText.js");
30
31
  /** An own data property of `source`, read without running a getter. */
31
32
  function ownData(source, name) {
32
33
  const descriptor = Object.getOwnPropertyDescriptor(source, name);
@@ -231,17 +232,39 @@ function answerOf(thrown) {
231
232
  if (!isInteger(status))
232
233
  return undefined;
233
234
  const statusText = ownData(response, 'statusText');
234
- return {
235
+ const copy = {
235
236
  status,
236
237
  ...(typeof statusText === 'string' ? { statusText } : {}),
237
238
  headers: ownData(response, 'headers'),
238
239
  data: ownData(response, 'data'),
239
240
  };
241
+ // A `rawText` answer's exact text goes with every copy of it.
242
+ (0, exactText_js_1.carryExact)(response, copy);
243
+ return copy;
240
244
  }
241
245
  catch {
242
246
  return undefined;
243
247
  }
244
248
  }
249
+ /**
250
+ * A `rawText` rejection's own `response.data` set to what the connection
251
+ * reads — the body the unflagged path has — so nothing inside, the
252
+ * credential provider included, sees the bytes. A value that will not take
253
+ * it is left as it is.
254
+ */
255
+ function arrivedBody(thrown, data) {
256
+ if (typeof thrown !== 'object' || thrown === null)
257
+ return;
258
+ try {
259
+ const response = ownData(thrown, 'response');
260
+ if (typeof response === 'object' && response !== null) {
261
+ Reflect.set(response, 'data', data);
262
+ }
263
+ }
264
+ catch {
265
+ // A response that will not be read or written: left as it arrived.
266
+ }
267
+ }
245
268
  /**
246
269
  * What an HTTP client's rejection becomes before it leaves the wire: an
247
270
  * `Error` in fixed words with its facts and SAP's answer, and nothing else.
@@ -253,8 +276,15 @@ function answerOf(thrown) {
253
276
  * `Request failed with status code <n>`, built from the status), else the
254
277
  * code (`ECONNREFUSED`, `ECONNABORTED`, …) and `The request failed: <code>`.
255
278
  */
256
- function httpFailure(thrown) {
257
- const response = answerOf(thrown);
279
+ function httpFailure(thrown,
280
+ /** The request's `rawText`: SAP's answer as bytes, read as `rawTextAnswer`. */
281
+ rawText = false) {
282
+ const copied = answerOf(thrown);
283
+ const response = rawText && copied !== undefined ? (0, exactText_js_1.rawTextAnswer)(copied) : copied;
284
+ // The provider reads the wire's error as it arrived (`asArrived`): its
285
+ // body, too, is what the unflagged path has, never the bytes.
286
+ if (rawText && response !== undefined)
287
+ arrivedBody(thrown, response.data);
258
288
  const code = failureCode(thrown);
259
289
  const error = new Error(response !== undefined
260
290
  ? `Request failed with status code ${response.status}`
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The one line a `noLog` request may write: the method, the path without its
3
+ * query, the integer status and the byte count — nothing of the request's
4
+ * query, headers or body, nothing of the answer's headers, status text or body.
5
+ *
6
+ * Shared by the connection and both wires, so a `noLog` line reads the same
7
+ * whichever of them wrote it.
8
+ */
9
+ /** What a quiet line carries, as its log fields. */
10
+ export interface QuietFacts {
11
+ method: string;
12
+ path: string;
13
+ status?: number;
14
+ bytes?: number;
15
+ }
16
+ /** What a quiet line names for a URL that does not parse: nothing of it. */
17
+ export declare const UNPARSABLE_URL = "<unparsable url>";
18
+ /**
19
+ * The path of a request URL. A path (`/…`, not `//…`) is cut at its query or
20
+ * fragment; anything else is parsed as an absolute URL and gives its pathname
21
+ * alone — never its user, password, host, query or fragment, which the WHATWG
22
+ * parser separates. One with a scheme and no authority (`user:pass@host/x`)
23
+ * names nothing; one that does not parse (a bad port, `//host/x`) names the
24
+ * fixed placeholder, never any part of the input.
25
+ */
26
+ export declare function pathOf(url: string): string;
27
+ /**
28
+ * The size of an answer's body in bytes. A body is the wire's, from outside the
29
+ * type system: a string or bytes as they are, anything else as it serialises;
30
+ * one that will not serialise counts as none.
31
+ */
32
+ export declare function byteCount(data: unknown): number;
33
+ /**
34
+ * The quiet line: `METHOD /path → STATUS (N bytes)` for an answer, and
35
+ * `METHOD /path → no answer` for a request that got none.
36
+ */
37
+ export declare function quietLine(rawMethod: string, url: string, answer?: {
38
+ status: number;
39
+ data: unknown;
40
+ }): {
41
+ line: string;
42
+ facts: QuietFacts;
43
+ };
44
+ //# sourceMappingURL=quietLine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quietLine.d.ts","sourceRoot":"","sources":["../../src/connection/quietLine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,oDAAoD;AACpD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,4EAA4E;AAC5E,eAAO,MAAM,cAAc,qBAAqB,CAAC;AAEjD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAgB1C;AA+BD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAW/C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAarC"}
@@ -0,0 +1,113 @@
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
+ const exactText_js_1 = require("./exactText.js");
16
+ /** What a quiet line names for a URL that does not parse: nothing of it. */
17
+ exports.UNPARSABLE_URL = '<unparsable url>';
18
+ /**
19
+ * The path of a request URL. A path (`/…`, not `//…`) is cut at its query or
20
+ * fragment; anything else is parsed as an absolute URL and gives its pathname
21
+ * alone — never its user, password, host, query or fragment, which the WHATWG
22
+ * parser separates. One with a scheme and no authority (`user:pass@host/x`)
23
+ * names nothing; one that does not parse (a bad port, `//host/x`) names the
24
+ * fixed placeholder, never any part of the input.
25
+ */
26
+ function pathOf(url) {
27
+ if (!url.startsWith('/') || url.startsWith('//')) {
28
+ let parsed;
29
+ try {
30
+ parsed = new URL(url);
31
+ }
32
+ catch {
33
+ return exports.UNPARSABLE_URL;
34
+ }
35
+ return parsed.host ? parsed.pathname : '';
36
+ }
37
+ let end = url.length;
38
+ const query = url.indexOf('?');
39
+ if (query !== -1)
40
+ end = query;
41
+ const fragment = url.indexOf('#');
42
+ if (fragment !== -1 && fragment < end)
43
+ end = fragment;
44
+ return escapedControls(url.slice(0, end));
45
+ }
46
+ /**
47
+ * Whether a code point can end or break a line: C0, DEL, C1 (U+0080–U+009F,
48
+ * NEL among them), and the line and paragraph separators.
49
+ */
50
+ function breaksLines(code) {
51
+ return (code < 0x20 ||
52
+ (code >= 0x7f && code <= 0x9f) ||
53
+ code === 0x2028 ||
54
+ code === 0x2029);
55
+ }
56
+ /**
57
+ * The text with every code point that can break a line written as a fixed
58
+ * escape — `\xNN` up to U+00FF, `\uNNNN` beyond: neither a path nor a method
59
+ * can split the quiet line into two, or forge a second one. Plain string code.
60
+ */
61
+ function escapedControls(text) {
62
+ let out = '';
63
+ for (const char of text) {
64
+ const code = char.codePointAt(0) ?? 0;
65
+ if (!breaksLines(code))
66
+ out += char;
67
+ else if (code <= 0xff)
68
+ out += `\\x${code.toString(16).padStart(2, '0')}`;
69
+ else
70
+ out += `\\u${code.toString(16).padStart(4, '0')}`;
71
+ }
72
+ return out;
73
+ }
74
+ /**
75
+ * The size of an answer's body in bytes. A body is the wire's, from outside the
76
+ * type system: a string or bytes as they are, anything else as it serialises;
77
+ * one that will not serialise counts as none.
78
+ */
79
+ function byteCount(data) {
80
+ if (data === undefined || data === null)
81
+ return 0;
82
+ if (typeof data === 'string')
83
+ return Buffer.byteLength(data, 'utf8');
84
+ if (ArrayBuffer.isView(data))
85
+ return data.byteLength;
86
+ if (data instanceof ArrayBuffer)
87
+ return data.byteLength;
88
+ try {
89
+ const text = JSON.stringify(data);
90
+ return text === undefined ? 0 : Buffer.byteLength(text, 'utf8');
91
+ }
92
+ catch {
93
+ return 0;
94
+ }
95
+ }
96
+ /**
97
+ * The quiet line: `METHOD /path → STATUS (N bytes)` for an answer, and
98
+ * `METHOD /path → no answer` for a request that got none.
99
+ */
100
+ function quietLine(rawMethod, url, answer) {
101
+ const path = pathOf(url);
102
+ // The caller's method, as written: escaped as the path is.
103
+ const method = escapedControls(rawMethod);
104
+ if (answer === undefined || !Number.isInteger(answer.status)) {
105
+ return { line: `${method} ${path} → no answer`, facts: { method, path } };
106
+ }
107
+ // A `rawText` answer counts the bytes that arrived.
108
+ const bytes = (0, exactText_js_1.rawByteLength)(answer) ?? byteCount(answer.data);
109
+ return {
110
+ line: `${method} ${path} → ${answer.status} (${bytes} bytes)`,
111
+ facts: { method, path, status: answer.status, bytes },
112
+ };
113
+ }
@@ -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;AAK/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,CA+Db"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withCheckRelogon = withCheckRelogon;
4
4
  const interfaces_adt_connection_1 = require("@mcp-abap-adt/interfaces-adt-connection");
5
5
  const AbstractAbapConnection_js_1 = require("./AbstractAbapConnection.js");
6
+ const exactText_js_1 = require("./exactText.js");
6
7
  const IAdtTransport_js_1 = require("./IAdtTransport.js");
7
8
  const statefulRequest_js_1 = require("./statefulRequest.js");
8
9
  /**
@@ -10,7 +11,13 @@ const statefulRequest_js_1 = require("./statefulRequest.js");
10
11
  * means SAP did not run it. Retry on a separate session only when that same
11
12
  * response proved the original session gone.
12
13
  */
13
- function withCheckRelogon(connection, fresh) {
14
+ function withCheckRelogon(connection,
15
+ /**
16
+ * A new connection for the replay. `quiet`: the call is a `noLog` one, so
17
+ * the connection writes no line — its logon, the replay and its logoff
18
+ * included; the call's one quiet line is the original request's.
19
+ */
20
+ fresh) {
14
21
  const send = connection.makeAdtRequest.bind(connection);
15
22
  const disconnect = connection.disconnect.bind(connection);
16
23
  const pending = new Set();
@@ -20,7 +27,10 @@ function withCheckRelogon(connection, fresh) {
20
27
  await Promise.all([disconnect(), ...Array.from(pending, (stop) => stop())]);
21
28
  };
22
29
  connection.makeAdtRequest = async (request) => {
23
- const eligible = request.method.toUpperCase() === 'POST' &&
30
+ const eligible =
31
+ // `noResend`: the refusal is the caller's answer, never replayed.
32
+ !request.noResend &&
33
+ request.method.toUpperCase() === 'POST' &&
24
34
  request.url.split('?', 1)[0] === '/sap/bc/adt/checkruns' &&
25
35
  typeof request.data === 'string' &&
26
36
  connection.getSessionMode() === 'stateless' &&
@@ -37,11 +47,14 @@ function withCheckRelogon(connection, fresh) {
37
47
  if (!eligible || closing || !(0, AbstractAbapConnection_js_1.carriesSessionLost)(error))
38
48
  throw error;
39
49
  const refusal = (0, IAdtTransport_js_1.refusalOf)(error);
50
+ // The body as the connection read it: `rawText` changes only the
51
+ // caller's view, applied at the connection's door below this replay.
52
+ const body = refusal === null ? undefined : (0, exactText_js_1.internalBody)(refusal);
40
53
  if (refusal?.status !== 403 ||
41
- typeof refusal.data !== 'string' ||
42
- !refusal.data.includes('CSRF token validation failed'))
54
+ typeof body !== 'string' ||
55
+ !body.includes('CSRF token validation failed'))
43
56
  throw error;
44
- const replacement = fresh();
57
+ const replacement = fresh(request.noLog === true);
45
58
  let stopped;
46
59
  const stop = () => (stopped ??= replacement.disconnect());
47
60
  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,41 @@ 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
+ Optional flags of `IAbapRequestOptions` (`noResend`, `noLog`, `stateless`:
859
+ 25.1.0; `rawText`: 25.2.0) change one request and nothing else; a request
860
+ without them behaves as before. In short:
861
+
862
+ - `noResend: true` — sent once: no CSRF recovery, no resend after the
863
+ credential's renewal (the provider is not asked), no resend on a dead pooled
864
+ socket, no syntax-check replay; the CSRF token fetch before a mutation still
865
+ happens, once — no fallback endpoint, a token only from a `2xx` (its failure
866
+ is the answer and the request is not sent); a
867
+ `3xx` from SAP's endpoint is the answer, not followed.
868
+ - `noLog: true` — the connection writes exactly one line about the request,
869
+ `METHOD /path → STATUS (N bytes)` (or `→ no answer`), the path without its
870
+ query, host or user; the wires write none of their own, two fixed-word lines
871
+ aside (`CSRF token obtained`, and the cloud wire's
872
+ `The server published no logoff resource; sending the platform logoff`); the thrown error keeps SAP's answer.
873
+ - `stateless: true` — stateless on HTTP and RFC whatever the session mode, over
874
+ the caller's own `x-sap-adt-sessiontype` header in any letter case; the header
875
+ and the `sap-contextid` cookie are stripped; the session mode stays.
876
+ - `rawText: true` — only the body you receive as the final answer changes: a
877
+ success's `data`, or your error's `response.data`, is the exact text SAP
878
+ sent. Everything inside the connection — CSRF recovery, session verdicts,
879
+ replays, the credential provider, logs, the error's shape — reads what it
880
+ reads without the flag, on the shipped HTTP client; an injected `httpClient`
881
+ with defaults of its own (`transitional.forcedJSONParsing`, `responseType`)
882
+ owns how its bodies look. HTTP
883
+ decodes the declared charset when `TextDecoder` knows it, else UTF-8, the BOM
884
+ kept, non-fatally: an invalid byte reads as U+FFFD. `noLog` counts the bytes
885
+ that arrived. RFC: already the text of `MESSAGE_BODY`.
886
+
887
+ The whole contract, and why `noResend` exists: [README — Request options](../README.md#request-options-noresend-nolog-stateless).
854
888
 
855
889
  ### Starting Over
856
890
 
@@ -1172,7 +1206,9 @@ carries it; the wire never reads `config.username` or `config.password`.
1172
1206
  the provider.
1173
1207
 
1174
1208
  Nothing else is sent again: a failed request — the CSRF token fetch included
1175
- (21.0.0) — is its own error.
1209
+ (21.0.0) — is its own error. A request with `noResend: true` (25.1.0) gets none
1210
+ of these three resends, and follows no redirect: see
1211
+ [Request options](#request-options-noresend-nolog-stateless).
1176
1212
  - RFC takes logon parameters (a password, or SNC settings) on every conversation
1177
1213
  it opens, the session's own and each per-call one. RFC refuses TLS material,
1178
1214
  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.2.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.3.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",