@mcp-abap-adt/connection 24.0.0 → 25.0.1

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 (41) hide show
  1. package/CHANGELOG.md +92 -1
  2. package/README.md +63 -7
  3. package/dist/connection/AbstractAbapConnection.d.ts +3 -0
  4. package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
  5. package/dist/connection/AbstractAbapConnection.js +27 -9
  6. package/dist/connection/CloudHttpTransport.d.ts.map +1 -1
  7. package/dist/connection/CloudHttpTransport.js +2 -1
  8. package/dist/connection/CredentialAbapConnection.d.ts.map +1 -1
  9. package/dist/connection/CredentialAbapConnection.js +2 -1
  10. package/dist/connection/GenericWebSocketTransport.d.ts +6 -0
  11. package/dist/connection/GenericWebSocketTransport.d.ts.map +1 -1
  12. package/dist/connection/GenericWebSocketTransport.js +22 -10
  13. package/dist/connection/HttpTransport.d.ts +4 -4
  14. package/dist/connection/HttpTransport.d.ts.map +1 -1
  15. package/dist/connection/HttpTransport.js +22 -9
  16. package/dist/connection/IAdtTransport.d.ts +4 -3
  17. package/dist/connection/IAdtTransport.d.ts.map +1 -1
  18. package/dist/connection/RfcTransport.d.ts +6 -0
  19. package/dist/connection/RfcTransport.d.ts.map +1 -1
  20. package/dist/connection/RfcTransport.js +40 -71
  21. package/dist/connection/authErrors.d.ts +21 -5
  22. package/dist/connection/authErrors.d.ts.map +1 -1
  23. package/dist/connection/authErrors.js +29 -6
  24. package/dist/connection/createConnection.d.ts.map +1 -1
  25. package/dist/connection/createConnection.js +7 -0
  26. package/dist/connection/failureFacts.d.ts +100 -0
  27. package/dist/connection/failureFacts.d.ts.map +1 -0
  28. package/dist/connection/failureFacts.js +280 -0
  29. package/dist/connection/rfcConversation.d.ts +2 -0
  30. package/dist/connection/rfcConversation.d.ts.map +1 -1
  31. package/dist/connection/rfcConversation.js +16 -4
  32. package/dist/connection/withCheckRelogon.d.ts +8 -0
  33. package/dist/connection/withCheckRelogon.d.ts.map +1 -0
  34. package/dist/connection/withCheckRelogon.js +68 -0
  35. package/docs/INDEX.md +2 -0
  36. package/docs/MIGRATION-10.0.md +11 -1
  37. package/docs/MIGRATION-12.0.md +8 -0
  38. package/docs/MIGRATION-25.0.md +88 -0
  39. package/docs/MIGRATION-4.0.md +4 -0
  40. package/docs/USAGE.md +43 -18
  41. package/package.json +1 -1
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ /**
3
+ * What a thrown value may say about itself to a caller or a log line: its
4
+ * typed facts, never its text.
5
+ *
6
+ * A thrown value comes from outside the type system — the NW RFC SDK, axios,
7
+ * Node's sockets, a WebSocket library, a consumer's own code — and its message,
8
+ * stack, cause and fields carry whatever its author put there: a gateway's
9
+ * `host:port`, a URL with credentials in it, a request's headers. So nothing
10
+ * of it is quoted. What it says is read as facts, each checked where it is
11
+ * read — the RFC SDK's fields (`rfc`), a Node or axios error code (`code`),
12
+ * an HTTP status (`status`) — and said in fixed words built from those facts.
13
+ *
14
+ * Every read is of an own data property: no getter runs, and an object whose
15
+ * traps throw reads as having no facts.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.NO_FACTS = void 0;
19
+ exports.ownData = ownData;
20
+ exports.rfcErrorOf = rfcErrorOf;
21
+ exports.codeOf = codeOf;
22
+ exports.failureCode = failureCode;
23
+ exports.statusOf = statusOf;
24
+ exports.factsOf = factsOf;
25
+ exports.factWords = factWords;
26
+ exports.failureCopy = failureCopy;
27
+ exports.httpFailure = httpFailure;
28
+ exports.asArrived = asArrived;
29
+ const interfaces_adt_connection_1 = require("@mcp-abap-adt/interfaces-adt-connection");
30
+ /** An own data property of `source`, read without running a getter. */
31
+ function ownData(source, name) {
32
+ const descriptor = Object.getOwnPropertyDescriptor(source, name);
33
+ return descriptor !== undefined && 'value' in descriptor
34
+ ? descriptor.value
35
+ : undefined;
36
+ }
37
+ function isInteger(value) {
38
+ return typeof value === 'number' && Number.isInteger(value);
39
+ }
40
+ /**
41
+ * The SDK's error as fields, or `undefined` when `thrown` is not that shape.
42
+ *
43
+ * The one place an SDK error enters, so the one place it is checked: `key` and
44
+ * `codeString` own data properties holding strings, `group` and `code` own
45
+ * data properties holding integers, and `codeString` one of the closed list
46
+ * `RFC_RCS`. No getter runs, and an object whose traps throw reads as no
47
+ * shape. `name` and `message` are not read, and nothing is read out of a
48
+ * message.
49
+ */
50
+ function rfcErrorOf(thrown) {
51
+ if (typeof thrown !== 'object' || thrown === null)
52
+ return undefined;
53
+ try {
54
+ const key = ownData(thrown, 'key');
55
+ const group = ownData(thrown, 'group');
56
+ const code = ownData(thrown, 'code');
57
+ const codeString = ownData(thrown, 'codeString');
58
+ if (typeof key !== 'string' || !isInteger(group) || !isInteger(code)) {
59
+ return undefined;
60
+ }
61
+ // Compared with each listed name, so only a string can match: this is
62
+ // the check of `codeString`, and what is stored is the listed member.
63
+ const listed = interfaces_adt_connection_1.RFC_RCS.find((name) => name === codeString);
64
+ if (listed === undefined)
65
+ return undefined;
66
+ return Object.freeze({ key, group, code, codeString: listed });
67
+ }
68
+ catch {
69
+ return undefined;
70
+ }
71
+ }
72
+ /** The longest code read as one: Node's and axios's are far shorter. */
73
+ const CODE_LIMIT = 64;
74
+ /** `A`–`Z`, `0`–`9` and `_`: what a Node or axios error code is made of. */
75
+ function isCodeUnit(unit) {
76
+ return ((unit >= 0x41 && unit <= 0x5a) ||
77
+ (unit >= 0x30 && unit <= 0x39) ||
78
+ unit === 0x5f);
79
+ }
80
+ /**
81
+ * A code as a Node or axios error carries it (`ECONNREFUSED`,
82
+ * `ERR_BAD_REQUEST`, one of `ADT_SESSION_ERROR`): a non-empty string of
83
+ * upper-case ASCII letters, digits and `_` only, at most 64 of them. Anything
84
+ * else is no code — free text is never taken for one.
85
+ */
86
+ function codeOf(thrown) {
87
+ if (typeof thrown !== 'object' || thrown === null)
88
+ return undefined;
89
+ try {
90
+ const code = ownData(thrown, 'code');
91
+ if (typeof code !== 'string')
92
+ return undefined;
93
+ if (code.length === 0 || code.length > CODE_LIMIT)
94
+ return undefined;
95
+ for (let i = 0; i < code.length; i += 1) {
96
+ if (!isCodeUnit(code.charCodeAt(i)))
97
+ return undefined;
98
+ }
99
+ return code;
100
+ }
101
+ catch {
102
+ return undefined;
103
+ }
104
+ }
105
+ /** How deep a `cause` chain is followed for a code. */
106
+ const CAUSE_DEPTH = 4;
107
+ /**
108
+ * The code a thrown value carries: its own (`codeOf`), else the first one down
109
+ * its `cause` chain (own data properties, at most four deep) — a client that
110
+ * wraps a socket's failure (`fetch failed`, its cause `ECONNREFUSED`) says it
111
+ * there.
112
+ */
113
+ function failureCode(thrown) {
114
+ let current = thrown;
115
+ for (let depth = 0; depth <= CAUSE_DEPTH; depth += 1) {
116
+ const code = codeOf(current);
117
+ if (code !== undefined)
118
+ return code;
119
+ if (typeof current !== 'object' || current === null)
120
+ return undefined;
121
+ try {
122
+ current = ownData(current, 'cause');
123
+ }
124
+ catch {
125
+ return undefined;
126
+ }
127
+ }
128
+ return undefined;
129
+ }
130
+ /**
131
+ * The RFC SDK's fields a thrown value carries: its own shape (the SDK's
132
+ * error), else an `rfc` field of that shape (an error this package raised).
133
+ */
134
+ function rfcFieldsOf(thrown) {
135
+ const own = rfcErrorOf(thrown);
136
+ if (own !== undefined)
137
+ return own;
138
+ if (typeof thrown !== 'object' || thrown === null)
139
+ return undefined;
140
+ try {
141
+ return rfcErrorOf(ownData(thrown, 'rfc'));
142
+ }
143
+ catch {
144
+ return undefined;
145
+ }
146
+ }
147
+ /** An HTTP status: an integer from 100 to 599. */
148
+ function isStatus(value) {
149
+ return isInteger(value) && value >= 100 && value <= 599;
150
+ }
151
+ /**
152
+ * The HTTP status a thrown value carries: its own `status`, else its
153
+ * `response`'s — `undefined` when neither is an HTTP status.
154
+ */
155
+ function statusOf(thrown) {
156
+ if (typeof thrown !== 'object' || thrown === null)
157
+ return undefined;
158
+ try {
159
+ const own = ownData(thrown, 'status');
160
+ if (isStatus(own))
161
+ return own;
162
+ const response = ownData(thrown, 'response');
163
+ if (typeof response !== 'object' || response === null)
164
+ return undefined;
165
+ const status = ownData(response, 'status');
166
+ return isStatus(status) ? status : undefined;
167
+ }
168
+ catch {
169
+ return undefined;
170
+ }
171
+ }
172
+ /** Every fact `thrown` carries, each checked; none of its text. */
173
+ function factsOf(thrown) {
174
+ const rfc = rfcFieldsOf(thrown);
175
+ // An RFC error's `code` is the SDK's number, said by `rfc`; a code is a
176
+ // string, so it is not read twice.
177
+ const code = failureCode(thrown);
178
+ const status = statusOf(thrown);
179
+ const response = answerOf(thrown);
180
+ return {
181
+ ...(code !== undefined ? { code } : {}),
182
+ ...(status !== undefined ? { status } : {}),
183
+ ...(rfc !== undefined ? { rfc } : {}),
184
+ ...(response !== undefined ? { response } : {}),
185
+ };
186
+ }
187
+ /** The words for a value that carries no fact. */
188
+ exports.NO_FACTS = 'no code was given';
189
+ /**
190
+ * A thrown value in fixed words: its facts — the RFC return code, the code,
191
+ * the status — or `no code was given`. For a message and a log line.
192
+ */
193
+ function factWords(thrown) {
194
+ const facts = factsOf(thrown);
195
+ const parts = [];
196
+ if (facts.rfc !== undefined)
197
+ parts.push(facts.rfc.codeString);
198
+ if (facts.code !== undefined)
199
+ parts.push(facts.code);
200
+ if (facts.status !== undefined)
201
+ parts.push(`status ${facts.status}`);
202
+ return parts.length === 0 ? exports.NO_FACTS : parts.join(', ');
203
+ }
204
+ /**
205
+ * A copy of `thrown` a consumer may stringify or inspect: an `Error` named
206
+ * `WireFailure`, its message `The failure: <facts>`, and its facts as fields
207
+ * (`code`, `status`, `rfc`, SAP's answer as `response`). No message, stack,
208
+ * cause, config or other field of `thrown` is kept. `undefined` stays
209
+ * `undefined`.
210
+ */
211
+ function failureCopy(thrown) {
212
+ if (thrown === undefined)
213
+ return undefined;
214
+ const copy = new Error(`The failure: ${factWords(thrown)}`);
215
+ copy.name = 'WireFailure';
216
+ return Object.assign(copy, factsOf(thrown));
217
+ }
218
+ /**
219
+ * SAP's answer a rejection carries, copied field by field — `status`,
220
+ * `statusText`, `headers`, `data`, as SAP gave them — and nothing else of the
221
+ * response object (axios's holds the request and its config).
222
+ */
223
+ function answerOf(thrown) {
224
+ if (typeof thrown !== 'object' || thrown === null)
225
+ return undefined;
226
+ try {
227
+ const response = ownData(thrown, 'response');
228
+ if (typeof response !== 'object' || response === null)
229
+ return undefined;
230
+ const status = ownData(response, 'status');
231
+ if (!isInteger(status))
232
+ return undefined;
233
+ const statusText = ownData(response, 'statusText');
234
+ return {
235
+ status,
236
+ ...(typeof statusText === 'string' ? { statusText } : {}),
237
+ headers: ownData(response, 'headers'),
238
+ data: ownData(response, 'data'),
239
+ };
240
+ }
241
+ catch {
242
+ return undefined;
243
+ }
244
+ }
245
+ /**
246
+ * What an HTTP client's rejection becomes before it leaves the wire: an
247
+ * `Error` in fixed words with its facts and SAP's answer, and nothing else.
248
+ *
249
+ * axios's error carries the request's config — its `Authorization`, `Cookie`
250
+ * and CSRF headers among it — the Node request, and a message that names the
251
+ * host and port it could not reach. None of that is kept. What is: SAP's
252
+ * answer when there was one (`response`, `status`; the message axios gives it,
253
+ * `Request failed with status code <n>`, built from the status), else the
254
+ * code (`ECONNREFUSED`, `ECONNABORTED`, …) and `The request failed: <code>`.
255
+ */
256
+ function httpFailure(thrown) {
257
+ const response = answerOf(thrown);
258
+ const code = failureCode(thrown);
259
+ const error = new Error(response !== undefined
260
+ ? `Request failed with status code ${response.status}`
261
+ : `The request failed: ${code ?? 'it got no answer'}`);
262
+ const failure = Object.assign(error, code !== undefined ? { code } : {}, response !== undefined ? { status: response.status, response } : {});
263
+ ARRIVED.set(failure, thrown);
264
+ return failure;
265
+ }
266
+ /**
267
+ * The value each `httpFailure` was made from, for the provider alone: what a
268
+ * provider reads is the wire's error as it arrived (`IAuthRejection.error`).
269
+ * Module-private, so nothing outside this package reaches it.
270
+ */
271
+ const ARRIVED = new WeakMap();
272
+ /**
273
+ * The wire's error as it arrived: the value an `httpFailure` was made from,
274
+ * or `value` itself. For `IAuthRejection.error` only — never for a consumer.
275
+ */
276
+ function asArrived(value) {
277
+ return typeof value === 'object' && value !== null && ARRIVED.has(value)
278
+ ? ARRIVED.get(value)
279
+ : value;
280
+ }
@@ -59,6 +59,8 @@ export type RfcAddress = RfcConnectionParams | RfcMessageServerParams;
59
59
  * The address only: no username or password is read from the config.
60
60
  */
61
61
  export declare function rfcParamsFrom(config: ISapRfcConfig): RfcAddress;
62
+ /** Whether `thrown` is one of this module's own errors, in fixed words. */
63
+ export declare function isFactoryOwnWords(thrown: unknown): boolean;
62
64
  /**
63
65
  * The factory `RfcTransport` asks for: the logon parameters the provider wrote
64
66
  * for this open go in, spread over the address the config states; nothing
@@ -1 +1 @@
1
- {"version":3,"file":"rfcConversation.d.ts","sourceRoot":"","sources":["../../src/connection/rfcConversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE9E,qEAAqE;AACrE,MAAM,MAAM,UAAU,GAAG,mBAAmB,GAAG,sBAAsB,CAAC;AAEtE;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAiB/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,GACpB,sBAAsB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAwBxD"}
1
+ {"version":3,"file":"rfcConversation.d.ts","sourceRoot":"","sources":["../../src/connection/rfcConversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE9E,qEAAqE;AACrE,MAAM,MAAM,UAAU,GAAG,mBAAmB,GAAG,sBAAsB,CAAC;AAEtE;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAiB/D;AAQD,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAE1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,GACpB,sBAAsB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CA0BxD"}
@@ -14,6 +14,7 @@
14
14
  */
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.rfcParamsFrom = rfcParamsFrom;
17
+ exports.isFactoryOwnWords = isFactoryOwnWords;
17
18
  exports.rfcConversationFrom = rfcConversationFrom;
18
19
  /**
19
20
  * The address the config states, in the SDK's terms — read as given, never
@@ -42,6 +43,15 @@ function rfcParamsFrom(config) {
42
43
  };
43
44
  return { mshost: config.mshost, group: config.group, ...service, ...logon };
44
45
  }
46
+ /**
47
+ * The errors this module throws in its own fixed words, which `RfcTransport`
48
+ * passes on as they are: they quote nothing a thrown value said.
49
+ */
50
+ const OWN_WORDS = new WeakSet();
51
+ /** Whether `thrown` is one of this module's own errors, in fixed words. */
52
+ function isFactoryOwnWords(thrown) {
53
+ return typeof thrown === 'object' && thrown !== null && OWN_WORDS.has(thrown);
54
+ }
45
55
  /**
46
56
  * The factory `RfcTransport` asks for: the logon parameters the provider wrote
47
57
  * for this open go in, spread over the address the config states; nothing
@@ -64,10 +74,12 @@ function rfcConversationFrom(config) {
64
74
  // SDK installed on the machine, and most consumers travel over HTTP.
65
75
  Client = require('@mcp-abap-adt/sap-rfc-lite').Client;
66
76
  }
67
- catch (error) {
68
- throw new Error('@mcp-abap-adt/sap-rfc-lite is not available. To take the RFC wire, ' +
69
- 'install the SAP NW RFC SDK and run: npm install @mcp-abap-adt/sap-rfc-lite. ' +
70
- `Details: ${error instanceof Error ? error.message : String(error)}`);
77
+ catch {
78
+ // The loader's words are not quoted: they name paths on this machine.
79
+ const missing = new Error('@mcp-abap-adt/sap-rfc-lite is not available. To take the RFC wire, ' +
80
+ 'install the SAP NW RFC SDK and run: npm install @mcp-abap-adt/sap-rfc-lite.');
81
+ OWN_WORDS.add(missing);
82
+ throw missing;
71
83
  }
72
84
  return new Client({ ...params, ...logon });
73
85
  };
@@ -0,0 +1,8 @@
1
+ import type { CreatedConnection } from './createConnection.js';
2
+ /**
3
+ * The syntax-check POST is a read. A 403 explicitly rejecting its CSRF token
4
+ * means SAP did not run it. Retry on a separate session only when that same
5
+ * response proved the original session gone.
6
+ */
7
+ export declare function withCheckRelogon<TConnection extends CreatedConnection>(connection: TConnection, fresh: () => TConnection): TConnection;
8
+ //# sourceMappingURL=withCheckRelogon.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withCheckRelogon = withCheckRelogon;
4
+ const interfaces_adt_connection_1 = require("@mcp-abap-adt/interfaces-adt-connection");
5
+ const AbstractAbapConnection_js_1 = require("./AbstractAbapConnection.js");
6
+ const IAdtTransport_js_1 = require("./IAdtTransport.js");
7
+ const statefulRequest_js_1 = require("./statefulRequest.js");
8
+ /**
9
+ * The syntax-check POST is a read. A 403 explicitly rejecting its CSRF token
10
+ * means SAP did not run it. Retry on a separate session only when that same
11
+ * response proved the original session gone.
12
+ */
13
+ function withCheckRelogon(connection, fresh) {
14
+ const send = connection.makeAdtRequest.bind(connection);
15
+ const disconnect = connection.disconnect.bind(connection);
16
+ const pending = new Set();
17
+ let closing = false;
18
+ connection.disconnect = async () => {
19
+ closing = true;
20
+ await Promise.all([disconnect(), ...Array.from(pending, (stop) => stop())]);
21
+ };
22
+ connection.makeAdtRequest = async (request) => {
23
+ const eligible = request.method.toUpperCase() === 'POST' &&
24
+ request.url.split('?', 1)[0] === '/sap/bc/adt/checkruns' &&
25
+ typeof request.data === 'string' &&
26
+ connection.getSessionMode() === 'stateless' &&
27
+ !connection.isInCriticalSection() &&
28
+ !(0, statefulRequest_js_1.isStatefulRequest)({
29
+ url: request.url,
30
+ method: request.method,
31
+ headers: request.headers,
32
+ });
33
+ try {
34
+ return await send(request);
35
+ }
36
+ catch (error) {
37
+ if (!eligible || closing || !(0, AbstractAbapConnection_js_1.carriesSessionLost)(error))
38
+ throw error;
39
+ const refusal = (0, IAdtTransport_js_1.refusalOf)(error);
40
+ if (refusal?.status !== 403 ||
41
+ typeof refusal.data !== 'string' ||
42
+ !refusal.data.includes('CSRF token validation failed'))
43
+ throw error;
44
+ const replacement = fresh();
45
+ let stopped;
46
+ const stop = () => (stopped ??= replacement.disconnect());
47
+ pending.add(stop);
48
+ try {
49
+ await replacement.connect();
50
+ if (closing)
51
+ throw error;
52
+ const result = await replacement.makeAdtRequest(request);
53
+ return { ...result, sessionLost: interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED };
54
+ }
55
+ finally {
56
+ // Disconnect waits until the logoff is written, as for any session.
57
+ // A caller closing during recovery shares this same disconnect.
58
+ try {
59
+ await stop();
60
+ }
61
+ finally {
62
+ pending.delete(stop);
63
+ }
64
+ }
65
+ }
66
+ };
67
+ return connection;
68
+ }
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-25.0.md # security: a failure carries typed facts, never a thrown value's text; the HTTP error is not axios's; AuthRefusedError.cause a WireFailure copy
18
19
  │ ├── MIGRATION-24.0.md # interfaces-adt-connection 5: IAbapConnection.makeAdtRequest takes no type argument
19
20
  │ ├── MIGRATION-23.0.md # a stateless request keeps its answer when the session was replaced: sessionLost
20
21
  │ ├── MIGRATION-22.0.md # RFC: the session lost after a connection-ending error; rfc fields; the passport
@@ -54,6 +55,7 @@ mcp-abap-connection/
54
55
  - 🧭 [Scope](./SCOPE.md) - What this package answers for, and only that
55
56
 
56
57
  ### Upgrading
58
+ - 🚚 [Migrating to 25.0.0](./MIGRATION-25.0.md) - security: errors and log lines carry typed facts (`code`, `status`, `rfc`, SAP's answer as `response`), never a thrown value's text or a request config; the HTTP failure is not the axios error; `AuthRefusedError.cause` is a `WireFailure` copy
57
59
  - 🚚 [Migrating to 24.0.0](./MIGRATION-24.0.md) - on `@mcp-abap-adt/interfaces-adt-connection` 5: `IAbapConnection` / `AbapConnection`'s `makeAdtRequest` takes no type argument; narrow `data` from `unknown`
58
60
  - 🚚 [Migrating to 21.0.0](./MIGRATION-21.0.md) - the CSRF token fetch asks once: no retry, no delay; the retry constants, context fields and parameters are removed
59
61
  - 🚚 [Migrating to 20.0.0](./MIGRATION-20.0.md) - an RFC config is an `ISapRfcConfig` stating its address, `client` and `language`: no URL, no defaults, no `SAP_SYSNR`; `getBaseUrl()` may answer `undefined`; HTTP transports take `baseUrl`
@@ -135,6 +135,14 @@ the provider's words, or the fixed "refused again" reason after its Ok — with
135
135
  SDK's error only in `cause`. A caller that matched the SDK error to tell an
136
136
  unreachable system from a refused one reads `cause` now.
137
137
 
138
+ > **Since 25.0.0** `AuthRefusedError.cause` is a copy, not the wire's error: an
139
+ > `Error` named `WireFailure` whose fields carry the facts — `code`, `status`,
140
+ > SAP's answer as `response`, and the RFC SDK's fields as `rfc`
141
+ > (`cause.rfc.codeString`, e.g. `RFC_COMMUNICATION_FAILURE`); its message is
142
+ > `The failure: <facts>`, never the SDK's text. The provider still receives the
143
+ > original, as `IAuthRejection.error`. See [MIGRATION-25.0.md](./MIGRATION-25.0.md) and the
144
+ > README, "What a failure carries".
145
+
138
146
  ## 5. Catch `AuthRefusedError`
139
147
 
140
148
  Before, a refused credential arrived as whatever the wire threw — an axios error
@@ -179,7 +187,9 @@ class AuthRefusedError extends Error {
179
187
  - A provider that throws is treated as refusing with the reason "the credential
180
188
  provider failed" and the throw as `cause`.
181
189
  - A `403` is never put to the provider and never becomes an `AuthRefusedError`; it
182
- reaches you unchanged, as before.
190
+ reaches you unchanged, as before. (Since 25.0.0 an HTTP failure is not
191
+ axios's error but an `Error` carrying SAP's answer as `response`, `status`
192
+ and `code` — no `config`, no `request`.)
183
193
 
184
194
  Inside a critical section (`beginCriticalSection()`), a mutation refused with a
185
195
  401 while a CSRF token is cached is no longer moved to a new session: it goes to
@@ -102,6 +102,14 @@ through `classifyOutcome`:
102
102
  A provider that throws is `provider-threw` too, with the throw as `cause`, as
103
103
  in 11.x.
104
104
 
105
+ > **Since 25.0.0** `AuthRefusedError.cause` is a copy, not the wire's error or the throw: an
106
+ > `Error` named `WireFailure` whose fields carry the facts — `code`, `status`,
107
+ > SAP's answer as `response`, and the RFC SDK's fields as `rfc`
108
+ > (`cause.rfc.codeString`, e.g. `RFC_COMMUNICATION_FAILURE`); its message is
109
+ > `The failure: <facts>`, never the SDK's text. The provider still receives the
110
+ > original, as `IAuthRejection.error`. See [MIGRATION-25.0.md](./MIGRATION-25.0.md) and the
111
+ > README, "What a failure carries".
112
+
105
113
  ## A logon target of your own
106
114
 
107
115
  A wire of your own hands the provider an `ILogonTarget`. Its refusals must be
@@ -0,0 +1,88 @@
1
+ # Migration to 25.0
2
+
3
+ 25.0.0 is a security release. No error the connection hands you, and no line
4
+ it logs, carries a thrown value's text or a request's config. A thrown value's
5
+ text names hosts and ports: axios's `connect ECONNREFUSED <host>:<port>`, and
6
+ the RFC SDK's partner. axios's error also holds the request's config, with its
7
+ `Authorization`, `Cookie` and CSRF headers. On every wire, a failure now
8
+ reaches you by its typed facts and in fixed words.
9
+
10
+ ## What changed
11
+
12
+ - **An HTTP failure is not the axios error.** The HTTP wire hands up an
13
+ `Error` that carries:
14
+ - SAP's answer as `response` (`status`, `statusText`, `headers`, `data`, as
15
+ SAP gave them);
16
+ - `status`;
17
+ - `code` (`ECONNREFUSED`, `ECONNABORTED`, `ERR_BAD_REQUEST`, …): its own,
18
+ else the first one down its `cause` chain.
19
+
20
+ Its message is `Request failed with status code <n>`, or, when there was no
21
+ answer, `The request failed: <code>`. It has no `config`, no `request`, no
22
+ `isAxiosError` and no `cause`.
23
+ - **`AuthRefusedError.cause` is a copy.** It is an `Error` named
24
+ `WireFailure`, its message `The failure: <facts>`. Its fields are `code`,
25
+ `status`, `rfc` (the RFC SDK's `key`, `group`, `code`, `codeString`) and
26
+ SAP's answer as `response`. Its type is `FailureCopy | undefined` (was
27
+ `unknown`). It is never the original object. The provider still receives
28
+ the original as `IAuthRejection.error`.
29
+ - **A `WireLogonError` that leaves `connect()` or `makeAdtRequest()`** carries
30
+ such a copy as its `cause`.
31
+ - **An RFC failure is worded from `rfc`:**
32
+ `RFC call to SADT_REST_RFC_ENDPOINT failed: <codeString>`, or
33
+ `… failed: the SDK did not name the failure`. `rfc` is unchanged.
34
+ - **The WebSocket transport** hands its error handlers `<words>: <facts>`, with
35
+ the facts as fields.
36
+ - **Log lines** say a failure's facts, or `no code was given`.
37
+
38
+ A transport you write yourself (`IAdtTransport`) hands up what it throws. A
39
+ failure that is not the credential's passes through the connection as your
40
+ wire raised it.
41
+
42
+ ## Who is affected
43
+
44
+ You are affected if your code does any of the following with an error the
45
+ connection threw:
46
+
47
+ - reads `error.config` or `error.request`;
48
+ - tests `error.isAxiosError`, `axios.isAxiosError(error)` or
49
+ `error instanceof AxiosError`;
50
+ - compares `AuthRefusedError.cause` with an error it holds
51
+ (`cause === original`), or reads fields of the cause other than `code`,
52
+ `status`, `rfc` and `response`;
53
+ - reads a failure from its message: the SDK's or axios's words are gone.
54
+
55
+ Code that reads `error.response` (its status, headers or body), `error.status`,
56
+ `error.code` or `error.rfc` is not affected.
57
+
58
+ ## What to do
59
+
60
+ Read the facts, never the axios error:
61
+
62
+ ```typescript
63
+ import { AuthRefusedError } from "@mcp-abap-adt/connection";
64
+
65
+ function describe(error: unknown): string {
66
+ if (error instanceof AuthRefusedError) {
67
+ // The provider's words; the cause is the wire's failure, by its facts.
68
+ const status = error.cause?.status;
69
+ return status === undefined
70
+ ? error.message
71
+ : `${error.message} (status ${status})`;
72
+ }
73
+ if (typeof error === "object" && error !== null && "response" in error) {
74
+ // SAP's answer, as SAP gave it.
75
+ const response = error.response;
76
+ if (typeof response === "object" && response !== null && "status" in response) {
77
+ return `SAP answered ${String(response.status)}`;
78
+ }
79
+ }
80
+ if (typeof error === "object" && error !== null && "code" in error) {
81
+ return `the request failed: ${String(error.code)}`;
82
+ }
83
+ return "the request failed";
84
+ }
85
+ ```
86
+
87
+ For an RFC failure read `rfc.codeString`, on the error or on an
88
+ `AuthRefusedError`'s `cause`.
@@ -10,6 +10,10 @@ It said that for a **401** and for a **403** alike, and it threw the original `A
10
10
  along with the status and the body. Now the server's error reaches the caller unchanged, and only
11
11
  a 401 is treated as a credential problem.
12
12
 
13
+ > **Since 25.0.0** the error is not the `AxiosError` itself but an `Error` carrying SAP's answer
14
+ > as `response` (status, reason, headers, body), `status` and `code` — no `config`, no `request`.
15
+ > `error.response?.status`, as below, reads it the same way.
16
+
13
17
  ## What breaks, and what to do
14
18
 
15
19
  ### 1. That message is gone