@mcp-abap-adt/connection 25.0.0 → 25.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -1
- package/README.md +73 -2
- package/dist/connection/AbstractAbapConnection.d.ts +14 -4
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +192 -56
- package/dist/connection/HttpTransport.d.ts +3 -1
- package/dist/connection/HttpTransport.d.ts.map +1 -1
- package/dist/connection/HttpTransport.js +66 -15
- package/dist/connection/IAdtTransport.d.ts +30 -1
- package/dist/connection/IAdtTransport.d.ts.map +1 -1
- package/dist/connection/RfcTransport.d.ts.map +1 -1
- package/dist/connection/RfcTransport.js +67 -24
- package/dist/connection/createConnection.d.ts.map +1 -1
- package/dist/connection/createConnection.js +12 -0
- package/dist/connection/quietLine.d.ts +44 -0
- package/dist/connection/quietLine.d.ts.map +1 -0
- package/dist/connection/quietLine.js +111 -0
- package/dist/connection/statefulRequest.d.ts +13 -0
- package/dist/connection/statefulRequest.d.ts.map +1 -1
- package/dist/connection/statefulRequest.js +27 -1
- package/dist/connection/withCheckRelogon.d.ts +14 -0
- package/dist/connection/withCheckRelogon.d.ts.map +1 -0
- package/dist/connection/withCheckRelogon.js +77 -0
- package/docs/STATEFUL_SESSION_GUIDE.md +5 -1
- package/docs/USAGE.md +48 -9
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractAbapConnection = void 0;
|
|
4
|
+
exports.carriesSessionLost = carriesSessionLost;
|
|
4
5
|
const node_crypto_1 = require("node:crypto");
|
|
5
6
|
const interfaces_adt_connection_1 = require("@mcp-abap-adt/interfaces-adt-connection");
|
|
6
7
|
const SessionLifecycle_js_1 = require("../session/SessionLifecycle.js");
|
|
@@ -9,6 +10,7 @@ const authErrors_js_1 = require("./authErrors.js");
|
|
|
9
10
|
const csrfConfig_js_1 = require("./csrfConfig.js");
|
|
10
11
|
const failureFacts_js_1 = require("./failureFacts.js");
|
|
11
12
|
const IAdtTransport_js_1 = require("./IAdtTransport.js");
|
|
13
|
+
const quietLine_js_1 = require("./quietLine.js");
|
|
12
14
|
const statefulRequest_js_1 = require("./statefulRequest.js");
|
|
13
15
|
/**
|
|
14
16
|
* Declares the capabilities explicitly rather than satisfying them by accident.
|
|
@@ -65,6 +67,20 @@ function dataPreview(data) {
|
|
|
65
67
|
return undefined;
|
|
66
68
|
}
|
|
67
69
|
}
|
|
70
|
+
/** A request's `noResend` and `noLog`, and nothing else of it. */
|
|
71
|
+
function flagsOf(request) {
|
|
72
|
+
return {
|
|
73
|
+
...(request.noResend ? { noResend: true } : {}),
|
|
74
|
+
...(request.noLog ? { noLog: true } : {}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* What a `noResend` request resolves on: `2xx` as always, and a `3xx` from
|
|
79
|
+
* SAP's own endpoint, which is returned rather than followed.
|
|
80
|
+
*/
|
|
81
|
+
function admitsRedirects(status) {
|
|
82
|
+
return status >= 200 && status < 400;
|
|
83
|
+
}
|
|
68
84
|
/** Whether a thrown value is a refusal this connection marked `sessionLost`. */
|
|
69
85
|
function carriesSessionLost(error) {
|
|
70
86
|
return (typeof error === 'object' &&
|
|
@@ -664,6 +680,8 @@ class AbstractAbapConnection {
|
|
|
664
680
|
closing = Promise.reject(error);
|
|
665
681
|
}
|
|
666
682
|
const answered = closing.catch((error) => {
|
|
683
|
+
if (context.noLog)
|
|
684
|
+
return;
|
|
667
685
|
this.logger?.debug(`Could not tell the server the session is finished: ${(0, failureFacts_js_1.factWords)(error)}`);
|
|
668
686
|
});
|
|
669
687
|
// A close that is over is past its write: it sent nothing, it failed to
|
|
@@ -975,7 +993,9 @@ class AbstractAbapConnection {
|
|
|
975
993
|
* Does not await: it is called from inside a request, and the cleanup must not
|
|
976
994
|
* wait for the very request that raised it.
|
|
977
995
|
*/
|
|
978
|
-
raiseSessionLost(reason
|
|
996
|
+
raiseSessionLost(reason,
|
|
997
|
+
/** Lost by a `noLog` request's answer: the caller is told, nothing logged. */
|
|
998
|
+
quiet = false) {
|
|
979
999
|
// The instance's one session is gone: it is spent, as after disconnect().
|
|
980
1000
|
// Nothing else is decided here — the caller is told, and decides. The
|
|
981
1001
|
// verdict first, then the word: a logger that throws cannot undo it.
|
|
@@ -985,7 +1005,9 @@ class AbstractAbapConnection {
|
|
|
985
1005
|
this.clearSessionState();
|
|
986
1006
|
this.lifecycle.markDisconnected();
|
|
987
1007
|
});
|
|
988
|
-
|
|
1008
|
+
if (!quiet) {
|
|
1009
|
+
this.logQuietly(() => this.logger?.warn(`Session lost: ${reason}`));
|
|
1010
|
+
}
|
|
989
1011
|
}
|
|
990
1012
|
/**
|
|
991
1013
|
* A log line on a failure path: a logger that throws must not replace the
|
|
@@ -1031,7 +1053,9 @@ class AbstractAbapConnection {
|
|
|
1031
1053
|
* caller's — `'lost'` is returned instead of the throw. Not given for the
|
|
1032
1054
|
* connection's own exchanges and for stateful requests.
|
|
1033
1055
|
*/
|
|
1034
|
-
keepAnswer = false
|
|
1056
|
+
keepAnswer = false,
|
|
1057
|
+
/** The answer is a `noLog` request's: the wire logs nothing of it. */
|
|
1058
|
+
quiet = false) {
|
|
1035
1059
|
// Fenced by SESSION GENERATION, not by the teardown epoch. Only a
|
|
1036
1060
|
// caller-initiated teardown moves the epoch — a recovery deliberately does
|
|
1037
1061
|
// not — so after a session loss and a successful recovery, a request from
|
|
@@ -1043,13 +1067,19 @@ class AbstractAbapConnection {
|
|
|
1043
1067
|
// session this would compare against.
|
|
1044
1068
|
if (generation !== undefined &&
|
|
1045
1069
|
generation !== this.lifecycle.sessionGeneration) {
|
|
1046
|
-
|
|
1070
|
+
// `noLog`: the request's one line is its quiet one.
|
|
1071
|
+
if (!quiet) {
|
|
1072
|
+
this.logger?.debug('Ignoring a response from a previous session: its effects are fenced');
|
|
1073
|
+
}
|
|
1047
1074
|
return 'kept';
|
|
1048
1075
|
}
|
|
1049
1076
|
// The wire folds the response into its own state; what the change MEANS
|
|
1050
1077
|
// is decided here, because it is a question about the session's lifetime.
|
|
1051
|
-
|
|
1052
|
-
|
|
1078
|
+
if (quiet)
|
|
1079
|
+
this.transport.ingest(headers, { noLog: true });
|
|
1080
|
+
else
|
|
1081
|
+
this.transport.ingest(headers);
|
|
1082
|
+
return this.applyIdentityPolicy(this.lifecycle.observe(this.transport.sessionFingerprint()), keepAnswer, quiet);
|
|
1053
1083
|
}
|
|
1054
1084
|
/**
|
|
1055
1085
|
* Acts on what a response said about the session identity.
|
|
@@ -1067,7 +1097,9 @@ class AbstractAbapConnection {
|
|
|
1067
1097
|
* Being wrong in this direction costs a reconnect; being wrong the other way
|
|
1068
1098
|
* costs a lock nobody can find.
|
|
1069
1099
|
*/
|
|
1070
|
-
applyIdentityPolicy(classification, keepAnswer
|
|
1100
|
+
applyIdentityPolicy(classification, keepAnswer,
|
|
1101
|
+
/** A `noLog` request's answer: the loss and its logoff write no line. */
|
|
1102
|
+
quiet = false) {
|
|
1071
1103
|
if (classification !== 'replaced')
|
|
1072
1104
|
return 'kept';
|
|
1073
1105
|
// The answer that replaced the session brought a session of its own,
|
|
@@ -1085,9 +1117,9 @@ class AbstractAbapConnection {
|
|
|
1085
1117
|
// logoff: the wire took its snapshot synchronously, and any other path
|
|
1086
1118
|
// that would end the session — a failed `connect()`'s logoff above all —
|
|
1087
1119
|
// must find nothing left to send, or the same session is logged off twice.
|
|
1088
|
-
this.endSession(this.sessionContext());
|
|
1120
|
+
this.endSession(quiet ? { ...this.sessionContext(), noLog: true } : this.sessionContext());
|
|
1089
1121
|
this.clearSessionState();
|
|
1090
|
-
this.raiseSessionLost('the session cookie changed under us');
|
|
1122
|
+
this.raiseSessionLost('the session cookie changed under us', quiet);
|
|
1091
1123
|
// A stateless request's answer is SAP's, and valid: it is returned, marked,
|
|
1092
1124
|
// the session already lost (fr0ster/mcp-abap-adt#354). Nothing is sent
|
|
1093
1125
|
// again for it. A stateful request — the one a lock is taken and released
|
|
@@ -1231,7 +1263,20 @@ class AbstractAbapConnection {
|
|
|
1231
1263
|
// exchange itself does not stop the request — the CSRF recovery below
|
|
1232
1264
|
// handles a token that is missing — but a refused credential does.
|
|
1233
1265
|
if (mutation && !this.transport.csrfToken()) {
|
|
1234
|
-
|
|
1266
|
+
try {
|
|
1267
|
+
await this.readyWireUpfront(renewal, lease, flagsOf(options));
|
|
1268
|
+
}
|
|
1269
|
+
catch (error) {
|
|
1270
|
+
// `noLog`: a request that ends before it is sent still writes its
|
|
1271
|
+
// one quiet line — the fetch's answer is the request's.
|
|
1272
|
+
if (options.noLog) {
|
|
1273
|
+
this.logQuietly(() => {
|
|
1274
|
+
const quiet = (0, quietLine_js_1.quietLine)(normalizedMethod, endpoint, (0, IAdtTransport_js_1.refusalOf)(error) ?? undefined);
|
|
1275
|
+
this.logger?.error(quiet.line, quiet.facts);
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
throw error;
|
|
1279
|
+
}
|
|
1235
1280
|
}
|
|
1236
1281
|
// The request's own headers: everything but the credential's, which is
|
|
1237
1282
|
// written fresh onto a copy of these for every attempt (`authorizedFrom`).
|
|
@@ -1322,27 +1367,50 @@ class AbstractAbapConnection {
|
|
|
1322
1367
|
// `unknown` on the caller's options, a record on the seam: the two
|
|
1323
1368
|
// transports serialise a query differently and both need the pairs.
|
|
1324
1369
|
params: params,
|
|
1325
|
-
|
|
1370
|
+
// `stateless` wins over the session mode, for this request alone: the
|
|
1371
|
+
// mode itself is not touched, so the next ordinary request follows it.
|
|
1372
|
+
stateful: !options.stateless && this.sessionMode === 'stateful',
|
|
1373
|
+
...(options.stateless ? { stateless: true } : {}),
|
|
1374
|
+
// `noResend`: the wire sends it once and follows no redirect, and a
|
|
1375
|
+
// `3xx` from SAP's own endpoint is the caller's answer; every other
|
|
1376
|
+
// status keeps today's verdict.
|
|
1377
|
+
...(options.noResend
|
|
1378
|
+
? { noResend: true, validateStatus: admitsRedirects }
|
|
1379
|
+
: {}),
|
|
1380
|
+
// `noLog`: every line about this request, here and on the wire, is the
|
|
1381
|
+
// quiet one.
|
|
1382
|
+
...(options.noLog ? { noLog: true } : {}),
|
|
1326
1383
|
};
|
|
1327
1384
|
if (data !== undefined) {
|
|
1328
1385
|
requestConfig.data = data;
|
|
1329
1386
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1387
|
+
// `noLog`: nothing before the answer; the one line is written once there
|
|
1388
|
+
// is a status to put on it (`quietLine`).
|
|
1389
|
+
if (!options.noLog) {
|
|
1390
|
+
this.logger?.debug(`Executing ${normalizedMethod} request to: ${requestUrl}`, {
|
|
1391
|
+
type: 'REQUEST_INFO',
|
|
1392
|
+
url: requestUrl,
|
|
1393
|
+
method: normalizedMethod,
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1335
1396
|
try {
|
|
1336
1397
|
const response = await this.sendObserved(requestConfig, lease);
|
|
1337
1398
|
// The answer outranks the logger's word on it: a logger that throws
|
|
1338
1399
|
// must not take a received answer — one marked `sessionLost` above all,
|
|
1339
1400
|
// whose session is already gone — from the caller.
|
|
1340
|
-
this.logQuietly(() =>
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1401
|
+
this.logQuietly(() => {
|
|
1402
|
+
if (options.noLog) {
|
|
1403
|
+
const quiet = (0, quietLine_js_1.quietLine)(normalizedMethod, requestUrl, response);
|
|
1404
|
+
this.logger?.debug(quiet.line, quiet.facts);
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
this.logger?.debug(`Request succeeded with status ${response.status}`, {
|
|
1408
|
+
type: 'REQUEST_SUCCESS',
|
|
1409
|
+
status: response.status,
|
|
1410
|
+
url: requestUrl,
|
|
1411
|
+
method: normalizedMethod,
|
|
1412
|
+
});
|
|
1413
|
+
});
|
|
1346
1414
|
return response;
|
|
1347
1415
|
}
|
|
1348
1416
|
catch (error) {
|
|
@@ -1370,7 +1438,7 @@ class AbstractAbapConnection {
|
|
|
1370
1438
|
throw (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.NOT_CONNECTED, 'The session this request was admitted to is gone; nothing was sent');
|
|
1371
1439
|
}
|
|
1372
1440
|
const response = await this.transport.send(requestConfig);
|
|
1373
|
-
const observed = this.observeResponse(response.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
|
|
1441
|
+
const observed = this.observeResponse(response.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig), requestConfig.noLog === true);
|
|
1374
1442
|
const answer = response;
|
|
1375
1443
|
// The answer itself says the session is gone: a field, on the one object
|
|
1376
1444
|
// that answers this request, never a word.
|
|
@@ -1469,7 +1537,14 @@ class AbstractAbapConnection {
|
|
|
1469
1537
|
//
|
|
1470
1538
|
// A stale request gets its error back and nothing else happens.
|
|
1471
1539
|
if (!this.lifecycle.isCurrent(lease)) {
|
|
1472
|
-
this.logQuietly(() =>
|
|
1540
|
+
this.logQuietly(() => {
|
|
1541
|
+
if (requestConfig.noLog) {
|
|
1542
|
+
const fenced = (0, quietLine_js_1.quietLine)(normalizedMethod, requestUrl, (0, IAdtTransport_js_1.refusalOf)(error) ?? undefined);
|
|
1543
|
+
this.logger?.debug(fenced.line, fenced.facts);
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
1546
|
+
this.logger?.debug('A request from a previous session failed; its recovery is fenced');
|
|
1547
|
+
});
|
|
1473
1548
|
throw error;
|
|
1474
1549
|
}
|
|
1475
1550
|
const errorDetails = {
|
|
@@ -1482,26 +1557,47 @@ class AbstractAbapConnection {
|
|
|
1482
1557
|
data: undefined,
|
|
1483
1558
|
};
|
|
1484
1559
|
const refusal = (0, IAdtTransport_js_1.refusalOf)(error);
|
|
1560
|
+
// `noLog`: the failure's lines carry the method, the path without its
|
|
1561
|
+
// query, the integer status and the byte count — no preview, no words.
|
|
1562
|
+
const quiet = requestConfig.noLog
|
|
1563
|
+
? (0, quietLine_js_1.quietLine)(normalizedMethod, requestUrl, refusal ?? undefined)
|
|
1564
|
+
: null;
|
|
1565
|
+
// Written here, once, before anything below can end the request — a
|
|
1566
|
+
// session verdict included, which then reaches the caller as the error
|
|
1567
|
+
// (`sessionLost`, `SESSION_REPLACED`) and never as a line.
|
|
1568
|
+
if (quiet) {
|
|
1569
|
+
this.logQuietly(() => {
|
|
1570
|
+
if (refusal?.status === 404)
|
|
1571
|
+
this.logger?.debug(quiet.line, quiet.facts);
|
|
1572
|
+
else
|
|
1573
|
+
this.logger?.error(quiet.line, quiet.facts);
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1485
1576
|
if (refusal) {
|
|
1486
1577
|
errorDetails.data = dataPreview(refusal.data);
|
|
1487
1578
|
// Every wire's refusal, not only axios's. A response the connection
|
|
1488
1579
|
// never observed is a session replacement it never noticed. A stateless
|
|
1489
1580
|
// request's refusal that showed one is the caller's answer: no recovery
|
|
1490
1581
|
// starts from it — no CSRF retry, no credential renewal.
|
|
1491
|
-
const observed = this.observeResponse(refusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
|
|
1582
|
+
const observed = this.observeResponse(refusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig), requestConfig.noLog === true);
|
|
1492
1583
|
if (observed === 'lost')
|
|
1493
1584
|
throw this.markedLost(error);
|
|
1494
1585
|
}
|
|
1495
|
-
this.throwIfSessionDead(error, lease);
|
|
1586
|
+
this.throwIfSessionDead(error, lease, quiet !== null);
|
|
1496
1587
|
// Check if this is a network error (connection refused, timeout, DNS, etc.)
|
|
1497
1588
|
// Don't retry for network errors - these indicate infrastructure/VPN issues
|
|
1498
1589
|
const networkError = (0, networkErrors_js_1.isNetworkError)(error);
|
|
1499
1590
|
if (networkError) {
|
|
1500
|
-
|
|
1591
|
+
if (!quiet) {
|
|
1592
|
+
this.logQuietly(() => this.logger?.error(`Network error - cannot connect to SAP system: ${errorDetails.message}`, errorDetails));
|
|
1593
|
+
}
|
|
1501
1594
|
throw error;
|
|
1502
1595
|
}
|
|
1503
1596
|
// Log 404 as debug (common for existence checks), other errors as error
|
|
1504
|
-
if (
|
|
1597
|
+
if (quiet) {
|
|
1598
|
+
// Written above.
|
|
1599
|
+
}
|
|
1600
|
+
else if (errorDetails.status === 404) {
|
|
1505
1601
|
this.logQuietly(() => this.logger?.debug(errorDetails.message, errorDetails));
|
|
1506
1602
|
}
|
|
1507
1603
|
else {
|
|
@@ -1514,13 +1610,18 @@ class AbstractAbapConnection {
|
|
|
1514
1610
|
// A CSRF complaint (403 "CSRF token validation failed", or a 401 to a
|
|
1515
1611
|
// mutation that holds no token yet): a token earned in the SAME session —
|
|
1516
1612
|
// the cookies are kept — and one resend.
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1613
|
+
// `noResend`: the first failure is the caller's answer — an abapGit
|
|
1614
|
+
// handler's own 500 holding `CSRF token` would be resent after it ran.
|
|
1615
|
+
if (!requestConfig.noResend &&
|
|
1616
|
+
this.shouldRetryCsrf(error, normalizedMethod)) {
|
|
1617
|
+
if (!quiet) {
|
|
1618
|
+
this.logger?.debug('CSRF token validation failed, fetching new token and retrying request', {
|
|
1619
|
+
url: requestUrl,
|
|
1620
|
+
method: normalizedMethod,
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1522
1623
|
try {
|
|
1523
|
-
this.setCsrfToken(await this.fetchCsrfToken(requestUrl, lease));
|
|
1624
|
+
this.setCsrfToken(await this.fetchCsrfToken(requestUrl, lease, flagsOf(requestConfig)));
|
|
1524
1625
|
const refreshedToken = this.getCsrfToken();
|
|
1525
1626
|
if (refreshedToken) {
|
|
1526
1627
|
requestHeaders['x-csrf-token'] = refreshedToken;
|
|
@@ -1543,11 +1644,11 @@ class AbstractAbapConnection {
|
|
|
1543
1644
|
// replacement it shows is its own answer, not the first attempt's 403.
|
|
1544
1645
|
const retryRefusal = (0, IAdtTransport_js_1.refusalOf)(retryError);
|
|
1545
1646
|
if (retryRefusal) {
|
|
1546
|
-
const observed = this.observeResponse(retryRefusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
|
|
1647
|
+
const observed = this.observeResponse(retryRefusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig), requestConfig.noLog === true);
|
|
1547
1648
|
if (observed === 'lost')
|
|
1548
1649
|
throw this.markedLost(retryError);
|
|
1549
1650
|
}
|
|
1550
|
-
this.throwIfSessionDead(retryError, lease);
|
|
1651
|
+
this.throwIfSessionDead(retryError, lease, quiet !== null);
|
|
1551
1652
|
// A session verdict outranks the error that started the retry: the
|
|
1552
1653
|
// caller can retry a 403 itself, but it cannot discover that its lock
|
|
1553
1654
|
// handle is dead from a 403. So does the credential's failure, which
|
|
@@ -1555,7 +1656,9 @@ class AbstractAbapConnection {
|
|
|
1555
1656
|
if (this.outranksOriginal(retryError)) {
|
|
1556
1657
|
throw retryError;
|
|
1557
1658
|
}
|
|
1558
|
-
|
|
1659
|
+
if (!quiet) {
|
|
1660
|
+
this.logQuietly(() => this.logger?.debug(`CSRF retry failed; rethrowing original error: ${(0, failureFacts_js_1.factWords)(retryError)}`));
|
|
1661
|
+
}
|
|
1559
1662
|
throw error;
|
|
1560
1663
|
}
|
|
1561
1664
|
}
|
|
@@ -1579,7 +1682,11 @@ class AbstractAbapConnection {
|
|
|
1579
1682
|
if (this.isSessionVerdict(failure))
|
|
1580
1683
|
throw failure;
|
|
1581
1684
|
// A resend inside the wire's recovery that met a dead session.
|
|
1582
|
-
this.throwIfSessionDead(failure, lease);
|
|
1685
|
+
this.throwIfSessionDead(failure, lease, requestConfig.noLog === true);
|
|
1686
|
+
// `noResend`: nothing to renew for, since nothing is resent — the refusal
|
|
1687
|
+
// is the caller's answer, and the provider is not asked.
|
|
1688
|
+
if (requestConfig.noResend)
|
|
1689
|
+
throw failure;
|
|
1583
1690
|
const rejection = this.credentialRejection(failure);
|
|
1584
1691
|
// A request from a previous session asks nobody anything: its recovery is
|
|
1585
1692
|
// fenced, and so is the credential's.
|
|
@@ -1595,7 +1702,7 @@ class AbstractAbapConnection {
|
|
|
1595
1702
|
try {
|
|
1596
1703
|
if (rejection.at === 'logon') {
|
|
1597
1704
|
this.transport.adoptCsrfToken(null);
|
|
1598
|
-
await this.ensureWireReady(lease);
|
|
1705
|
+
await this.ensureWireReady(lease, flagsOf(requestConfig));
|
|
1599
1706
|
const token = this.transport.csrfToken();
|
|
1600
1707
|
if (token && ['POST', 'PUT', 'DELETE'].includes(requestConfig.method)) {
|
|
1601
1708
|
requestHeaders['x-csrf-token'] = token;
|
|
@@ -1621,11 +1728,11 @@ class AbstractAbapConnection {
|
|
|
1621
1728
|
// SAP replaced in between is SESSION_REPLACED, not a bare status.
|
|
1622
1729
|
const refusal = (0, IAdtTransport_js_1.refusalOf)(again);
|
|
1623
1730
|
if (refusal) {
|
|
1624
|
-
const observed = this.observeResponse(refusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
|
|
1731
|
+
const observed = this.observeResponse(refusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig), requestConfig.noLog === true);
|
|
1625
1732
|
if (observed === 'lost')
|
|
1626
1733
|
throw this.markedLost(again);
|
|
1627
1734
|
}
|
|
1628
|
-
this.throwIfSessionDead(again, lease);
|
|
1735
|
+
this.throwIfSessionDead(again, lease, requestConfig.noLog === true);
|
|
1629
1736
|
const secondRejection = this.credentialRejection(again);
|
|
1630
1737
|
if (!secondRejection)
|
|
1631
1738
|
throw again;
|
|
@@ -1642,15 +1749,17 @@ class AbstractAbapConnection {
|
|
|
1642
1749
|
* dead session. A request from a previous session says nothing about the
|
|
1643
1750
|
* current one, so its answer is not acted on.
|
|
1644
1751
|
*/
|
|
1645
|
-
throwIfSessionDead(error, lease
|
|
1752
|
+
throwIfSessionDead(error, lease,
|
|
1753
|
+
/** A `noLog` request's: the loss reaches the caller, no line. */
|
|
1754
|
+
quiet = false) {
|
|
1646
1755
|
if (error instanceof authErrors_js_1.WireSessionLostError) {
|
|
1647
|
-
this.throwWireSessionLost(error, lease);
|
|
1756
|
+
this.throwWireSessionLost(error, lease, quiet);
|
|
1648
1757
|
}
|
|
1649
1758
|
if (!this.isDeadSessionResponse(error))
|
|
1650
1759
|
return;
|
|
1651
1760
|
if (!this.lifecycle.isCurrent(lease))
|
|
1652
1761
|
return;
|
|
1653
|
-
this.raiseSessionLost('the server reports the session no longer exists');
|
|
1762
|
+
this.raiseSessionLost('the server reports the session no longer exists', quiet);
|
|
1654
1763
|
// No internal retry: a blind retry here is what produced further locks
|
|
1655
1764
|
// in the field. The caller decides.
|
|
1656
1765
|
throw (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED, 'The SAP session no longer exists; any lock handle from it is dead');
|
|
@@ -1663,10 +1772,10 @@ class AbstractAbapConnection {
|
|
|
1663
1772
|
* session: that is a new instance, the caller's to create. A mark from a
|
|
1664
1773
|
* previous session says nothing about the current one and is not acted on.
|
|
1665
1774
|
*/
|
|
1666
|
-
throwWireSessionLost(error, lease) {
|
|
1775
|
+
throwWireSessionLost(error, lease, quiet = false) {
|
|
1667
1776
|
if (!this.lifecycle.isCurrent(lease))
|
|
1668
1777
|
return;
|
|
1669
|
-
this.raiseSessionLost('the wire reports the session ended');
|
|
1778
|
+
this.raiseSessionLost('the wire reports the session ended', quiet);
|
|
1670
1779
|
const verdict = (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED, "The RFC conversation that carried this connection's SAP session has ended; any lock held in it is gone. Create a new connection for a new session.");
|
|
1671
1780
|
throw error.rfc === undefined
|
|
1672
1781
|
? verdict
|
|
@@ -1744,10 +1853,16 @@ class AbstractAbapConnection {
|
|
|
1744
1853
|
* fetch within the request's one retry — unless the session the request
|
|
1745
1854
|
* was admitted to is gone by then, when nothing more is sent.
|
|
1746
1855
|
*/
|
|
1747
|
-
async readyWireUpfront(renewal, lease
|
|
1856
|
+
async readyWireUpfront(renewal, lease,
|
|
1857
|
+
/**
|
|
1858
|
+
* The request's flags. `noResend`: the fetch goes once, and its failure —
|
|
1859
|
+
* a refused logon included, the provider not asked — is the request's
|
|
1860
|
+
* answer: the request is not sent. `noLog`: no line of the fetch's own.
|
|
1861
|
+
*/
|
|
1862
|
+
flags = {}) {
|
|
1748
1863
|
for (;;) {
|
|
1749
1864
|
try {
|
|
1750
|
-
await this.ensureWireReady(lease);
|
|
1865
|
+
await this.ensureWireReady(lease, flags);
|
|
1751
1866
|
return;
|
|
1752
1867
|
}
|
|
1753
1868
|
catch (error) {
|
|
@@ -1759,8 +1874,20 @@ class AbstractAbapConnection {
|
|
|
1759
1874
|
throw this.staleVerdict(error);
|
|
1760
1875
|
if (error instanceof authErrors_js_1.AuthRefusedError)
|
|
1761
1876
|
throw error;
|
|
1877
|
+
// `noResend`: the fetch's failure is the answer. A refused logon goes
|
|
1878
|
+
// as SAP's refusal it wraps — its status and body on top, as any
|
|
1879
|
+
// refusal's — since no provider is asked to act on the mark.
|
|
1880
|
+
if (flags.noResend) {
|
|
1881
|
+
throw error instanceof authErrors_js_1.WireLogonError && (0, IAdtTransport_js_1.refusalOf)(error.cause)
|
|
1882
|
+
? // A copy, made as every failure that leaves is: SAP's answer and
|
|
1883
|
+
// the facts, nothing of the request a custom wire put beside it.
|
|
1884
|
+
(0, failureFacts_js_1.failureCopy)(error.cause)
|
|
1885
|
+
: error;
|
|
1886
|
+
}
|
|
1762
1887
|
if (!(error instanceof authErrors_js_1.WireLogonError)) {
|
|
1763
|
-
|
|
1888
|
+
if (!flags.noLog) {
|
|
1889
|
+
this.logger?.debug(`Could not fetch CSRF token upfront, will retry on error: ${(0, failureFacts_js_1.factWords)(error)}`);
|
|
1890
|
+
}
|
|
1764
1891
|
return;
|
|
1765
1892
|
}
|
|
1766
1893
|
const rejection = this.credentialRejection(error);
|
|
@@ -1791,15 +1918,17 @@ class AbstractAbapConnection {
|
|
|
1791
1918
|
* wire's own ingest of it, and never stops the request being sent.
|
|
1792
1919
|
* Omitted during connect(), which has no lease.
|
|
1793
1920
|
*/
|
|
1794
|
-
fence
|
|
1921
|
+
fence,
|
|
1922
|
+
/** The flags of the request the token is fetched for. */
|
|
1923
|
+
flags = {}) {
|
|
1795
1924
|
// Dropped first, because this is only ever reached to REPLACE one: the
|
|
1796
1925
|
// establishment is idempotent and would hand back the very token the
|
|
1797
1926
|
// caller has just been told is stale.
|
|
1798
1927
|
this.transport.adoptCsrfToken(null);
|
|
1799
1928
|
await this.transport.establish({
|
|
1800
1929
|
...(typeof fence === 'number'
|
|
1801
|
-
? this.leasedContext(undefined, fence)
|
|
1802
|
-
: this.leasedContext(fence)),
|
|
1930
|
+
? this.leasedContext(undefined, fence, flags)
|
|
1931
|
+
: this.leasedContext(fence, undefined, flags)),
|
|
1803
1932
|
});
|
|
1804
1933
|
const token = this.transport.csrfToken();
|
|
1805
1934
|
if (!token)
|
|
@@ -1846,8 +1975,10 @@ class AbstractAbapConnection {
|
|
|
1846
1975
|
*/
|
|
1847
1976
|
async ensureWireReady(
|
|
1848
1977
|
/** The request's lease: fences what is sent and the response effects. */
|
|
1849
|
-
lease
|
|
1850
|
-
|
|
1978
|
+
lease,
|
|
1979
|
+
/** The flags of the request the wire is made ready for. */
|
|
1980
|
+
flags = {}) {
|
|
1981
|
+
await this.transport.establish(this.leasedContext(lease, undefined, flags));
|
|
1851
1982
|
}
|
|
1852
1983
|
/**
|
|
1853
1984
|
* The context for a token exchange a request makes on its own behalf — its
|
|
@@ -1865,8 +1996,13 @@ class AbstractAbapConnection {
|
|
|
1865
1996
|
* what the connection does with an answer, and nothing else: the request is
|
|
1866
1997
|
* sent, and the wire still folds the answer into its jar.
|
|
1867
1998
|
*/
|
|
1868
|
-
leasedContext(lease, generation = lease?.generation
|
|
1999
|
+
leasedContext(lease, generation = lease?.generation,
|
|
2000
|
+
/** The flags of the request the exchange is made for. */
|
|
2001
|
+
flags = {}) {
|
|
2002
|
+
const quiet = flags.noLog === true;
|
|
1869
2003
|
return {
|
|
2004
|
+
...(flags.noResend ? { noResend: true } : {}),
|
|
2005
|
+
...(quiet ? { noLog: true } : {}),
|
|
1870
2006
|
authorize: async (headers) => {
|
|
1871
2007
|
await this.credentialHeaders(headers);
|
|
1872
2008
|
if (lease && !this.lifecycle.isCurrent(lease)) {
|
|
@@ -1883,7 +2019,7 @@ class AbstractAbapConnection {
|
|
|
1883
2019
|
if (lease && !this.lifecycle.isCurrent(lease)) {
|
|
1884
2020
|
throw (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.NOT_CONNECTED, 'The session this request was admitted to is gone; its answer was not taken');
|
|
1885
2021
|
}
|
|
1886
|
-
this.observeResponse(headers, generation);
|
|
2022
|
+
this.observeResponse(headers, generation, false, quiet);
|
|
1887
2023
|
},
|
|
1888
2024
|
};
|
|
1889
2025
|
}
|
|
@@ -133,7 +133,9 @@ export declare class HttpTransport implements IAdtTransport {
|
|
|
133
133
|
* establishment or a replacement is a question about the session's lifetime,
|
|
134
134
|
* which this has no way to answer and no business answering.
|
|
135
135
|
*/
|
|
136
|
-
ingest(headers?: Record<string, unknown
|
|
136
|
+
ingest(headers?: Record<string, unknown>, options?: {
|
|
137
|
+
noLog?: true | undefined;
|
|
138
|
+
}): void;
|
|
137
139
|
/** What to put on the `Cookie` header, or nothing if the jar is empty. */
|
|
138
140
|
cookies(): string | null;
|
|
139
141
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpTransport.d.ts","sourceRoot":"","sources":["../../src/connection/HttpTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EACL,KAAK,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