@mcp-abap-adt/connection 20.1.0 → 22.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.
@@ -57,6 +57,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
57
57
  exports.RfcTransport = void 0;
58
58
  const node_crypto_1 = require("node:crypto");
59
59
  const auth_errors_1 = require("@mcp-abap-adt/auth-errors");
60
+ const interfaces_adt_connection_1 = require("@mcp-abap-adt/interfaces-adt-connection");
60
61
  const authErrors_js_1 = require("./authErrors.js");
61
62
  const statefulRequest_js_1 = require("./statefulRequest.js");
62
63
  /**
@@ -146,19 +147,119 @@ const EXCEPTION_STATUS = {
146
147
  ExceptionNotSupported: { code: 501, text: 'Not Implemented' },
147
148
  ExceptionConflict: { code: 409, text: 'Conflict' },
148
149
  };
150
+ const TYPE_OPEN = '<exc:type';
151
+ const TYPE_CLOSE = '</exc:type>';
152
+ /**
153
+ * The text of the first `<exc:type …>TEXT</exc:type>` in `body`: from a
154
+ * `<exc:type`, the first `>` after it opens the text, which runs to the next
155
+ * `<` and counts only when it is not empty and that `<` begins `</exc:type>`.
156
+ *
157
+ * Linear: every search starts where the previous one ended, so the body is
158
+ * read once, left to right. A failed candidate need not be followed by the next
159
+ * `<exc:type` after it: one that begins before its `>` holds no `>` of its own
160
+ * in its first nine characters, so it meets the same `>` and the same `<` and
161
+ * fails the same way; and none begins between that `>` and the `<` that ended
162
+ * the text, since a candidate begins with `<`. The next candidate is searched
163
+ * from that `<`. With no `<` after the `>`, no candidate is left.
164
+ */
165
+ function exceptionType(body) {
166
+ let open = body.indexOf(TYPE_OPEN);
167
+ while (open >= 0) {
168
+ const tagEnd = body.indexOf('>', open + TYPE_OPEN.length);
169
+ if (tagEnd < 0)
170
+ return undefined;
171
+ const textEnd = body.indexOf('<', tagEnd + 1);
172
+ if (textEnd < 0)
173
+ return undefined;
174
+ if (textEnd > tagEnd + 1 && body.startsWith(TYPE_CLOSE, textEnd)) {
175
+ return body.slice(tagEnd + 1, textEnd);
176
+ }
177
+ open = body.indexOf(TYPE_OPEN, textEnd);
178
+ }
179
+ return undefined;
180
+ }
181
+ /**
182
+ * The status an exception document stands for. A type is looked up only as an
183
+ * own key of `EXCEPTION_STATUS`: `toString`, `constructor` and the other
184
+ * members every object inherits name no status, and give 500 as an unknown
185
+ * type does.
186
+ */
149
187
  function statusFromExceptionXml(body) {
150
- const type = /<exc:type[^>]*>([^<]+)<\/exc:type>/.exec(body)?.[1]?.trim();
151
- return ((type ? EXCEPTION_STATUS[type] : undefined) ?? {
152
- code: 500,
153
- text: 'Internal Server Error',
154
- });
188
+ const type = exceptionType(body)?.trim();
189
+ return type && Object.hasOwn(EXCEPTION_STATUS, type)
190
+ ? EXCEPTION_STATUS[type]
191
+ : { code: 500, text: 'Internal Server Error' };
155
192
  }
193
+ /** An own data property of `source`, read without running a getter. */
194
+ function ownData(source, name) {
195
+ const descriptor = Object.getOwnPropertyDescriptor(source, name);
196
+ return descriptor !== undefined && 'value' in descriptor
197
+ ? descriptor.value
198
+ : undefined;
199
+ }
200
+ function isInteger(value) {
201
+ return typeof value === 'number' && Number.isInteger(value);
202
+ }
203
+ /**
204
+ * The SDK's error as fields, or `undefined` when `thrown` is not that shape.
205
+ *
206
+ * The one place an SDK error enters, so the one place it is checked: `key` and
207
+ * `codeString` own data properties holding strings, `group` and `code` own
208
+ * data properties holding integers, and `codeString` one of the closed list
209
+ * `RFC_RCS`. No getter runs, and an object whose traps throw reads as no
210
+ * shape. `name` and `message` are not read, and nothing is read out of a
211
+ * message.
212
+ */
213
+ function rfcErrorOf(thrown) {
214
+ if (typeof thrown !== 'object' || thrown === null)
215
+ return undefined;
216
+ try {
217
+ const key = ownData(thrown, 'key');
218
+ const group = ownData(thrown, 'group');
219
+ const code = ownData(thrown, 'code');
220
+ const codeString = ownData(thrown, 'codeString');
221
+ if (typeof key !== 'string' || !isInteger(group) || !isInteger(code)) {
222
+ return undefined;
223
+ }
224
+ // Compared with each listed name, so only a string can match: this is
225
+ // the check of `codeString`, and what is stored is the listed member.
226
+ const listed = interfaces_adt_connection_1.RFC_RCS.find((name) => name === codeString);
227
+ if (listed === undefined)
228
+ return undefined;
229
+ return Object.freeze({ key, group, code, codeString: listed });
230
+ }
231
+ catch {
232
+ return undefined;
233
+ }
234
+ }
235
+ /**
236
+ * What a failed call throws: an `Error` with today's words, and the SDK's
237
+ * fields as `rfc` when the SDK named the failure. The top-level `code` is not
238
+ * set: `rfc` does not change what it means.
239
+ */
240
+ function rfcCallError(text, rfc) {
241
+ const error = new Error(text);
242
+ return rfc === undefined ? error : Object.assign(error, { rfc });
243
+ }
244
+ /** Words a value is described by when describing it throws. */
245
+ const UNDESCRIBABLE = 'the failure could not be described';
246
+ /**
247
+ * A thrown value in words, for a message and a log line. It never throws:
248
+ * `instanceof` runs a Proxy's trap, `message` may be a getter, and
249
+ * `JSON.stringify` runs every enumerable getter and `toJSON` — any of which
250
+ * may throw. Then the words are fixed, and nothing the throw said is kept.
251
+ */
156
252
  function message(e) {
157
- if (e instanceof Error)
158
- return e.message;
159
- if (e && typeof e === 'object')
160
- return JSON.stringify(e);
161
- return String(e);
253
+ try {
254
+ if (e instanceof Error)
255
+ return String(e.message);
256
+ if (e && typeof e === 'object')
257
+ return String(JSON.stringify(e));
258
+ return String(e);
259
+ }
260
+ catch {
261
+ return UNDESCRIBABLE;
262
+ }
162
263
  }
163
264
  /**
164
265
  * Header names whose VALUE must never reach a log.
@@ -169,25 +270,98 @@ function message(e) {
169
270
  * (`SAP_SESSIONID_*`, `MYSAPSSO2`), an `x-csrf-token` or its own `X-Api-Key`
170
271
  * arrives here too. A log line advertised as safe to paste into an issue has
171
272
  * to be safe for the headers nobody here anticipated, so this matches by
172
- * pattern rather than by the list we happened to think of.
273
+ * part of the name rather than by the list we happened to think of.
274
+ *
275
+ * Plain string code, no regular expression: the name is folded to lower case
276
+ * in ASCII `A`–`Z` only (the former `/i` patterns, without the `u` flag, never
277
+ * folded a non-ASCII character to an ASCII letter — `toLowerCase()` would map
278
+ * the Kelvin sign to `k`), then searched for each part.
173
279
  */
174
- const SECRET_HEADER_PATTERNS = [
175
- /authorization/i,
176
- /cookie/i,
177
- /token/i,
178
- /secret/i,
179
- /password/i,
180
- /credential/i,
181
- /api[-_]?key/i,
280
+ const SECRET_HEADER_PARTS = [
281
+ 'authorization',
282
+ 'cookie',
283
+ 'token',
284
+ 'secret',
285
+ 'password',
286
+ 'credential',
287
+ 'apikey',
288
+ 'api-key',
289
+ 'api_key',
182
290
  ];
291
+ /** `text` with ASCII `A`–`Z` lowered, every other character as it is. */
292
+ function asciiLowerCase(text) {
293
+ let folded = '';
294
+ for (let i = 0; i < text.length; i += 1) {
295
+ const unit = text.charCodeAt(i);
296
+ folded +=
297
+ unit >= 0x41 && unit <= 0x5a
298
+ ? String.fromCharCode(unit + 0x20)
299
+ : text.charAt(i);
300
+ }
301
+ return folded;
302
+ }
303
+ /** Whether a header's value must not reach a log, by its name. */
304
+ function isSecretHeader(name) {
305
+ const folded = asciiLowerCase(name);
306
+ return SECRET_HEADER_PARTS.some((part) => folded.includes(part));
307
+ }
308
+ /**
309
+ * The header an HTTP request carries the SAP passport in. Over RFC it is not a
310
+ * header field: `SADT_REST_RFC_ENDPOINT` does not read one there, so the
311
+ * passport goes to the SDK as the call's own.
312
+ */
313
+ const PASSPORT_HEADER = 'sap-passport';
314
+ function isPassportHeader(name) {
315
+ return asciiLowerCase(name) === PASSPORT_HEADER;
316
+ }
317
+ /** `0`–`9`, `A`–`F`, `a`–`f`. */
318
+ function isHexDigit(unit) {
319
+ return ((unit >= 0x30 && unit <= 0x39) ||
320
+ (unit >= 0x41 && unit <= 0x46) ||
321
+ (unit >= 0x61 && unit <= 0x66));
322
+ }
323
+ /** Non-empty, of even length, and every character a hex digit. */
324
+ function isHex(value) {
325
+ if (value.length === 0 || value.length % 2 !== 0)
326
+ return false;
327
+ for (let i = 0; i < value.length; i += 1) {
328
+ if (!isHexDigit(value.charCodeAt(i)))
329
+ return false;
330
+ }
331
+ return true;
332
+ }
333
+ /**
334
+ * The passport a request carries in `SAP-PASSPORT` (its name read without
335
+ * case), decoded; `undefined` when it carries none. Refused, before anything
336
+ * is sent, when the header is named more than once or its value is not hex —
337
+ * the header named, its value never quoted. The passport's structure is the
338
+ * SDK's to check.
339
+ */
340
+ function passportOf(headers) {
341
+ let value;
342
+ for (const [name, each] of Object.entries(headers ?? {})) {
343
+ if (!isPassportHeader(name))
344
+ continue;
345
+ if (value !== undefined) {
346
+ throw new Error('The request names SAP-PASSPORT more than once; nothing was sent.');
347
+ }
348
+ value = each;
349
+ }
350
+ if (value === undefined)
351
+ return undefined;
352
+ if (!isHex(value)) {
353
+ throw new Error('The SAP-PASSPORT header is not a passport in hex; nothing was sent.');
354
+ }
355
+ // Only after the test: `Buffer.from(…, 'hex')` stops silently at the first
356
+ // pair that is not hex.
357
+ return Buffer.from(value, 'hex');
358
+ }
183
359
  /**
184
360
  * The NAME is kept and only the VALUE goes — a redacted header still says it
185
361
  * was sent, which is half of what the log is read for.
186
362
  */
187
363
  function redactHeaders(fields) {
188
- return fields.map((field) => SECRET_HEADER_PATTERNS.some((pattern) => pattern.test(field.NAME))
189
- ? { ...field, VALUE: '[redacted]' }
190
- : field);
364
+ return fields.map((field) => isSecretHeader(field.NAME) ? { ...field, VALUE: '[redacted]' } : field);
191
365
  }
192
366
  /**
193
367
  * How much of a body a log line carries before it is cut. An ADT payload is
@@ -394,15 +568,16 @@ class RfcTransport {
394
568
  // Taken once, here: every await below compares against it, and a call
395
569
  // that finds the wire closed since it began sends nothing.
396
570
  const generation = this.generation;
571
+ const passport = passportOf(request.headers);
397
572
  const language = requestedLanguage(request);
398
573
  if ((0, statefulRequest_js_1.isStatefulRequest)(request)) {
399
574
  const other = otherLanguage(language, this.logonLanguage);
400
575
  if (other !== undefined) {
401
576
  throw new Error(`The request asks for ${LANGUAGE_FIELD} ${other}, but the stateful RFC session is logged on in ${this.logonLanguage ?? 'a language neither the RFC conversation factory nor the provider states'}: a session cannot change its language, so the request was not sent.`);
402
577
  }
403
- return this.carry(request, this.conversation, generation);
578
+ return this.carry(request, this.conversation, generation, passport, true);
404
579
  }
405
- return this.carryOnItsOwn(request, language, generation);
580
+ return this.carryOnItsOwn(request, language, generation, passport);
406
581
  }
407
582
  /**
408
583
  * A request that is not stateful, in a fresh ABAP session.
@@ -422,13 +597,13 @@ class RfcTransport {
422
597
  * it: the kept one when that one's logon language is the same, else one of
423
598
  * its own logged on with that `lang`, closed after the call.
424
599
  */
425
- async carryOnItsOwn(request, language, generation) {
600
+ async carryOnItsOwn(request, language, generation, passport) {
426
601
  if (this.canReset !== false && !this.statelessBusy) {
427
- return this.carryOnKept(request, language, generation);
602
+ return this.carryOnKept(request, language, generation, passport);
428
603
  }
429
- return this.carryOnThrowaway(request, inLanguage(await this.logonParameters(), language), generation);
604
+ return this.carryOnThrowaway(request, inLanguage(await this.logonParameters(), language), generation, passport);
430
605
  }
431
- async carryOnKept(request, language, generation) {
606
+ async carryOnKept(request, language, generation, passport) {
432
607
  this.statelessBusy = true;
433
608
  try {
434
609
  let kept = this.stateless;
@@ -437,7 +612,7 @@ class RfcTransport {
437
612
  // kept conversation would log on in, before any logon is made.
438
613
  const parameters = await this.logonParameters();
439
614
  if (otherLanguage(language, this.languageOf(parameters)) !== undefined) {
440
- return await this.carryOnThrowaway(request, inLanguage(parameters, language), generation);
615
+ return await this.carryOnThrowaway(request, inLanguage(parameters, language), generation, passport);
441
616
  }
442
617
  const opened = await this.openOwn(parameters, generation);
443
618
  // Checked again after the await: close() may have run since openOwn()
@@ -452,10 +627,10 @@ class RfcTransport {
452
627
  // and every later call opens its own.
453
628
  this.canReset = false;
454
629
  try {
455
- return await this.carry(request, opened, generation);
630
+ return await this.carry(request, opened, generation, passport);
456
631
  }
457
632
  finally {
458
- await this.closeQuietly(opened);
633
+ await this.closeUnlessReleased(opened);
459
634
  }
460
635
  }
461
636
  this.canReset = true;
@@ -465,23 +640,30 @@ class RfcTransport {
465
640
  this.logger?.debug('RFC stateless conversation opened (reset per call)');
466
641
  }
467
642
  else if (otherLanguage(language, this.statelessLanguage) !== undefined) {
468
- return await this.carryOnThrowaway(request, inLanguage(await this.logonParameters(), language), generation);
643
+ return await this.carryOnThrowaway(request, inLanguage(await this.logonParameters(), language), generation, passport);
469
644
  }
470
645
  try {
471
- return await this.carry(request, kept, generation);
646
+ return await this.carry(request, kept, generation, passport);
472
647
  }
473
648
  finally {
474
- try {
475
- await kept.resetServerContext?.();
649
+ if (!kept.alive) {
650
+ // An RFC error ended it, and the library released it: nothing is
651
+ // left to reset or close, and either would reject. It carried no
652
+ // session of this instance — a reset clears it after every call —
653
+ // so it is replaced as a failed reset replaces it: dropped, and the
654
+ // next call opens another.
655
+ this.dropStateless(kept);
476
656
  }
477
- catch (e) {
478
- // A context that could not be reset must not serve the next call.
479
- this.logQuietly(() => `RFC reset failed, dropping the conversation: ${message(e)}`);
480
- if (this.stateless === kept) {
481
- this.stateless = null;
482
- this.statelessLanguage = undefined;
657
+ else {
658
+ try {
659
+ await kept.resetServerContext?.();
660
+ }
661
+ catch (e) {
662
+ // A context that could not be reset must not serve the next call.
663
+ this.logQuietly(() => `RFC reset failed, dropping the conversation: ${message(e)}`);
664
+ this.dropStateless(kept);
665
+ await this.closeQuietly(kept);
483
666
  }
484
- await this.closeQuietly(kept);
485
667
  }
486
668
  }
487
669
  }
@@ -493,16 +675,42 @@ class RfcTransport {
493
675
  * A conversation opened for this one call with `parameters`, closed when it
494
676
  * answers, whatever the answer.
495
677
  */
496
- async carryOnThrowaway(request, parameters, generation) {
678
+ async carryOnThrowaway(request, parameters, generation, passport) {
497
679
  const own = await this.openOwn(parameters, generation);
498
680
  try {
499
681
  this.logger?.debug('RFC conversation opened for one stateless call');
500
- return await this.carry(request, own, generation);
682
+ return await this.carry(request, own, generation, passport);
501
683
  }
502
684
  finally {
503
- await this.closeQuietly(own);
685
+ await this.closeUnlessReleased(own);
504
686
  }
505
687
  }
688
+ /**
689
+ * The stateful conversation is `conversation` no more: the library released
690
+ * it, so there is nothing left to close, and a close would only reject.
691
+ */
692
+ dropSession(conversation) {
693
+ if (this.conversation === conversation) {
694
+ this.conversation = null;
695
+ this.conversationId = '';
696
+ this.logonLanguage = undefined;
697
+ }
698
+ }
699
+ /** The kept stateless conversation is `conversation` no more. */
700
+ dropStateless(conversation) {
701
+ if (this.stateless === conversation) {
702
+ this.stateless = null;
703
+ this.statelessLanguage = undefined;
704
+ }
705
+ }
706
+ /**
707
+ * A conversation used for one call, closed — unless an RFC error ended it:
708
+ * the library has released it, and a close would only reject.
709
+ */
710
+ async closeUnlessReleased(conversation) {
711
+ if (conversation.alive)
712
+ await this.closeQuietly(conversation);
713
+ }
506
714
  /**
507
715
  * A new conversation, logged on with `parameters`. The logon takes time
508
716
  * (~0.5 s on E19); if the wire was closed meanwhile, the conversation is
@@ -589,7 +797,9 @@ class RfcTransport {
589
797
  this.logQuietly(() => `RFC close error: ${message(e)}`);
590
798
  }
591
799
  }
592
- async carry(request, conversation, generation) {
800
+ async carry(request, conversation, generation, passport,
801
+ /** Whether `conversation` is the stateful one: the instance's session. */
802
+ carriesSession = false) {
593
803
  const method = request.method.toUpperCase();
594
804
  // HTTP clients serialise `params`; RFC has no such step, so they go into
595
805
  // the URI here or they do not travel at all.
@@ -599,7 +809,11 @@ class RfcTransport {
599
809
  const serialised = new URLSearchParams(query.map(([k, v]) => [k, String(v)])).toString();
600
810
  uri += (uri.includes('?') ? '&' : '?') + serialised;
601
811
  }
602
- const headerFields = Object.entries(request.headers ?? {}).map(([NAME, VALUE]) => ({ NAME, VALUE: String(VALUE) }));
812
+ // The passport is not a header field over RFC: it goes to the SDK as the
813
+ // call's own (`passport`, read in `send()`).
814
+ const headerFields = Object.entries(request.headers ?? {})
815
+ .filter(([NAME]) => !isPassportHeader(NAME))
816
+ .map(([NAME, VALUE]) => ({ NAME, VALUE: String(VALUE) }));
603
817
  // ADT refuses a request with no Accept — `400 ExceptionResourceBadRequest:
604
818
  // Accept header missing`, measured on E19. Over HTTP axios supplies the
605
819
  // default and nobody notices; this endpoint forwards only what it is
@@ -652,7 +866,7 @@ class RfcTransport {
652
866
  }
653
867
  let raw;
654
868
  try {
655
- raw = await conversation.call('SADT_REST_RFC_ENDPOINT', {
869
+ const params = {
656
870
  REQUEST: {
657
871
  REQUEST_LINE: {
658
872
  METHOD: method,
@@ -662,13 +876,40 @@ class RfcTransport {
662
876
  HEADER_FIELDS: headerFields,
663
877
  MESSAGE_BODY: body ? Buffer.from(body, 'utf-8') : Buffer.alloc(0),
664
878
  },
665
- });
879
+ };
880
+ // The passport, for this call only; without one, the call as it always
881
+ // was — two arguments, so a conversation written for two still works.
882
+ raw =
883
+ passport === undefined
884
+ ? await conversation.call('SADT_REST_RFC_ENDPOINT', params)
885
+ : await conversation.call('SADT_REST_RFC_ENDPOINT', params, {
886
+ passport,
887
+ });
666
888
  }
667
889
  catch (e) {
668
890
  // An RFC-level failure, not an answer: nothing came back to classify.
891
+ // The verdict comes first — the SDK's fields, read once, and whether the
892
+ // session survived — so nothing that describes the failure afterwards
893
+ // (formatting the thrown value, a logger) can stand in for it.
894
+ const rfc = rfcErrorOf(e);
895
+ // The library released the stateful conversation after the error
896
+ // (`alive` false), and it was not a close() of ours: the session it
897
+ // carried is gone, with every lock taken in it. Said, not cured — no
898
+ // other conversation is opened in its place.
899
+ const lost = carriesSession && !conversation.alive && generation === this.generation;
900
+ if (lost)
901
+ this.dropSession(conversation);
669
902
  const msg = message(e);
670
- this.logger?.error(`RFC call failed: ${msg}`);
671
- throw new Error(`RFC call to SADT_REST_RFC_ENDPOINT failed: ${msg}`);
903
+ const text = `RFC call to SADT_REST_RFC_ENDPOINT failed: ${msg}`;
904
+ try {
905
+ this.logger?.error(`RFC call failed: ${msg}`);
906
+ }
907
+ catch {
908
+ // A broken logger must not replace the call's failure.
909
+ }
910
+ if (lost)
911
+ throw new authErrors_js_1.WireSessionLostError(text, rfc);
912
+ throw rfcCallError(text, rfc);
672
913
  }
673
914
  const answer = record(raw.RESPONSE) ?? raw;
674
915
  const statusLine = record(answer.STATUS_LINE);
@@ -2,6 +2,7 @@
2
2
  * What the connection raises when the credential says no, and the mark a wire
3
3
  * puts on a failure that is a refused logon.
4
4
  */
5
+ import type { IAbapConnectionError, IRfcErrorInfo } from '@mcp-abap-adt/interfaces-adt-connection';
5
6
  import type { AuthOutcome, IAuthRefusal } from '@mcp-abap-adt/interfaces-auth';
6
7
  /** When in the connection's life the credential refused. */
7
8
  export type AuthRefusalMoment = 'prepare' | 'logon' | 'request';
@@ -35,6 +36,19 @@ export declare class WireLogonError extends Error {
35
36
  readonly cause: unknown;
36
37
  constructor(cause: unknown, status?: number);
37
38
  }
39
+ /**
40
+ * A wire's mark: the session this wire carries has ended under it — over RFC,
41
+ * an RFC error ended the stateful conversation, and the locks taken in it
42
+ * with it. It decides nothing: the connection reports the session lost and
43
+ * the instance is spent; nothing opens a new session in its place.
44
+ *
45
+ * Exported so a consumer's own wire can say the same thing. `rfc` is the
46
+ * failed call's fields when the SDK named the failure.
47
+ */
48
+ export declare class WireSessionLostError extends Error implements IAbapConnectionError {
49
+ readonly rfc?: IRfcErrorInfo | undefined;
50
+ constructor(message: string, rfc?: IRfcErrorInfo);
51
+ }
38
52
  /**
39
53
  * A provider threw instead of answering, or answered something that is not an
40
54
  * outcome: a bug in the provider, not an answer.
@@ -1 +1 @@
1
- {"version":3,"file":"authErrors.d.ts","sourceRoot":"","sources":["../../src/connection/authErrors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE/E,4DAA4D;AAC5D,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,EAAE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C,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,SAAkB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEtB,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,OAAO;CAU1E;AAmBD;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,SAAkB,KAAK,EAAE,OAAO,CAAC;gBAErB,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM;CAM5C;AAED;;;;;;;;GAQG;AACH,qBAAa,oBACX,SAAQ,KACR,YAAW,oBAAoB;IAE/B,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;gBAE7B,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,aAAa;CAKjD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,iBAAiB,GAAG,YAAY,CAElE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,iBAAiB,GAAG,YAAY,CAEhE;AAED,oEAAoE;AACpE,eAAO,MAAM,sBAAsB,EAAE,YAEnC,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,EAChC,EAAE,EAAE,iBAAiB,GACpB,OAAO,CAAC,aAAa,CAAC,CAOxB"}
@@ -4,7 +4,7 @@
4
4
  * puts on a failure that is a refused logon.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.NO_CREDENTIAL_TO_RENEW = exports.WireLogonError = exports.AuthRefusedError = void 0;
7
+ exports.NO_CREDENTIAL_TO_RENEW = exports.WireSessionLostError = exports.WireLogonError = exports.AuthRefusedError = void 0;
8
8
  exports.providerFailed = providerFailed;
9
9
  exports.refusedAgain = refusedAgain;
10
10
  exports.guarded = guarded;
@@ -66,6 +66,24 @@ class WireLogonError extends Error {
66
66
  }
67
67
  }
68
68
  exports.WireLogonError = WireLogonError;
69
+ /**
70
+ * A wire's mark: the session this wire carries has ended under it — over RFC,
71
+ * an RFC error ended the stateful conversation, and the locks taken in it
72
+ * with it. It decides nothing: the connection reports the session lost and
73
+ * the instance is spent; nothing opens a new session in its place.
74
+ *
75
+ * Exported so a consumer's own wire can say the same thing. `rfc` is the
76
+ * failed call's fields when the SDK named the failure.
77
+ */
78
+ class WireSessionLostError extends Error {
79
+ rfc;
80
+ constructor(message, rfc) {
81
+ super(message);
82
+ this.name = 'WireSessionLostError';
83
+ this.rfc = rfc;
84
+ }
85
+ }
86
+ exports.WireSessionLostError = WireSessionLostError;
69
87
  /**
70
88
  * A provider threw instead of answering, or answered something that is not an
71
89
  * outcome: a bug in the provider, not an answer.
@@ -3,18 +3,12 @@
3
3
  *
4
4
  * Centralized constants for CSRF token fetching to ensure consistency
5
5
  * across different connection implementations.
6
+ *
7
+ * The fetch is one request per endpoint, never repeated and never delayed: a
8
+ * failed request is its own error. The fallback endpoint is asked only after
9
+ * the primary answered 404 (or 501) — a system without it — and is not a retry.
6
10
  */
7
11
  export declare const CSRF_CONFIG: {
8
- /**
9
- * Number of retry attempts for CSRF token fetch
10
- * Default: 3 attempts (total of 4 requests: initial + 3 retries)
11
- */
12
- readonly RETRY_COUNT: 3;
13
- /**
14
- * Delay between retry attempts (milliseconds)
15
- * Default: 1000ms (1 second)
16
- */
17
- readonly RETRY_DELAY: 1000;
18
12
  /**
19
13
  * CSRF token endpoint path (primary)
20
14
  * Standard SAP ADT core discovery endpoint (newer systems, returns smaller response)
@@ -1 +1 @@
1
- {"version":3,"file":"csrfConfig.d.ts","sourceRoot":"","sources":["../../src/connection/csrfConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW;IACtB;;;OAGG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;OAIG;;IAGH;;OAEG;;;;;CAKK,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB;sCACL,MAAM,SAAS,MAAM;;;CAOtC,CAAC"}
1
+ {"version":3,"file":"csrfConfig.d.ts","sourceRoot":"","sources":["../../src/connection/csrfConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IACtB;;;OAGG;;IAGH;;;;OAIG;;IAGH;;OAEG;;;;;CAKK,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB;sCACL,MAAM,SAAS,MAAM;;;CAOtC,CAAC"}
@@ -6,18 +6,12 @@ exports.CSRF_ERROR_MESSAGES = exports.CSRF_CONFIG = void 0;
6
6
  *
7
7
  * Centralized constants for CSRF token fetching to ensure consistency
8
8
  * across different connection implementations.
9
+ *
10
+ * The fetch is one request per endpoint, never repeated and never delayed: a
11
+ * failed request is its own error. The fallback endpoint is asked only after
12
+ * the primary answered 404 (or 501) — a system without it — and is not a retry.
9
13
  */
10
14
  exports.CSRF_CONFIG = {
11
- /**
12
- * Number of retry attempts for CSRF token fetch
13
- * Default: 3 attempts (total of 4 requests: initial + 3 retries)
14
- */
15
- RETRY_COUNT: 3,
16
- /**
17
- * Delay between retry attempts (milliseconds)
18
- * Default: 1000ms (1 second)
19
- */
20
- RETRY_DELAY: 1000,
21
15
  /**
22
16
  * CSRF token endpoint path (primary)
23
17
  * Standard SAP ADT core discovery endpoint (newer systems, returns smaller response)
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { sapConfigSignature } from './config/sapConfig.js';
4
4
  export type { AbapConnection, AbapRequestOptions, } from './connection/AbapConnection.js';
5
5
  export { AdtCloudConnector } from './connection/AdtCloudConnector.js';
6
6
  export { AdtOnPremConnector } from './connection/AdtOnPremConnector.js';
7
- export { type AuthRefusalMoment, AuthRefusedError, WireLogonError, } from './connection/authErrors.js';
7
+ export { type AuthRefusalMoment, AuthRefusedError, WireLogonError, WireSessionLostError, } from './connection/authErrors.js';
8
8
  export { CloudHttpTransport } from './connection/CloudHttpTransport.js';
9
9
  export { type CloudHttpSpec, type ConnectionSpec, type CreatedConnection, createConnection, type OnPremHttpSpec, type OnPremRfcSpec, } from './connection/createConnection.js';
10
10
  export { CSRF_CONFIG, CSRF_ERROR_MESSAGES } from './connection/csrfConfig.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAK1C,YAAY,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,YAAY,GACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,YAAY,EACV,cAAc,EACd,kBAAkB,GACnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EACL,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,cAAc,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAGxE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,kCAAkC,CAAC;AAQ1C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EACL,yB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B,EAChB,cAAc,EACd,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAGxE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,kCAAkC,CAAC;AAQ1C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EACL,yBAAyB,EACzB,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,aAAa,EACb,cAAc,GACf,MAAM,+BAA+B,CAAC;AACvC,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,YAAY,GACb,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,mBAAmB,EACnB,aAAa,GACd,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Types - re-exported from the contract packages, under the names this
3
3
  // package has always published them by.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.rfcParamsFrom = exports.rfcConversationFrom = exports.RfcTransport = exports.OnPremHttpTransport = exports.LegacyOnPremHttpTransport = exports.nodeHttpClient = exports.HttpTransport = exports.GenericWebSocketTransport = exports.CSRF_ERROR_MESSAGES = exports.CSRF_CONFIG = exports.createConnection = exports.CloudHttpTransport = exports.WireLogonError = exports.AuthRefusedError = exports.AdtOnPremConnector = exports.AdtCloudConnector = exports.sapConfigSignature = void 0;
5
+ exports.rfcParamsFrom = exports.rfcConversationFrom = exports.RfcTransport = exports.OnPremHttpTransport = exports.LegacyOnPremHttpTransport = exports.nodeHttpClient = exports.HttpTransport = exports.GenericWebSocketTransport = exports.CSRF_ERROR_MESSAGES = exports.CSRF_CONFIG = exports.createConnection = exports.CloudHttpTransport = exports.WireSessionLostError = exports.WireLogonError = exports.AuthRefusedError = exports.AdtOnPremConnector = exports.AdtCloudConnector = exports.sapConfigSignature = void 0;
6
6
  // Config utilities
7
7
  var sapConfig_js_1 = require("./config/sapConfig.js");
8
8
  Object.defineProperty(exports, "sapConfigSignature", { enumerable: true, get: function () { return sapConfig_js_1.sapConfigSignature; } });
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "AdtOnPremConnector", { enumerable: true, get: fu
13
13
  var authErrors_js_1 = require("./connection/authErrors.js");
14
14
  Object.defineProperty(exports, "AuthRefusedError", { enumerable: true, get: function () { return authErrors_js_1.AuthRefusedError; } });
15
15
  Object.defineProperty(exports, "WireLogonError", { enumerable: true, get: function () { return authErrors_js_1.WireLogonError; } });
16
+ Object.defineProperty(exports, "WireSessionLostError", { enumerable: true, get: function () { return authErrors_js_1.WireSessionLostError; } });
16
17
  var CloudHttpTransport_js_1 = require("./connection/CloudHttpTransport.js");
17
18
  Object.defineProperty(exports, "CloudHttpTransport", { enumerable: true, get: function () { return CloudHttpTransport_js_1.CloudHttpTransport; } });
18
19
  // The recommended way to build a connection: the system and the wire stated,
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-22.0.md # RFC: the session lost after a connection-ending error; rfc fields; the passport
19
+ │ ├── MIGRATION-21.0.md # the CSRF token fetch asks once: no retry, no delay
18
20
  │ ├── MIGRATION-20.0.md # an RFC config states its address, client and language; no URL over RFC
19
21
  │ ├── MIGRATION-18.0.md # rfcParamsFrom returns RfcAddress; RFC through a message server
20
22
  │ ├── MIGRATION-17.0.md # no deadline of the package's own; an instance on an existing session
@@ -50,6 +52,7 @@ mcp-abap-connection/
50
52
  - 🧭 [Scope](./SCOPE.md) - What this package answers for, and only that
51
53
 
52
54
  ### Upgrading
55
+ - 🚚 [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
53
56
  - 🚚 [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`
54
57
  - 🚚 [Migrating to 18.0.0](./MIGRATION-18.0.md) - `rfcParamsFrom` returns `RfcAddress`; RFC through a message server and a logon group
55
58
  - 🚚 [Migrating to 17.0.0](./MIGRATION-17.0.md) - `getTimeout`, `getTimeoutConfig` and `SAP_TIMEOUT_*` are gone; a request carries only the caller's `timeout`, and none inside a critical section; `createConnection({ …, session })` and `sessionCookies()`