@mcp-abap-adt/connection 23.0.0 → 25.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +100 -1
  2. package/README.md +59 -10
  3. package/dist/connection/AbstractAbapConnection.d.ts +1 -0
  4. package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
  5. package/dist/connection/AbstractAbapConnection.js +29 -12
  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/failureFacts.d.ts +100 -0
  25. package/dist/connection/failureFacts.d.ts.map +1 -0
  26. package/dist/connection/failureFacts.js +280 -0
  27. package/dist/connection/rfcConversation.d.ts +2 -0
  28. package/dist/connection/rfcConversation.d.ts.map +1 -1
  29. package/dist/connection/rfcConversation.js +16 -4
  30. package/docs/INDEX.md +4 -0
  31. package/docs/MIGRATION-10.0.md +11 -1
  32. package/docs/MIGRATION-12.0.md +8 -0
  33. package/docs/MIGRATION-24.0.md +42 -0
  34. package/docs/MIGRATION-25.0.md +88 -0
  35. package/docs/MIGRATION-4.0.md +4 -0
  36. package/docs/USAGE.md +29 -17
  37. package/package.json +2 -2
@@ -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
  };
package/docs/INDEX.md CHANGED
@@ -15,6 +15,8 @@ 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
19
+ │ ├── MIGRATION-24.0.md # interfaces-adt-connection 5: IAbapConnection.makeAdtRequest takes no type argument
18
20
  │ ├── MIGRATION-23.0.md # a stateless request keeps its answer when the session was replaced: sessionLost
19
21
  │ ├── MIGRATION-22.0.md # RFC: the session lost after a connection-ending error; rfc fields; the passport
20
22
  │ ├── MIGRATION-21.0.md # the CSRF token fetch asks once: no retry, no delay
@@ -53,6 +55,8 @@ mcp-abap-connection/
53
55
  - 🧭 [Scope](./SCOPE.md) - What this package answers for, and only that
54
56
 
55
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
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`
56
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
57
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`
58
62
  - 🚚 [Migrating to 18.0.0](./MIGRATION-18.0.md) - `rfcParamsFrom` returns `RfcAddress`; RFC through a message server and a logon group
@@ -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,42 @@
1
+ # Migration to 24.0
2
+
3
+ 24.0.0 moves the shared contract to `@mcp-abap-adt/interfaces-adt-connection`
4
+ ^5.0.0. Nothing changes at run time.
5
+
6
+ ## What changed
7
+
8
+ - **`IAbapConnection.makeAdtRequest` takes no type argument.** Version 5
9
+ declares `makeAdtRequest(options): Promise<IAdtWireResponse>`; the answer's
10
+ `data` is `unknown`. This package's `AbapConnection` is an alias for
11
+ `IAbapConnection`, so it changed with it.
12
+ - **The connectors are unchanged.** `AdtOnPremConnector` and
13
+ `AdtCloudConnector` keep their own `makeAdtRequest` signature, and each is
14
+ assignable to version 5's `IAbapConnection`.
15
+
16
+ ## Who is affected
17
+
18
+ Code that holds a value typed `IAbapConnection` or `AbapConnection` and calls
19
+ `makeAdtRequest<T>(…)` with a type argument. It no longer compiles. Code that
20
+ calls it without a type argument, or holds a connector type, is not affected.
21
+
22
+ ## What to do
23
+
24
+ Drop the type argument and narrow `data` from `unknown` before using it:
25
+
26
+ ```typescript
27
+ import type {
28
+ IAbapConnection,
29
+ IAbapRequestOptions,
30
+ } from "@mcp-abap-adt/interfaces-adt-connection";
31
+
32
+ async function readXml(
33
+ connection: IAbapConnection,
34
+ options: IAbapRequestOptions,
35
+ ): Promise<string> {
36
+ const response = await connection.makeAdtRequest(options);
37
+ if (typeof response.data !== "string") {
38
+ throw new Error("expected a text body");
39
+ }
40
+ return response.data;
41
+ }
42
+ ```
@@ -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
package/docs/USAGE.md CHANGED
@@ -275,8 +275,8 @@ them is refused with `ADT_NOT_CONNECTED`.
275
275
  ### GET Request
276
276
 
277
277
  ```typescript
278
- // The body is XML: name its type, or the answer's `data` is `unknown`.
279
- const packages = await connection.makeAdtRequest<string>({
278
+ // The answer's `data` is `unknown`: read the XML body after checking it is text.
279
+ const packages = await connection.makeAdtRequest({
280
280
  method: 'GET',
281
281
  url: '/sap/bc/adt/repository/nodestructure',
282
282
  params: {
@@ -286,6 +286,8 @@ const packages = await connection.makeAdtRequest<string>({
286
286
  },
287
287
  timeout: 0,
288
288
  });
289
+ if (typeof packages.data !== 'string') throw new Error('expected an XML body');
290
+ const xml = packages.data;
289
291
  ```
290
292
 
291
293
  ### POST Request (Create Object)
@@ -707,7 +709,7 @@ on whether it is stateful (since 23.0.0):
707
709
  gave it is valid and is returned as it came — a success resolves, a refusal
708
710
  rejects as itself — with `sessionLost: 'ADT_SESSION_REPLACED'` on that
709
711
  response or on that error (`IAdtWireResponse`, `IAbapConnectionError`,
710
- `@mcp-abap-adt/interfaces-adt-connection` ^4.2.0). Only the request whose own
712
+ `@mcp-abap-adt/interfaces-adt-connection`, since 4.2.0). Only the request whose own
711
713
  answer showed the replacement carries it. Nothing is sent again for it: no
712
714
  CSRF retry, no credential renewal. The session is lost before the answer
713
715
  reaches you.
@@ -994,10 +996,9 @@ import type { AbapRequestOptions } from '@mcp-abap-adt/connection';
994
996
  import type { IAdtWireResponse } from '@mcp-abap-adt/interfaces-adt-connection';
995
997
  interface AbapConnection {
996
998
  connect(): Promise<void>; // REQUIRED before any request
997
- // An answer whose type is not named is `unknown` (interfaces-adt-connection 2).
998
- makeAdtRequest<T = unknown, D = unknown>(
999
- options: AbapRequestOptions,
1000
- ): Promise<IAdtWireResponse<T, D>>;
999
+ // The answer's `data` is `unknown`; the caller names no type for it
1000
+ // (interfaces-adt-connection 5).
1001
+ makeAdtRequest(options: AbapRequestOptions): Promise<IAdtWireResponse>;
1001
1002
  getBaseUrl(): Promise<string | undefined>; // undefined over RFC: no HTTP origin
1002
1003
  setSessionType(type: "stateless" | "stateful"): void;
1003
1004
  getSessionId(): string | null; // client-side conversation id
@@ -1163,15 +1164,21 @@ carries it; the wire never reads `config.username` or `config.password`.
1163
1164
  and a provider that writes no logon parameters (a bearer token) cannot log on
1164
1165
  over RFC: the open fails, the provider is asked, and you get its refusal.
1165
1166
  - A failed RFC open is thrown as `WireLogonError` with the SDK's own error as
1166
- `cause`, so a provider can read the SDK's `key` and message.
1167
+ `cause`, so a provider can read the SDK's `key` and message. Its own message
1168
+ is fixed words (`The logon failed`, with the status when the wire has one),
1169
+ never the cause's text (25.0.0).
1167
1170
  - **A failed RFC call carries `rfc`** (22.0.0): `{ key, group, code,
1168
1171
  codeString }` (`IRfcErrorInfo`, `codeString` one of `RFC_RCS`, both from
1169
1172
  `@mcp-abap-adt/interfaces-adt-connection`), checked once where the wire
1170
1173
  receives the SDK's error — own data properties only, nothing read out of a
1171
1174
  message. An error the SDK did not name carries no `rfc`. `rfc` is carried on
1172
- every conversation, stateful or not. The message is the call's
1173
- (`RFC call to SADT_REST_RFC_ENDPOINT failed: …`, ending in fixed words when
1174
- the thrown value cannot be described) and the top-level `code` is not set —
1175
+ every conversation, stateful or not. The message is the call's, in fixed
1176
+ words built from `rfc` — `RFC call to SADT_REST_RFC_ENDPOINT failed:
1177
+ <codeString>`, or `… failed: the SDK did not name the failure` without `rfc`
1178
+ (25.0.0; before, it quoted the SDK's text, which names the partner's
1179
+ `host:port`, the time and the kernel's source module). The connection's log
1180
+ lines about a failed call, close or reset say the same words. The top-level
1181
+ `code` is not set —
1175
1182
  except when the error ended the stateful conversation: then the message is
1176
1183
  the session-lost one ("The RFC conversation that carried this connection's
1177
1184
  SAP session has ended; …") and `code` is `ADT_SESSION_REPLACED`, the instance
@@ -1310,7 +1317,7 @@ token the provider renewed is on the very next attempt.
1310
1317
  | answer | what happens |
1311
1318
  |---|---|
1312
1319
  | **403** "CSRF token validation failed", or a **401** to a mutation that holds no CSRF token yet | the wire's own CSRF recovery: a token fetched in the same session (its cookies kept) and one resend. None of this discards the session or opens another |
1313
- | any other **401** — a mutation's with a CSRF token cached included — or a logon the system refused | put to `provider.rejected({ at, status?, error })`. On Ok the request is authorized again and sent **once more**, in the same session; on no, `AuthRefusedError` carrying SAP's 401 as its cause |
1320
+ | any other **401** — a mutation's with a CSRF token cached included — or a logon the system refused | put to `provider.rejected({ at, status?, error })`. On Ok the request is authorized again and sent **once more**, in the same session; on no, `AuthRefusedError` whose cause is a copy of SAP's 401 (`status`) |
1314
1321
  | the same refusal after an Ok | the verdict. The provider is not asked again — asking would invite a second renewal — and you get an `AuthRefusedError` saying the credential was refused again after the provider renewed it |
1315
1322
  | **403** | propagates untouched, never put to the provider. The server authenticated the caller and refused the action anyway, so a new credential is the same caller — usually the body names the authorization object |
1316
1323
  | anything else | untouched |
@@ -1355,8 +1362,9 @@ try {
1355
1362
  if (error instanceof AuthRefusedError) {
1356
1363
  // error.refusal is an IAuthProviderError: decide on its kind and facts;
1357
1364
  // .reason / .hint are the words to show (the message is `reason — hint`).
1358
- // error.at is 'prepare' | 'logon' | 'request'; error.cause is the provider's
1359
- // throw when it threw, else the wire's error.
1365
+ // error.at is 'prepare' | 'logon' | 'request'; error.cause is a copy
1366
+ // (`WireFailure`: code, status, rfc) of the provider's throw when it threw,
1367
+ // else of the wire's error.
1360
1368
  if (error.refusal.kind === 'credential-refused') {
1361
1369
  // the credential itself was refused
1362
1370
  }
@@ -1366,16 +1374,20 @@ try {
1366
1374
  }
1367
1375
  ```
1368
1376
 
1369
- `refusal` is the provider's, `cause` is the error the wire raised as it arrived,
1377
+ `refusal` is the provider's, `cause` says the error the wire raised by its facts,
1370
1378
  so a network failure stays visible even when a provider words it as a credential
1371
- problem. A refusal is an `IAuthProviderError` minted by `@mcp-abap-adt/auth-errors`
1379
+ problem: an `Error` named `WireFailure`, its message `The failure: <facts>`, with
1380
+ `code`, `status`, `rfc` and SAP's answer (`response`) as fields — never the value itself, whose text may
1381
+ name a host and whose fields may hold the request's credential headers
1382
+ (25.0.0). The provider was handed the value as it arrived
1383
+ (`IAuthRejection.error`). A refusal is an `IAuthProviderError` minted by `@mcp-abap-adt/auth-errors`
1372
1384
  — frozen, with a `kind` and `facts` from closed allowlists; relay it, never copy
1373
1385
  it. Every provider answer is re-checked with `classifyOutcome`: a minted refusal
1374
1386
  passes as the same object, one from another copy of `auth-errors` is rebuilt,
1375
1387
  and anything else — a plain `{ reason }` from a JavaScript provider, a value that
1376
1388
  is no outcome — becomes `connection` / `provider-threw`, "the credential provider
1377
1389
  failed", its text in no message. A provider that throws is the same refusal,
1378
- with the throw as the cause.
1390
+ with a copy of the throw as the cause.
1379
1391
 
1380
1392
  The connection's own refusals:
1381
1393