@sasjs/adapter 6.1.5 → 6.1.7

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.
@@ -3510,6 +3510,12 @@ class SASViyaApiClient {
3510
3510
  }
3511
3511
  /**
3512
3512
  * Deletes the client representing the supplied ID.
3513
+ *
3514
+ * @deprecated Removing an OAuth client is an identity provider's administrative
3515
+ * action: on Viya it takes an administrator's token, and the client it removes
3516
+ * is a credential other callers sign in with. Nothing in this framework calls
3517
+ * it, from a browser or from the CLI, so it is kept only until the next major
3518
+ * release and will be removed then.
3513
3519
  * @param clientId - the client ID to authenticate with.
3514
3520
  * @param accessToken - an access token for authorizing the request.
3515
3521
  */
@@ -4330,6 +4336,15 @@ class SASjs {
4330
4336
  return yield this.sasViyaApiClient.refreshTokens(clientId, clientSecret, refreshToken);
4331
4337
  });
4332
4338
  }
4339
+ /**
4340
+ * Deletes the client representing the supplied ID.
4341
+ *
4342
+ * @deprecated Nothing in the framework calls it - no CLI command, no SASjs
4343
+ * Server route and no published app - and deleting an OAuth client is an estate
4344
+ * administrator's action, taken in the platform against an administrator's
4345
+ * token, so a browser or CLI client has no use for it. It keeps working until
4346
+ * the next major release, when it will be removed.
4347
+ */
4333
4348
  deleteClient(clientId, accessToken) {
4334
4349
  return __awaiter(this, void 0, void 0, function* () {
4335
4350
  this.isMethodSupported('deleteClient', [types_2.ServerType.SasViya]);
@@ -6444,7 +6459,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
6444
6459
  };
6445
6460
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6446
6461
  exports.getAccessTokenForSasjs = getAccessTokenForSasjs;
6447
- const error_1 = __webpack_require__(6340);
6448
6462
  const getTokenRequestErrorPrefix_1 = __webpack_require__(1087);
6449
6463
  const types_1 = __webpack_require__(3631);
6450
6464
  const apiBasePath_1 = __webpack_require__(6838);
@@ -6472,7 +6486,7 @@ function getAccessTokenForSasjs(requestClient_1, clientId_1, authCode_1) {
6472
6486
  };
6473
6487
  })
6474
6488
  .catch((err) => {
6475
- throw (0, error_1.prefixMessage)(err, (0, getTokenRequestErrorPrefix_1.getTokenRequestErrorPrefix)('fetching access token', 'getAccessTokenForSasjs', types_1.ServerType.Sasjs, url, data, clientId));
6489
+ throw (0, getTokenRequestErrorPrefix_1.tokenRequestErrorMessage)(err, 'fetching access token', 'getAccessTokenForSasjs', types_1.ServerType.Sasjs, url, data, undefined, clientId);
6476
6490
  });
6477
6491
  });
6478
6492
  }
@@ -6497,7 +6511,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
6497
6511
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6498
6512
  exports.getAccessTokenForViya = getAccessTokenForViya;
6499
6513
  const types_1 = __webpack_require__(3631);
6500
- const error_1 = __webpack_require__(6340);
6501
6514
  const errors_1 = __webpack_require__(7388);
6502
6515
  const getTokenRequestErrorPrefix_1 = __webpack_require__(1087);
6503
6516
  /**
@@ -6532,7 +6545,7 @@ function getAccessTokenForViya(requestClient, clientId, clientSecret, authCode)
6532
6545
  .catch((err) => {
6533
6546
  if (err instanceof errors_1.CertificateError)
6534
6547
  throw err;
6535
- throw (0, error_1.prefixMessage)(err, (0, getTokenRequestErrorPrefix_1.getTokenRequestErrorPrefix)('fetching access token', 'getAccessTokenForViya', types_1.ServerType.SasViya, url, dataJson, headers, clientId, clientSecret));
6548
+ throw (0, getTokenRequestErrorPrefix_1.tokenRequestErrorMessage)(err, 'fetching access token', 'getAccessTokenForViya', types_1.ServerType.SasViya, url, dataJson, headers, clientId, clientSecret);
6536
6549
  });
6537
6550
  return authResponse;
6538
6551
  });
@@ -6548,35 +6561,60 @@ function getAccessTokenForViya(requestClient, clientId, clientSecret, authCode)
6548
6561
  var __webpack_unused_export__;
6549
6562
 
6550
6563
  __webpack_unused_export__ = ({ value: true });
6551
- __webpack_unused_export__ = exports.getTokenRequestErrorPrefix = void 0;
6564
+ __webpack_unused_export__ = exports.tokenRequestErrorMessage = exports.vV = void 0;
6552
6565
  const types_1 = __webpack_require__(3631);
6566
+ const error_1 = __webpack_require__(6340);
6567
+ const responseReceived_1 = __webpack_require__(5775);
6568
+ const redactCredentials_1 = __webpack_require__(6894);
6553
6569
  const getServerName = (server) => server === types_1.ServerType.SasViya ? 'Viya' : 'Sasjs';
6554
- const getResponseTitle = (server) => `Response from ${getServerName(server)} is below.`;
6570
+ /**
6571
+ * What follows the request details: the server's answer, or the statement that
6572
+ * there was none.
6573
+ *
6574
+ * A transport failure - a wrong URL, a closed port, a VPN that is down, a
6575
+ * certificate that does not verify - carries no response, so calling its text
6576
+ * "Response from Viya" claims something the server never said. That is
6577
+ * sasjs/adapter#895: the reader was told the target answered with
6578
+ * `connect ETIMEDOUT`.
6579
+ */
6580
+ const getResponseTitle = (server, responseReceived) => responseReceived
6581
+ ? `Response from ${getServerName(server)} is below.`
6582
+ : `No response from ${getServerName(server)} - the request did not reach it.`;
6555
6583
  /**
6556
6584
  * Forms error prefix for requests related to token operations.
6557
6585
  * @param operation - string describing operation ('fetching access token' or 'refreshing tokens').
6558
6586
  * @param funcName - name of the function sent the request.
6559
6587
  * @param server - server type (SASVIYA or SASJS).
6560
6588
  * @param url - endpoint used to send the request.
6561
- * @param data - request payload.
6562
- * @param headers - request headers.
6563
- * @param clientId - client ID to authenticate with.
6564
- * @param clientSecret - client secret to authenticate with.
6565
- * @returns - string containing request information. Example:
6589
+ * @param data - request payload. Object and form-encoded payloads are redacted
6590
+ * field by field, at any depth; any other text body is reported as a shape
6591
+ * rather than printed.
6592
+ * @param headers - request headers. An authorization value keeps its scheme and
6593
+ * loses its credential.
6594
+ * @param clientId - client ID to authenticate with. Printed: it names which
6595
+ * client failed.
6596
+ * @param clientSecret - client secret to authenticate with. Replaced, never
6597
+ * printed; the report states that one was supplied.
6598
+ * @param responseReceived - whether the request came back with a response
6599
+ * (default `true`). When it did not, the title says so rather than presenting
6600
+ * the transport's own message as an answer from the server.
6601
+ * @returns - string containing request information, with every credential
6602
+ * named rather than printed. A failure is pasted into tickets and kept in CI
6603
+ * logs, so the report never carries a value that could be used as one. Example:
6566
6604
  * Error while fetching access token from /SASLogon/oauth/token
6567
6605
  * Thrown by the @sasjs/adapter getAccessTokenForViya function.
6568
6606
  * Payload:
6569
6607
  * {
6570
6608
  * "grant_type": "authorization_code",
6571
- * "code": "example_code"
6609
+ * "code": "<redacted>"
6572
6610
  * }
6573
6611
  * Headers:
6574
6612
  * {
6575
- * "Authorization": "Basic NEdMQXBwOjRHTEFwcDE=",
6613
+ * "Authorization": "Basic <redacted>",
6576
6614
  * "Accept": "application/json"
6577
6615
  * }
6578
6616
  * ClientId: exampleClientId
6579
- * ClientSecret: exampleClientSecret
6617
+ * ClientSecret: <redacted>
6580
6618
  *
6581
6619
  * Response from Viya is below.
6582
6620
  * Auth error: {
@@ -6584,37 +6622,81 @@ const getResponseTitle = (server) => `Response from ${getServerName(server)} is
6584
6622
  * "error_description": "No scopes were granted"
6585
6623
  * }
6586
6624
  */
6587
- const getTokenRequestErrorPrefix = (operation, funcName, server, url, data, headers, clientId, clientSecret) => {
6625
+ const getTokenRequestErrorPrefix = (operation, funcName, server, url, data, headers, clientId, clientSecret, responseReceived = true) => {
6588
6626
  const stringify = (obj) => JSON.stringify(obj, null, 2);
6589
6627
  const lines = [
6590
6628
  `Error while ${operation} from ${url}`,
6591
6629
  `Thrown by the @sasjs/adapter ${funcName} function.`
6592
6630
  ];
6631
+ // The request carries the credentials that minted the token: the header is the
6632
+ // client pair base64-encoded together, the body a refresh token or an
6633
+ // authorization code. A failure is pasted into tickets, so the values are
6634
+ // named and not printed (#895).
6593
6635
  if (data) {
6636
+ const payload = (0, redactCredentials_1.redactPayload)(data);
6594
6637
  lines.push('Payload:');
6595
- lines.push(stringify(data));
6638
+ lines.push(typeof payload === 'string' ? payload : stringify(payload));
6596
6639
  }
6597
6640
  if (headers) {
6598
6641
  lines.push('Headers:');
6599
- lines.push(stringify(headers));
6642
+ lines.push(stringify((0, redactCredentials_1.redactHeaders)(headers)));
6600
6643
  }
6644
+ // The client id names which client failed and is not a credential; the secret
6645
+ // beside it is, so it is stated as supplied rather than printed.
6601
6646
  if (clientId)
6602
6647
  lines.push(`ClientId: ${clientId}`);
6603
6648
  if (clientSecret)
6604
- lines.push(`ClientSecret: ${clientSecret}`);
6649
+ lines.push(`ClientSecret: ${redactCredentials_1.REDACTED}`);
6605
6650
  lines.push('');
6606
- lines.push(`${getResponseTitle(server)}`);
6651
+ lines.push(`${getResponseTitle(server, responseReceived)}`);
6607
6652
  lines.push('');
6608
6653
  return lines.join(`\n`);
6609
6654
  };
6610
- exports.getTokenRequestErrorPrefix = getTokenRequestErrorPrefix;
6655
+ exports.vV = getTokenRequestErrorPrefix;
6656
+ /**
6657
+ * The message for a failed token request: how the request was made, then what
6658
+ * came back.
6659
+ *
6660
+ * Every caller holds the error, so this is where "did the server answer?" is
6661
+ * decided - once. Threading a boolean through the optional parameters of
6662
+ * `getTokenRequestErrorPrefix` instead leaves the short call sites padding
6663
+ * arguments they do not have, which is how a later caller gets it wrong.
6664
+ *
6665
+ * @param error - the rejection from the request client.
6666
+ * @param operation - string describing operation ('fetching access token' or 'refreshing tokens').
6667
+ * @param funcName - name of the function that sent the request.
6668
+ * @param server - server type (SASVIYA or SASJS).
6669
+ * @param url - endpoint used to send the request.
6670
+ * @param data - request payload. Object and form-encoded payloads are redacted
6671
+ * field by field, at any depth; any other text body is reported as a shape
6672
+ * rather than printed.
6673
+ * @param headers - request headers. An authorization value keeps its scheme and
6674
+ * loses its credential.
6675
+ * @param clientId - client ID to authenticate with. Printed: it names which
6676
+ * client failed.
6677
+ * @param clientSecret - client secret to authenticate with. Replaced, never
6678
+ * printed; the report states that one was supplied.
6679
+ * @returns - the error, with the prefix in front of its message.
6680
+ */
6681
+ const tokenRequestErrorMessage = (error, operation, funcName, server, url, data, headers, clientId, clientSecret) => (0, error_1.prefixMessage)(error, (0, exports.vV)(operation, funcName, server, url, data, headers, clientId, clientSecret, (0, responseReceived_1.responseWasReceived)(error)));
6682
+ exports.tokenRequestErrorMessage = tokenRequestErrorMessage;
6611
6683
  /**
6612
6684
  * Parse error prefix to get response payload.
6685
+ *
6686
+ * A prefix built for a request that never reached the server carries the
6687
+ * transport's own message where the payload would be, so the split is made on
6688
+ * whichever title the prefix holds rather than assuming one.
6689
+ *
6613
6690
  * @param prefix - error prefix generated by getTokenRequestErrorPrefix function.
6614
6691
  * @param server - server type (SASVIYA or SASJS).
6615
6692
  * @returns - response payload.
6616
6693
  */
6617
- const getTokenRequestErrorPrefixResponse = (prefix, server) => prefix.split(`${getResponseTitle(server)}\n`).pop();
6694
+ const getTokenRequestErrorPrefixResponse = (prefix, server) => {
6695
+ const receivedTitle = `${getResponseTitle(server, true)}\n`;
6696
+ if (prefix.includes(receivedTitle))
6697
+ return prefix.split(receivedTitle).pop();
6698
+ return prefix.split(`${getResponseTitle(server, false)}\n`).pop();
6699
+ };
6618
6700
  __webpack_unused_export__ = getTokenRequestErrorPrefixResponse;
6619
6701
 
6620
6702
 
@@ -6931,6 +7013,202 @@ function openWebPage(url_1) {
6931
7013
  }
6932
7014
 
6933
7015
 
7016
+ /***/ },
7017
+
7018
+ /***/ 6894
7019
+ (__unused_webpack_module, exports) {
7020
+
7021
+ "use strict";
7022
+ var __webpack_unused_export__;
7023
+
7024
+ __webpack_unused_export__ = ({ value: true });
7025
+ exports.redactPayload = exports.redactHeaders = exports.eP = exports.uE = exports.REDACTED = void 0;
7026
+ /**
7027
+ * What a failed token request may say about the request it sent.
7028
+ *
7029
+ * A token failure is read by a person, pasted into a ticket and captured in CI
7030
+ * logs, and the request behind it carries the credentials that minted it: an
7031
+ * `Authorization` header holding the client id and secret base64-encoded
7032
+ * together, a body holding a refresh token, and the authorization code itself.
7033
+ * Printing those turns one error report into a credential disclosure, so this
7034
+ * module names the values that are secret and replaces each with a marker.
7035
+ *
7036
+ * The marker is a fixed string, not an empty one, so a reader can tell "this was
7037
+ * supplied" from "this was not". Keys are matched case-insensitively.
7038
+ */
7039
+ exports.REDACTED = '<redacted>';
7040
+ /**
7041
+ * The parameter names that carry a credential, in any of the spellings the
7042
+ * estate uses: OAuth's snake case, the adapter's camel case, and the headers a
7043
+ * server sets alongside a session.
7044
+ */
7045
+ const SECRET_KEYS = [
7046
+ 'authorization',
7047
+ 'token',
7048
+ 'cookie',
7049
+ 'x-csrf-token',
7050
+ 'x-xsrf-token',
7051
+ 'client_secret',
7052
+ 'clientsecret',
7053
+ 'secret',
7054
+ 'password',
7055
+ 'passwd',
7056
+ 'refresh_token',
7057
+ 'refreshtoken',
7058
+ 'access_token',
7059
+ 'accesstoken',
7060
+ 'id_token',
7061
+ 'idtoken',
7062
+ 'code'
7063
+ ];
7064
+ /** A parameter name with the spellings that vary (case, hyphen, underscore) removed. */
7065
+ const normalise = (key) => key.toLowerCase().replace(/[\s_-]/g, '');
7066
+ /**
7067
+ * What a form-encoded decoder is allowed to read as a parameter name.
7068
+ *
7069
+ * Deliberately narrow: a name carrying `{`, `[`, `"`, `%`, `&`, whitespace or a
7070
+ * second `=` is not a parameter of a form-encoded body, it is text this module
7071
+ * cannot read - and a body it cannot read is reported as a shape, never printed.
7072
+ */
7073
+ const PARAMETER_NAME = /^[A-Za-z0-9_.~[\]]+$/;
7074
+ /** Whether a parameter name carries a credential. */
7075
+ const isSecretKey = (key) => SECRET_KEYS.map(normalise).includes(normalise(key));
7076
+ exports.uE = isSecretKey;
7077
+ /**
7078
+ * An `Authorization` value with its scheme kept and its credential removed.
7079
+ *
7080
+ * The scheme stays because it is the part a reader diagnoses with: `Basic`
7081
+ * means a client pair, `Bearer` means a token, and the two fail in different
7082
+ * ways.
7083
+ */
7084
+ const redactAuthorizationValue = (value) => {
7085
+ var _a;
7086
+ const scheme = (_a = /^(basic|bearer|negotiate|digest)\b/i.exec(String(value))) === null || _a === void 0 ? void 0 : _a[0];
7087
+ return scheme ? `${scheme} ${exports.REDACTED}` : exports.REDACTED;
7088
+ };
7089
+ exports.eP = redactAuthorizationValue;
7090
+ /** Request headers, with the credential-bearing ones redacted. */
7091
+ const redactHeaders = (headers) => Object.fromEntries(Object.entries(headers).map(([key, value]) => [
7092
+ key,
7093
+ (0, exports.uE)(key) ? (0, exports.eP)(value) : value
7094
+ ]));
7095
+ exports.redactHeaders = redactHeaders;
7096
+ const MAX_DEPTH = 20;
7097
+ /**
7098
+ * A value, with secret-named keys redacted at any depth.
7099
+ *
7100
+ * Two guards belong here because this is where the walk happens, and both are
7101
+ * about a payload the reporter cannot print:
7102
+ *
7103
+ * - a byte view - a Buffer, a typed array, an ArrayBuffer - is a body, and walking
7104
+ * one as an object emits a numbered key per byte (`{"0":103,"1":114,...}`), the
7105
+ * body reproduced as clearly as the text it came from;
7106
+ * - a payload that refers to itself, or nests past `MAX_DEPTH`, would replace the
7107
+ * token failure with `RangeError: Maximum call stack size exceeded`. Both are
7108
+ * reported as a shape instead.
7109
+ *
7110
+ * `seen` holds the objects on the CURRENT path, not every object ever visited, so a
7111
+ * body that shares a sub-object between two keys is walked twice rather than
7112
+ * reported as circular - it is not.
7113
+ */
7114
+ const redactValue = (value, seen = new WeakSet(), depth = 0) => {
7115
+ if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer)
7116
+ return 'binary body - values redacted';
7117
+ if (!value || typeof value !== 'object')
7118
+ return value;
7119
+ if (seen.has(value))
7120
+ return 'circular body - values redacted';
7121
+ if (depth >= MAX_DEPTH)
7122
+ return 'nested too deep - values redacted';
7123
+ seen.add(value);
7124
+ try {
7125
+ if (Array.isArray(value))
7126
+ return value.map((inner) => redactValue(inner, seen, depth + 1));
7127
+ return Object.fromEntries(Object.entries(value).map(([key, inner]) => [
7128
+ key,
7129
+ (0, exports.uE)(key) ? exports.REDACTED : redactValue(inner, seen, depth + 1)
7130
+ ]));
7131
+ }
7132
+ finally {
7133
+ seen.delete(value);
7134
+ }
7135
+ };
7136
+ /**
7137
+ * A body that arrived as text, which a caller is free to pass: the parameter is
7138
+ * typed to admit one.
7139
+ *
7140
+ * Form-encoded text is rebuilt pair by pair so the parameters that are not
7141
+ * secrets stay readable, and anything else is reported as a shape rather than
7142
+ * echoed, because a body this module cannot read is a body it cannot redact.
7143
+ *
7144
+ * A JSON body is never form-encoded, whatever it contains. Base64 carries `=`
7145
+ * padding, so `{"client_secret":"YWJjWg=="}` splits into a key that is the
7146
+ * secret's own text and a value of `"}"` - the key is not a secret *name*, so no
7147
+ * key check catches it, and the secret is printed as though it were a parameter
7148
+ * name. Structured text therefore takes the shape branch on its opening
7149
+ * character, before any splitting.
7150
+ */
7151
+ const redactText = (text) => {
7152
+ const trimmed = text.trim();
7153
+ if (!trimmed)
7154
+ return trimmed;
7155
+ if (/^[{[]/.test(trimmed))
7156
+ return 'text body - values redacted';
7157
+ // A linear test, not a regular expression: the obvious pattern for "pairs
7158
+ // joined by &" nests quantifiers and backtracks exponentially on a string like
7159
+ // `!=&!=&!=&...` (CodeQL js/redos, found on this branch).
7160
+ const pairs = trimmed.split('&');
7161
+ const isFormEncoded = !/\s/.test(trimmed) &&
7162
+ pairs.every((pair) => pair.indexOf('=') > 0) &&
7163
+ pairs.every((pair) => PARAMETER_NAME.test(pair.slice(0, pair.indexOf('='))));
7164
+ if (isFormEncoded) {
7165
+ const redacted = {};
7166
+ for (const pair of pairs) {
7167
+ const [key, ...rest] = pair.split('=');
7168
+ const value = rest.join('=');
7169
+ redacted[key] = (0, exports.uE)(key) ? exports.REDACTED : value;
7170
+ }
7171
+ return redacted;
7172
+ }
7173
+ // not form-encoded: a JSON string, a SAS log, an HTML page. It is not parsed
7174
+ // here because a half-parsed body is worse than a stated shape.
7175
+ return 'text body - values redacted';
7176
+ };
7177
+ /**
7178
+ * A request payload, with the credential-bearing values redacted.
7179
+ *
7180
+ * The shapes that reach this function, each handled on its own terms: a plain
7181
+ * object or array is walked, so a secret one level down is redacted like one at the
7182
+ * top; a byte view - a Buffer or any typed array - is reported as a shape, because
7183
+ * walking it emits a key per byte; `URLSearchParams` (the form the OAuth code
7184
+ * exchange is sent as) is rebuilt pair by pair; a string that parses as
7185
+ * `key=value&key=value` is rebuilt the same way; and multipart form data (the
7186
+ * refresh) is reported as its shape rather than its fields, because its parts are a
7187
+ * stream the request still needs.
7188
+ *
7189
+ * `redactValue` carries the byte-view and cycle guards, so they hold at every depth
7190
+ * rather than only here.
7191
+ */
7192
+ const redactPayload = (data) => {
7193
+ if (!data)
7194
+ return data;
7195
+ if (typeof data === 'string')
7196
+ return redactText(data);
7197
+ const candidate = data;
7198
+ if (typeof candidate.getBoundary === 'function')
7199
+ return 'multipart form data - fields and values redacted';
7200
+ if (typeof candidate.entries === 'function' &&
7201
+ typeof candidate.get === 'function') {
7202
+ const redacted = {};
7203
+ for (const [key, value] of candidate.entries())
7204
+ redacted[key] = (0, exports.uE)(key) ? exports.REDACTED : value;
7205
+ return redacted;
7206
+ }
7207
+ return redactValue(candidate);
7208
+ };
7209
+ exports.redactPayload = redactPayload;
7210
+
7211
+
6934
7212
  /***/ },
6935
7213
 
6936
7214
  /***/ 6725
@@ -6949,7 +7227,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
6949
7227
  };
6950
7228
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6951
7229
  exports.refreshTokensForSasjs = refreshTokensForSasjs;
6952
- const error_1 = __webpack_require__(6340);
6953
7230
  const getTokenRequestErrorPrefix_1 = __webpack_require__(1087);
6954
7231
  const types_1 = __webpack_require__(3631);
6955
7232
  const apiBasePath_1 = __webpack_require__(6838);
@@ -6975,7 +7252,7 @@ function refreshTokensForSasjs(requestClient_1, refreshToken_1) {
6975
7252
  };
6976
7253
  })
6977
7254
  .catch((err) => {
6978
- throw (0, error_1.prefixMessage)(err, (0, getTokenRequestErrorPrefix_1.getTokenRequestErrorPrefix)('refreshing tokens', 'refreshTokensForSasjs', types_1.ServerType.Sasjs, url));
7255
+ throw (0, getTokenRequestErrorPrefix_1.tokenRequestErrorMessage)(err, 'refreshing tokens', 'refreshTokensForSasjs', types_1.ServerType.Sasjs, url);
6979
7256
  });
6980
7257
  return authResponse;
6981
7258
  });
@@ -7004,7 +7281,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7004
7281
  Object.defineProperty(exports, "__esModule", ({ value: true }));
7005
7282
  exports.refreshTokensForViya = refreshTokensForViya;
7006
7283
  const types_1 = __webpack_require__(3631);
7007
- const error_1 = __webpack_require__(6340);
7008
7284
  const form_data_1 = __importDefault(__webpack_require__(1894));
7009
7285
  const utils_1 = __webpack_require__(9266);
7010
7286
  const getTokenRequestErrorPrefix_1 = __webpack_require__(1087);
@@ -7035,7 +7311,7 @@ function refreshTokensForViya(requestClient, clientId, clientSecret, refreshToke
7035
7311
  .post(url, formData, undefined, 'multipart/form-data; boundary=' + formData._boundary, headers)
7036
7312
  .then((res) => res.result)
7037
7313
  .catch((err) => {
7038
- throw (0, error_1.prefixMessage)(err, (0, getTokenRequestErrorPrefix_1.getTokenRequestErrorPrefix)('refreshing tokens', 'refreshTokensForViya', types_1.ServerType.SasViya, url, formData, headers, clientId, clientSecret));
7314
+ throw (0, getTokenRequestErrorPrefix_1.tokenRequestErrorMessage)(err, 'refreshing tokens', 'refreshTokensForViya', types_1.ServerType.SasViya, url, formData, headers, clientId, clientSecret);
7039
7315
  });
7040
7316
  return authResponse;
7041
7317
  });
@@ -8121,6 +8397,7 @@ const SAS9AuthError_1 = __webpack_require__(2079);
8121
8397
  const utils_1 = __webpack_require__(9266);
8122
8398
  const InvalidSASjsCsrfError_1 = __webpack_require__(4001);
8123
8399
  const host_1 = __webpack_require__(5334);
8400
+ const responseReceived_1 = __webpack_require__(5775);
8124
8401
  const isNode_1 = __webpack_require__(6308);
8125
8402
  const mockReadiness_1 = __webpack_require__(2600);
8126
8403
  const MockReadinessError_1 = __webpack_require__(314);
@@ -8415,19 +8692,19 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
8415
8692
  throw (0, error_1.prefixMessage)(err, 'Error while executing callback in handleError. ');
8416
8693
  });
8417
8694
  }
8418
- throw e;
8695
+ throw (0, responseReceived_1.markResponseReceived)(e, true);
8419
8696
  }
8420
8697
  else if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
8421
- throw new errors_1.NotFoundError(response.config.url);
8698
+ throw (0, responseReceived_1.markResponseReceived)(new errors_1.NotFoundError(response.config.url), true);
8422
8699
  }
8423
8700
  else if ((response === null || response === void 0 ? void 0 : response.status) === 502) {
8424
8701
  if (debug)
8425
- throw new errors_1.InternalServerError();
8702
+ throw (0, responseReceived_1.markResponseReceived)(new errors_1.InternalServerError(), true);
8426
8703
  else
8427
8704
  return;
8428
8705
  }
8429
8706
  if (e.isAxiosError && e.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
8430
- throw new errors_1.CertificateError(e.message);
8707
+ throw (0, responseReceived_1.markResponseReceived)(new errors_1.CertificateError(e.message), false);
8431
8708
  }
8432
8709
  if (e.isAxiosError &&
8433
8710
  !response &&
@@ -8452,18 +8729,20 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
8452
8729
  }
8453
8730
  return yield callback();
8454
8731
  }
8455
- catch (_b) {
8456
- // Session could not be recovered — surface LoginRequiredError
8457
- throw new errors_1.LoginRequiredError();
8732
+ catch (retryError) {
8733
+ // Session could not be recovered — surface LoginRequiredError. The
8734
+ // retry itself may have reached the server and been refused, which is
8735
+ // not the same as never arriving: the marker follows the retry's own
8736
+ // answer, not the opaque network error that started this.
8737
+ throw (0, responseReceived_1.markResponseReceived)(new errors_1.LoginRequiredError(), (0, responseReceived_1.responseWasReceived)(retryError));
8458
8738
  }
8459
8739
  finally {
8460
8740
  this.isRecoveringFromNetworkError = false;
8461
8741
  }
8462
8742
  }
8463
8743
  if (e.message)
8464
- throw e;
8465
- else
8466
- throw (0, error_1.prefixMessage)(e, 'Error while handling error. ');
8744
+ throw (0, responseReceived_1.markResponseReceived)(e, Boolean(response));
8745
+ throw (0, responseReceived_1.markResponseReceived)((0, error_1.prefixMessage)(e, 'Error while handling error. '), Boolean(response));
8467
8746
  });
8468
8747
  this.createHttpClient(baseUrl, httpsAgentOptions);
8469
8748
  if (requestsLimit)
@@ -8732,7 +9011,27 @@ exports.RequestClient = RequestClient;
8732
9011
  * included here.
8733
9012
  */
8734
9013
  const isTokenRefreshUrl = (url) => !!url && /(^|\/)auth\/refresh(\?|$)/.test(url);
9014
+ /**
9015
+ * Raises the error a response status implies, marked as one built from a
9016
+ * response.
9017
+ *
9018
+ * The marking has to happen here: every error below is a new object carrying
9019
+ * the body, so the axios error - the thing that knew a response had arrived -
9020
+ * is gone by the time a caller catches it (sasjs/adapter#895). A 401 from a
9021
+ * refresh route is named by `throwForStatus` as a rejected refresh token
9022
+ * (sasjs/adapter#975); this marks it as an answer that arrived, so a transport
9023
+ * failure and a refusal are not reported with the same title.
9024
+ */
8735
9025
  const throwIfError = (response) => {
9026
+ try {
9027
+ throwForStatus(response);
9028
+ }
9029
+ catch (error) {
9030
+ throw (0, responseReceived_1.markResponseReceived)(error, true);
9031
+ }
9032
+ };
9033
+ exports.throwIfError = throwIfError;
9034
+ const throwForStatus = (response) => {
8736
9035
  var _a, _b, _c, _d, _e, _f, _g, _h;
8737
9036
  switch (response.status) {
8738
9037
  case 400:
@@ -8784,7 +9083,6 @@ const throwIfError = (response) => {
8784
9083
  throw error;
8785
9084
  }
8786
9085
  };
8787
- exports.throwIfError = throwIfError;
8788
9086
  const parseError = (data) => {
8789
9087
  if (!data)
8790
9088
  return null;
@@ -9436,6 +9734,78 @@ const waitForMockReadiness = (ready, config) => __awaiter(void 0, void 0, void 0
9436
9734
  exports.waitForMockReadiness = waitForMockReadiness;
9437
9735
 
9438
9736
 
9737
+ /***/ },
9738
+
9739
+ /***/ 5775
9740
+ (__unused_webpack_module, exports) {
9741
+
9742
+ "use strict";
9743
+ var __webpack_unused_export__;
9744
+
9745
+ /**
9746
+ * Whether a failed request came back with an HTTP response.
9747
+ *
9748
+ * The request client turns a response into an error of its own - a 401 becomes a
9749
+ * `LoginRequiredError` carrying the body, a 404 a `NotFoundError` - so the axios
9750
+ * error, and with it the `response` property, is gone by the time a caller sees
9751
+ * the failure. That is why this cannot be inferred at the call site from the
9752
+ * error's shape: `throwIfError` has already replaced the shape.
9753
+ *
9754
+ * So the boundary stamps what it knows (`markResponseReceived`) and callers ask
9755
+ * this module. The `response` property is still the fallback, for errors that
9756
+ * never passed through the request client - but the marker wins when both are
9757
+ * present, because the boundary saw the response itself rather than a rebuilt
9758
+ * error that may or may not carry it.
9759
+ */
9760
+ __webpack_unused_export__ = ({ value: true });
9761
+ exports.responseWasReceived = exports.markResponseReceived = void 0;
9762
+ /** The property the request client leaves on an error it built. */
9763
+ const MARKER = 'responseReceived';
9764
+ /**
9765
+ * Records on an error whether the request it reports on came back with a
9766
+ * response. Returns the same error, so a throw site reads `throw mark(...)`.
9767
+ * Marks are kept but hidden: the error travels to the caller, where a new
9768
+ * enumerable field would show up in a log, a `JSON.stringify`, or a
9769
+ * deep-equality assertion against an unmarked copy - a difference nothing to do
9770
+ * with the request, reported as though it were.
9771
+ *
9772
+ * A frozen error cannot take the mark; it is returned unchanged and
9773
+ * `responseWasReceived` falls back to whatever `response` the error carries.
9774
+ */
9775
+ const markResponseReceived = (error, received) => {
9776
+ if (!error || (typeof error !== 'object' && typeof error !== 'function'))
9777
+ return error;
9778
+ try {
9779
+ Object.defineProperty(error, MARKER, {
9780
+ value: received,
9781
+ enumerable: false,
9782
+ configurable: true,
9783
+ writable: true
9784
+ });
9785
+ }
9786
+ catch (_a) {
9787
+ // not extensible: leave it unmarked rather than fail the request twice
9788
+ }
9789
+ return error;
9790
+ };
9791
+ exports.markResponseReceived = markResponseReceived;
9792
+ /**
9793
+ * Whether the failure behind this error came with an HTTP response.
9794
+ *
9795
+ * `false` is what a transport failure looks like: a wrong URL, a closed port, a
9796
+ * VPN that is down, a certificate that does not verify. The message that
9797
+ * accompanies such a failure is the transport's own (`connect ETIMEDOUT
9798
+ * 192.0.2.1:443`), not something a server said.
9799
+ */
9800
+ const responseWasReceived = (error) => {
9801
+ const marked = error === null || error === void 0 ? void 0 : error.responseReceived;
9802
+ if (typeof marked === 'boolean')
9803
+ return marked;
9804
+ return Boolean(error === null || error === void 0 ? void 0 : error.response);
9805
+ };
9806
+ exports.responseWasReceived = responseWasReceived;
9807
+
9808
+
9439
9809
  /***/ },
9440
9810
 
9441
9811
  /***/ 5777
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  "license": "ISC",
38
38
  "devDependencies": {
39
39
  "@cypress/webpack-preprocessor": "8.0.0",
40
- "@sasjs/release": "0.11.1",
40
+ "@sasjs/release": "0.18.0",
41
41
  "@types/cors": "2.8.19",
42
42
  "@types/express": "5.0.6",
43
43
  "@types/jest": "30.0.0",
@@ -120,7 +120,7 @@
120
120
  "safer-buffer": "npm:@socketregistry/safer-buffer@1.0.10",
121
121
  "side-channel": "npm:@socketregistry/side-channel@1.0.10"
122
122
  },
123
- "version": "6.1.5",
123
+ "version": "6.1.7",
124
124
  "engines": {
125
125
  "node": ">=22"
126
126
  },
@@ -122,4 +122,15 @@ export declare class RequestClient implements HttpClient {
122
122
  };
123
123
  private createHttpClient;
124
124
  }
125
+ /**
126
+ * Raises the error a response status implies, marked as one built from a
127
+ * response.
128
+ *
129
+ * The marking has to happen here: every error below is a new object carrying
130
+ * the body, so the axios error - the thing that knew a response had arrived -
131
+ * is gone by the time a caller catches it (sasjs/adapter#895). A 401 from a
132
+ * refresh route is named by `throwForStatus` as a rejected refresh token
133
+ * (sasjs/adapter#975); this marks it as an answer that arrived, so a transport
134
+ * failure and a refusal are not reported with the same title.
135
+ */
125
136
  export declare const throwIfError: (response: AxiosResponse) => void;