@mcp-abap-adt/connection 25.0.1 → 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 +61 -1
- package/README.md +65 -1
- package/dist/connection/AbstractAbapConnection.d.ts +12 -4
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +191 -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 +6 -1
- 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 +7 -1
- package/dist/connection/withCheckRelogon.d.ts.map +1 -1
- package/dist/connection/withCheckRelogon.js +12 -3
- package/docs/STATEFUL_SESSION_GUIDE.md +5 -1
- package/docs/USAGE.md +27 -2
- package/package.json +2 -2
|
@@ -10,6 +10,7 @@ const authErrors_js_1 = require("./authErrors.js");
|
|
|
10
10
|
const csrfConfig_js_1 = require("./csrfConfig.js");
|
|
11
11
|
const failureFacts_js_1 = require("./failureFacts.js");
|
|
12
12
|
const IAdtTransport_js_1 = require("./IAdtTransport.js");
|
|
13
|
+
const quietLine_js_1 = require("./quietLine.js");
|
|
13
14
|
const statefulRequest_js_1 = require("./statefulRequest.js");
|
|
14
15
|
/**
|
|
15
16
|
* Declares the capabilities explicitly rather than satisfying them by accident.
|
|
@@ -66,6 +67,20 @@ function dataPreview(data) {
|
|
|
66
67
|
return undefined;
|
|
67
68
|
}
|
|
68
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
|
+
}
|
|
69
84
|
/** Whether a thrown value is a refusal this connection marked `sessionLost`. */
|
|
70
85
|
function carriesSessionLost(error) {
|
|
71
86
|
return (typeof error === 'object' &&
|
|
@@ -665,6 +680,8 @@ class AbstractAbapConnection {
|
|
|
665
680
|
closing = Promise.reject(error);
|
|
666
681
|
}
|
|
667
682
|
const answered = closing.catch((error) => {
|
|
683
|
+
if (context.noLog)
|
|
684
|
+
return;
|
|
668
685
|
this.logger?.debug(`Could not tell the server the session is finished: ${(0, failureFacts_js_1.factWords)(error)}`);
|
|
669
686
|
});
|
|
670
687
|
// A close that is over is past its write: it sent nothing, it failed to
|
|
@@ -976,7 +993,9 @@ class AbstractAbapConnection {
|
|
|
976
993
|
* Does not await: it is called from inside a request, and the cleanup must not
|
|
977
994
|
* wait for the very request that raised it.
|
|
978
995
|
*/
|
|
979
|
-
raiseSessionLost(reason
|
|
996
|
+
raiseSessionLost(reason,
|
|
997
|
+
/** Lost by a `noLog` request's answer: the caller is told, nothing logged. */
|
|
998
|
+
quiet = false) {
|
|
980
999
|
// The instance's one session is gone: it is spent, as after disconnect().
|
|
981
1000
|
// Nothing else is decided here — the caller is told, and decides. The
|
|
982
1001
|
// verdict first, then the word: a logger that throws cannot undo it.
|
|
@@ -986,7 +1005,9 @@ class AbstractAbapConnection {
|
|
|
986
1005
|
this.clearSessionState();
|
|
987
1006
|
this.lifecycle.markDisconnected();
|
|
988
1007
|
});
|
|
989
|
-
|
|
1008
|
+
if (!quiet) {
|
|
1009
|
+
this.logQuietly(() => this.logger?.warn(`Session lost: ${reason}`));
|
|
1010
|
+
}
|
|
990
1011
|
}
|
|
991
1012
|
/**
|
|
992
1013
|
* A log line on a failure path: a logger that throws must not replace the
|
|
@@ -1032,7 +1053,9 @@ class AbstractAbapConnection {
|
|
|
1032
1053
|
* caller's — `'lost'` is returned instead of the throw. Not given for the
|
|
1033
1054
|
* connection's own exchanges and for stateful requests.
|
|
1034
1055
|
*/
|
|
1035
|
-
keepAnswer = false
|
|
1056
|
+
keepAnswer = false,
|
|
1057
|
+
/** The answer is a `noLog` request's: the wire logs nothing of it. */
|
|
1058
|
+
quiet = false) {
|
|
1036
1059
|
// Fenced by SESSION GENERATION, not by the teardown epoch. Only a
|
|
1037
1060
|
// caller-initiated teardown moves the epoch — a recovery deliberately does
|
|
1038
1061
|
// not — so after a session loss and a successful recovery, a request from
|
|
@@ -1044,13 +1067,19 @@ class AbstractAbapConnection {
|
|
|
1044
1067
|
// session this would compare against.
|
|
1045
1068
|
if (generation !== undefined &&
|
|
1046
1069
|
generation !== this.lifecycle.sessionGeneration) {
|
|
1047
|
-
|
|
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
|
+
}
|
|
1048
1074
|
return 'kept';
|
|
1049
1075
|
}
|
|
1050
1076
|
// The wire folds the response into its own state; what the change MEANS
|
|
1051
1077
|
// is decided here, because it is a question about the session's lifetime.
|
|
1052
|
-
|
|
1053
|
-
|
|
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);
|
|
1054
1083
|
}
|
|
1055
1084
|
/**
|
|
1056
1085
|
* Acts on what a response said about the session identity.
|
|
@@ -1068,7 +1097,9 @@ class AbstractAbapConnection {
|
|
|
1068
1097
|
* Being wrong in this direction costs a reconnect; being wrong the other way
|
|
1069
1098
|
* costs a lock nobody can find.
|
|
1070
1099
|
*/
|
|
1071
|
-
applyIdentityPolicy(classification, keepAnswer
|
|
1100
|
+
applyIdentityPolicy(classification, keepAnswer,
|
|
1101
|
+
/** A `noLog` request's answer: the loss and its logoff write no line. */
|
|
1102
|
+
quiet = false) {
|
|
1072
1103
|
if (classification !== 'replaced')
|
|
1073
1104
|
return 'kept';
|
|
1074
1105
|
// The answer that replaced the session brought a session of its own,
|
|
@@ -1086,9 +1117,9 @@ class AbstractAbapConnection {
|
|
|
1086
1117
|
// logoff: the wire took its snapshot synchronously, and any other path
|
|
1087
1118
|
// that would end the session — a failed `connect()`'s logoff above all —
|
|
1088
1119
|
// must find nothing left to send, or the same session is logged off twice.
|
|
1089
|
-
this.endSession(this.sessionContext());
|
|
1120
|
+
this.endSession(quiet ? { ...this.sessionContext(), noLog: true } : this.sessionContext());
|
|
1090
1121
|
this.clearSessionState();
|
|
1091
|
-
this.raiseSessionLost('the session cookie changed under us');
|
|
1122
|
+
this.raiseSessionLost('the session cookie changed under us', quiet);
|
|
1092
1123
|
// A stateless request's answer is SAP's, and valid: it is returned, marked,
|
|
1093
1124
|
// the session already lost (fr0ster/mcp-abap-adt#354). Nothing is sent
|
|
1094
1125
|
// again for it. A stateful request — the one a lock is taken and released
|
|
@@ -1232,7 +1263,20 @@ class AbstractAbapConnection {
|
|
|
1232
1263
|
// exchange itself does not stop the request — the CSRF recovery below
|
|
1233
1264
|
// handles a token that is missing — but a refused credential does.
|
|
1234
1265
|
if (mutation && !this.transport.csrfToken()) {
|
|
1235
|
-
|
|
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
|
+
}
|
|
1236
1280
|
}
|
|
1237
1281
|
// The request's own headers: everything but the credential's, which is
|
|
1238
1282
|
// written fresh onto a copy of these for every attempt (`authorizedFrom`).
|
|
@@ -1323,27 +1367,50 @@ class AbstractAbapConnection {
|
|
|
1323
1367
|
// `unknown` on the caller's options, a record on the seam: the two
|
|
1324
1368
|
// transports serialise a query differently and both need the pairs.
|
|
1325
1369
|
params: params,
|
|
1326
|
-
|
|
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 } : {}),
|
|
1327
1383
|
};
|
|
1328
1384
|
if (data !== undefined) {
|
|
1329
1385
|
requestConfig.data = data;
|
|
1330
1386
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
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
|
+
}
|
|
1336
1396
|
try {
|
|
1337
1397
|
const response = await this.sendObserved(requestConfig, lease);
|
|
1338
1398
|
// The answer outranks the logger's word on it: a logger that throws
|
|
1339
1399
|
// must not take a received answer — one marked `sessionLost` above all,
|
|
1340
1400
|
// whose session is already gone — from the caller.
|
|
1341
|
-
this.logQuietly(() =>
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
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
|
+
});
|
|
1347
1414
|
return response;
|
|
1348
1415
|
}
|
|
1349
1416
|
catch (error) {
|
|
@@ -1371,7 +1438,7 @@ class AbstractAbapConnection {
|
|
|
1371
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');
|
|
1372
1439
|
}
|
|
1373
1440
|
const response = await this.transport.send(requestConfig);
|
|
1374
|
-
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);
|
|
1375
1442
|
const answer = response;
|
|
1376
1443
|
// The answer itself says the session is gone: a field, on the one object
|
|
1377
1444
|
// that answers this request, never a word.
|
|
@@ -1470,7 +1537,14 @@ class AbstractAbapConnection {
|
|
|
1470
1537
|
//
|
|
1471
1538
|
// A stale request gets its error back and nothing else happens.
|
|
1472
1539
|
if (!this.lifecycle.isCurrent(lease)) {
|
|
1473
|
-
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
|
+
});
|
|
1474
1548
|
throw error;
|
|
1475
1549
|
}
|
|
1476
1550
|
const errorDetails = {
|
|
@@ -1483,26 +1557,47 @@ class AbstractAbapConnection {
|
|
|
1483
1557
|
data: undefined,
|
|
1484
1558
|
};
|
|
1485
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
|
+
}
|
|
1486
1576
|
if (refusal) {
|
|
1487
1577
|
errorDetails.data = dataPreview(refusal.data);
|
|
1488
1578
|
// Every wire's refusal, not only axios's. A response the connection
|
|
1489
1579
|
// never observed is a session replacement it never noticed. A stateless
|
|
1490
1580
|
// request's refusal that showed one is the caller's answer: no recovery
|
|
1491
1581
|
// starts from it — no CSRF retry, no credential renewal.
|
|
1492
|
-
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);
|
|
1493
1583
|
if (observed === 'lost')
|
|
1494
1584
|
throw this.markedLost(error);
|
|
1495
1585
|
}
|
|
1496
|
-
this.throwIfSessionDead(error, lease);
|
|
1586
|
+
this.throwIfSessionDead(error, lease, quiet !== null);
|
|
1497
1587
|
// Check if this is a network error (connection refused, timeout, DNS, etc.)
|
|
1498
1588
|
// Don't retry for network errors - these indicate infrastructure/VPN issues
|
|
1499
1589
|
const networkError = (0, networkErrors_js_1.isNetworkError)(error);
|
|
1500
1590
|
if (networkError) {
|
|
1501
|
-
|
|
1591
|
+
if (!quiet) {
|
|
1592
|
+
this.logQuietly(() => this.logger?.error(`Network error - cannot connect to SAP system: ${errorDetails.message}`, errorDetails));
|
|
1593
|
+
}
|
|
1502
1594
|
throw error;
|
|
1503
1595
|
}
|
|
1504
1596
|
// Log 404 as debug (common for existence checks), other errors as error
|
|
1505
|
-
if (
|
|
1597
|
+
if (quiet) {
|
|
1598
|
+
// Written above.
|
|
1599
|
+
}
|
|
1600
|
+
else if (errorDetails.status === 404) {
|
|
1506
1601
|
this.logQuietly(() => this.logger?.debug(errorDetails.message, errorDetails));
|
|
1507
1602
|
}
|
|
1508
1603
|
else {
|
|
@@ -1515,13 +1610,18 @@ class AbstractAbapConnection {
|
|
|
1515
1610
|
// A CSRF complaint (403 "CSRF token validation failed", or a 401 to a
|
|
1516
1611
|
// mutation that holds no token yet): a token earned in the SAME session —
|
|
1517
1612
|
// the cookies are kept — and one resend.
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
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
|
+
}
|
|
1523
1623
|
try {
|
|
1524
|
-
this.setCsrfToken(await this.fetchCsrfToken(requestUrl, lease));
|
|
1624
|
+
this.setCsrfToken(await this.fetchCsrfToken(requestUrl, lease, flagsOf(requestConfig)));
|
|
1525
1625
|
const refreshedToken = this.getCsrfToken();
|
|
1526
1626
|
if (refreshedToken) {
|
|
1527
1627
|
requestHeaders['x-csrf-token'] = refreshedToken;
|
|
@@ -1544,11 +1644,11 @@ class AbstractAbapConnection {
|
|
|
1544
1644
|
// replacement it shows is its own answer, not the first attempt's 403.
|
|
1545
1645
|
const retryRefusal = (0, IAdtTransport_js_1.refusalOf)(retryError);
|
|
1546
1646
|
if (retryRefusal) {
|
|
1547
|
-
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);
|
|
1548
1648
|
if (observed === 'lost')
|
|
1549
1649
|
throw this.markedLost(retryError);
|
|
1550
1650
|
}
|
|
1551
|
-
this.throwIfSessionDead(retryError, lease);
|
|
1651
|
+
this.throwIfSessionDead(retryError, lease, quiet !== null);
|
|
1552
1652
|
// A session verdict outranks the error that started the retry: the
|
|
1553
1653
|
// caller can retry a 403 itself, but it cannot discover that its lock
|
|
1554
1654
|
// handle is dead from a 403. So does the credential's failure, which
|
|
@@ -1556,7 +1656,9 @@ class AbstractAbapConnection {
|
|
|
1556
1656
|
if (this.outranksOriginal(retryError)) {
|
|
1557
1657
|
throw retryError;
|
|
1558
1658
|
}
|
|
1559
|
-
|
|
1659
|
+
if (!quiet) {
|
|
1660
|
+
this.logQuietly(() => this.logger?.debug(`CSRF retry failed; rethrowing original error: ${(0, failureFacts_js_1.factWords)(retryError)}`));
|
|
1661
|
+
}
|
|
1560
1662
|
throw error;
|
|
1561
1663
|
}
|
|
1562
1664
|
}
|
|
@@ -1580,7 +1682,11 @@ class AbstractAbapConnection {
|
|
|
1580
1682
|
if (this.isSessionVerdict(failure))
|
|
1581
1683
|
throw failure;
|
|
1582
1684
|
// A resend inside the wire's recovery that met a dead session.
|
|
1583
|
-
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;
|
|
1584
1690
|
const rejection = this.credentialRejection(failure);
|
|
1585
1691
|
// A request from a previous session asks nobody anything: its recovery is
|
|
1586
1692
|
// fenced, and so is the credential's.
|
|
@@ -1596,7 +1702,7 @@ class AbstractAbapConnection {
|
|
|
1596
1702
|
try {
|
|
1597
1703
|
if (rejection.at === 'logon') {
|
|
1598
1704
|
this.transport.adoptCsrfToken(null);
|
|
1599
|
-
await this.ensureWireReady(lease);
|
|
1705
|
+
await this.ensureWireReady(lease, flagsOf(requestConfig));
|
|
1600
1706
|
const token = this.transport.csrfToken();
|
|
1601
1707
|
if (token && ['POST', 'PUT', 'DELETE'].includes(requestConfig.method)) {
|
|
1602
1708
|
requestHeaders['x-csrf-token'] = token;
|
|
@@ -1622,11 +1728,11 @@ class AbstractAbapConnection {
|
|
|
1622
1728
|
// SAP replaced in between is SESSION_REPLACED, not a bare status.
|
|
1623
1729
|
const refusal = (0, IAdtTransport_js_1.refusalOf)(again);
|
|
1624
1730
|
if (refusal) {
|
|
1625
|
-
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);
|
|
1626
1732
|
if (observed === 'lost')
|
|
1627
1733
|
throw this.markedLost(again);
|
|
1628
1734
|
}
|
|
1629
|
-
this.throwIfSessionDead(again, lease);
|
|
1735
|
+
this.throwIfSessionDead(again, lease, requestConfig.noLog === true);
|
|
1630
1736
|
const secondRejection = this.credentialRejection(again);
|
|
1631
1737
|
if (!secondRejection)
|
|
1632
1738
|
throw again;
|
|
@@ -1643,15 +1749,17 @@ class AbstractAbapConnection {
|
|
|
1643
1749
|
* dead session. A request from a previous session says nothing about the
|
|
1644
1750
|
* current one, so its answer is not acted on.
|
|
1645
1751
|
*/
|
|
1646
|
-
throwIfSessionDead(error, lease
|
|
1752
|
+
throwIfSessionDead(error, lease,
|
|
1753
|
+
/** A `noLog` request's: the loss reaches the caller, no line. */
|
|
1754
|
+
quiet = false) {
|
|
1647
1755
|
if (error instanceof authErrors_js_1.WireSessionLostError) {
|
|
1648
|
-
this.throwWireSessionLost(error, lease);
|
|
1756
|
+
this.throwWireSessionLost(error, lease, quiet);
|
|
1649
1757
|
}
|
|
1650
1758
|
if (!this.isDeadSessionResponse(error))
|
|
1651
1759
|
return;
|
|
1652
1760
|
if (!this.lifecycle.isCurrent(lease))
|
|
1653
1761
|
return;
|
|
1654
|
-
this.raiseSessionLost('the server reports the session no longer exists');
|
|
1762
|
+
this.raiseSessionLost('the server reports the session no longer exists', quiet);
|
|
1655
1763
|
// No internal retry: a blind retry here is what produced further locks
|
|
1656
1764
|
// in the field. The caller decides.
|
|
1657
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');
|
|
@@ -1664,10 +1772,10 @@ class AbstractAbapConnection {
|
|
|
1664
1772
|
* session: that is a new instance, the caller's to create. A mark from a
|
|
1665
1773
|
* previous session says nothing about the current one and is not acted on.
|
|
1666
1774
|
*/
|
|
1667
|
-
throwWireSessionLost(error, lease) {
|
|
1775
|
+
throwWireSessionLost(error, lease, quiet = false) {
|
|
1668
1776
|
if (!this.lifecycle.isCurrent(lease))
|
|
1669
1777
|
return;
|
|
1670
|
-
this.raiseSessionLost('the wire reports the session ended');
|
|
1778
|
+
this.raiseSessionLost('the wire reports the session ended', quiet);
|
|
1671
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.");
|
|
1672
1780
|
throw error.rfc === undefined
|
|
1673
1781
|
? verdict
|
|
@@ -1745,10 +1853,16 @@ class AbstractAbapConnection {
|
|
|
1745
1853
|
* fetch within the request's one retry — unless the session the request
|
|
1746
1854
|
* was admitted to is gone by then, when nothing more is sent.
|
|
1747
1855
|
*/
|
|
1748
|
-
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 = {}) {
|
|
1749
1863
|
for (;;) {
|
|
1750
1864
|
try {
|
|
1751
|
-
await this.ensureWireReady(lease);
|
|
1865
|
+
await this.ensureWireReady(lease, flags);
|
|
1752
1866
|
return;
|
|
1753
1867
|
}
|
|
1754
1868
|
catch (error) {
|
|
@@ -1760,8 +1874,20 @@ class AbstractAbapConnection {
|
|
|
1760
1874
|
throw this.staleVerdict(error);
|
|
1761
1875
|
if (error instanceof authErrors_js_1.AuthRefusedError)
|
|
1762
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
|
+
}
|
|
1763
1887
|
if (!(error instanceof authErrors_js_1.WireLogonError)) {
|
|
1764
|
-
|
|
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
|
+
}
|
|
1765
1891
|
return;
|
|
1766
1892
|
}
|
|
1767
1893
|
const rejection = this.credentialRejection(error);
|
|
@@ -1792,15 +1918,17 @@ class AbstractAbapConnection {
|
|
|
1792
1918
|
* wire's own ingest of it, and never stops the request being sent.
|
|
1793
1919
|
* Omitted during connect(), which has no lease.
|
|
1794
1920
|
*/
|
|
1795
|
-
fence
|
|
1921
|
+
fence,
|
|
1922
|
+
/** The flags of the request the token is fetched for. */
|
|
1923
|
+
flags = {}) {
|
|
1796
1924
|
// Dropped first, because this is only ever reached to REPLACE one: the
|
|
1797
1925
|
// establishment is idempotent and would hand back the very token the
|
|
1798
1926
|
// caller has just been told is stale.
|
|
1799
1927
|
this.transport.adoptCsrfToken(null);
|
|
1800
1928
|
await this.transport.establish({
|
|
1801
1929
|
...(typeof fence === 'number'
|
|
1802
|
-
? this.leasedContext(undefined, fence)
|
|
1803
|
-
: this.leasedContext(fence)),
|
|
1930
|
+
? this.leasedContext(undefined, fence, flags)
|
|
1931
|
+
: this.leasedContext(fence, undefined, flags)),
|
|
1804
1932
|
});
|
|
1805
1933
|
const token = this.transport.csrfToken();
|
|
1806
1934
|
if (!token)
|
|
@@ -1847,8 +1975,10 @@ class AbstractAbapConnection {
|
|
|
1847
1975
|
*/
|
|
1848
1976
|
async ensureWireReady(
|
|
1849
1977
|
/** The request's lease: fences what is sent and the response effects. */
|
|
1850
|
-
lease
|
|
1851
|
-
|
|
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));
|
|
1852
1982
|
}
|
|
1853
1983
|
/**
|
|
1854
1984
|
* The context for a token exchange a request makes on its own behalf — its
|
|
@@ -1866,8 +1996,13 @@ class AbstractAbapConnection {
|
|
|
1866
1996
|
* what the connection does with an answer, and nothing else: the request is
|
|
1867
1997
|
* sent, and the wire still folds the answer into its jar.
|
|
1868
1998
|
*/
|
|
1869
|
-
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;
|
|
1870
2003
|
return {
|
|
2004
|
+
...(flags.noResend ? { noResend: true } : {}),
|
|
2005
|
+
...(quiet ? { noLog: true } : {}),
|
|
1871
2006
|
authorize: async (headers) => {
|
|
1872
2007
|
await this.credentialHeaders(headers);
|
|
1873
2008
|
if (lease && !this.lifecycle.isCurrent(lease)) {
|
|
@@ -1884,7 +2019,7 @@ class AbstractAbapConnection {
|
|
|
1884
2019
|
if (lease && !this.lifecycle.isCurrent(lease)) {
|
|
1885
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');
|
|
1886
2021
|
}
|
|
1887
|
-
this.observeResponse(headers, generation);
|
|
2022
|
+
this.observeResponse(headers, generation, false, quiet);
|
|
1888
2023
|
},
|
|
1889
2024
|
};
|
|
1890
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,aAAa,EAClB,KAAK,IAAI,SAAS,EAGlB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAA2B,MAAM,YAAY,CAAC;AAG/E,OAAO,KAAK,EAGV,YAAY,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAc,EACZ,KAAK,aAAa,EAGnB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,OAAO,EAAE,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