@sasjs/adapter 6.1.4 → 6.1.6
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/auth/getAccessTokenForSasjs.js +1 -2
- package/auth/getAccessTokenForViya.js +1 -2
- package/auth/getTokenRequestErrorPrefix.d.ts +50 -9
- package/auth/getTokenRequestErrorPrefix.js +85 -16
- package/auth/redactCredentials.d.ts +42 -0
- package/auth/redactCredentials.js +187 -0
- package/auth/refreshTokensForSasjs.js +1 -2
- package/auth/refreshTokensForViya.js +1 -2
- package/dist/minified_sas9.js +105 -11
- package/dist/sasjs-adapter.js +391 -36
- package/package.json +1 -1
- package/request/RequestClient.d.ts +11 -0
- package/request/RequestClient.js +33 -11
- package/request/responseReceived.d.ts +36 -0
- package/request/responseReceived.js +63 -0
package/dist/sasjs-adapter.js
CHANGED
|
@@ -6444,7 +6444,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
6444
6444
|
};
|
|
6445
6445
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
6446
6446
|
exports.getAccessTokenForSasjs = getAccessTokenForSasjs;
|
|
6447
|
-
const error_1 = __webpack_require__(6340);
|
|
6448
6447
|
const getTokenRequestErrorPrefix_1 = __webpack_require__(1087);
|
|
6449
6448
|
const types_1 = __webpack_require__(3631);
|
|
6450
6449
|
const apiBasePath_1 = __webpack_require__(6838);
|
|
@@ -6472,7 +6471,7 @@ function getAccessTokenForSasjs(requestClient_1, clientId_1, authCode_1) {
|
|
|
6472
6471
|
};
|
|
6473
6472
|
})
|
|
6474
6473
|
.catch((err) => {
|
|
6475
|
-
throw (0,
|
|
6474
|
+
throw (0, getTokenRequestErrorPrefix_1.tokenRequestErrorMessage)(err, 'fetching access token', 'getAccessTokenForSasjs', types_1.ServerType.Sasjs, url, data, undefined, clientId);
|
|
6476
6475
|
});
|
|
6477
6476
|
});
|
|
6478
6477
|
}
|
|
@@ -6497,7 +6496,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
6497
6496
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
6498
6497
|
exports.getAccessTokenForViya = getAccessTokenForViya;
|
|
6499
6498
|
const types_1 = __webpack_require__(3631);
|
|
6500
|
-
const error_1 = __webpack_require__(6340);
|
|
6501
6499
|
const errors_1 = __webpack_require__(7388);
|
|
6502
6500
|
const getTokenRequestErrorPrefix_1 = __webpack_require__(1087);
|
|
6503
6501
|
/**
|
|
@@ -6532,7 +6530,7 @@ function getAccessTokenForViya(requestClient, clientId, clientSecret, authCode)
|
|
|
6532
6530
|
.catch((err) => {
|
|
6533
6531
|
if (err instanceof errors_1.CertificateError)
|
|
6534
6532
|
throw err;
|
|
6535
|
-
throw (0,
|
|
6533
|
+
throw (0, getTokenRequestErrorPrefix_1.tokenRequestErrorMessage)(err, 'fetching access token', 'getAccessTokenForViya', types_1.ServerType.SasViya, url, dataJson, headers, clientId, clientSecret);
|
|
6536
6534
|
});
|
|
6537
6535
|
return authResponse;
|
|
6538
6536
|
});
|
|
@@ -6548,35 +6546,60 @@ function getAccessTokenForViya(requestClient, clientId, clientSecret, authCode)
|
|
|
6548
6546
|
var __webpack_unused_export__;
|
|
6549
6547
|
|
|
6550
6548
|
__webpack_unused_export__ = ({ value: true });
|
|
6551
|
-
__webpack_unused_export__ = exports.
|
|
6549
|
+
__webpack_unused_export__ = exports.tokenRequestErrorMessage = exports.vV = void 0;
|
|
6552
6550
|
const types_1 = __webpack_require__(3631);
|
|
6551
|
+
const error_1 = __webpack_require__(6340);
|
|
6552
|
+
const responseReceived_1 = __webpack_require__(5775);
|
|
6553
|
+
const redactCredentials_1 = __webpack_require__(6894);
|
|
6553
6554
|
const getServerName = (server) => server === types_1.ServerType.SasViya ? 'Viya' : 'Sasjs';
|
|
6554
|
-
|
|
6555
|
+
/**
|
|
6556
|
+
* What follows the request details: the server's answer, or the statement that
|
|
6557
|
+
* there was none.
|
|
6558
|
+
*
|
|
6559
|
+
* A transport failure - a wrong URL, a closed port, a VPN that is down, a
|
|
6560
|
+
* certificate that does not verify - carries no response, so calling its text
|
|
6561
|
+
* "Response from Viya" claims something the server never said. That is
|
|
6562
|
+
* sasjs/adapter#895: the reader was told the target answered with
|
|
6563
|
+
* `connect ETIMEDOUT`.
|
|
6564
|
+
*/
|
|
6565
|
+
const getResponseTitle = (server, responseReceived) => responseReceived
|
|
6566
|
+
? `Response from ${getServerName(server)} is below.`
|
|
6567
|
+
: `No response from ${getServerName(server)} - the request did not reach it.`;
|
|
6555
6568
|
/**
|
|
6556
6569
|
* Forms error prefix for requests related to token operations.
|
|
6557
6570
|
* @param operation - string describing operation ('fetching access token' or 'refreshing tokens').
|
|
6558
6571
|
* @param funcName - name of the function sent the request.
|
|
6559
6572
|
* @param server - server type (SASVIYA or SASJS).
|
|
6560
6573
|
* @param url - endpoint used to send the request.
|
|
6561
|
-
* @param data - request payload.
|
|
6562
|
-
*
|
|
6563
|
-
*
|
|
6564
|
-
* @param
|
|
6565
|
-
*
|
|
6574
|
+
* @param data - request payload. Object and form-encoded payloads are redacted
|
|
6575
|
+
* field by field, at any depth; any other text body is reported as a shape
|
|
6576
|
+
* rather than printed.
|
|
6577
|
+
* @param headers - request headers. An authorization value keeps its scheme and
|
|
6578
|
+
* loses its credential.
|
|
6579
|
+
* @param clientId - client ID to authenticate with. Printed: it names which
|
|
6580
|
+
* client failed.
|
|
6581
|
+
* @param clientSecret - client secret to authenticate with. Replaced, never
|
|
6582
|
+
* printed; the report states that one was supplied.
|
|
6583
|
+
* @param responseReceived - whether the request came back with a response
|
|
6584
|
+
* (default `true`). When it did not, the title says so rather than presenting
|
|
6585
|
+
* the transport's own message as an answer from the server.
|
|
6586
|
+
* @returns - string containing request information, with every credential
|
|
6587
|
+
* named rather than printed. A failure is pasted into tickets and kept in CI
|
|
6588
|
+
* logs, so the report never carries a value that could be used as one. Example:
|
|
6566
6589
|
* Error while fetching access token from /SASLogon/oauth/token
|
|
6567
6590
|
* Thrown by the @sasjs/adapter getAccessTokenForViya function.
|
|
6568
6591
|
* Payload:
|
|
6569
6592
|
* {
|
|
6570
6593
|
* "grant_type": "authorization_code",
|
|
6571
|
-
* "code": "
|
|
6594
|
+
* "code": "<redacted>"
|
|
6572
6595
|
* }
|
|
6573
6596
|
* Headers:
|
|
6574
6597
|
* {
|
|
6575
|
-
* "Authorization": "Basic
|
|
6598
|
+
* "Authorization": "Basic <redacted>",
|
|
6576
6599
|
* "Accept": "application/json"
|
|
6577
6600
|
* }
|
|
6578
6601
|
* ClientId: exampleClientId
|
|
6579
|
-
* ClientSecret:
|
|
6602
|
+
* ClientSecret: <redacted>
|
|
6580
6603
|
*
|
|
6581
6604
|
* Response from Viya is below.
|
|
6582
6605
|
* Auth error: {
|
|
@@ -6584,37 +6607,81 @@ const getResponseTitle = (server) => `Response from ${getServerName(server)} is
|
|
|
6584
6607
|
* "error_description": "No scopes were granted"
|
|
6585
6608
|
* }
|
|
6586
6609
|
*/
|
|
6587
|
-
const getTokenRequestErrorPrefix = (operation, funcName, server, url, data, headers, clientId, clientSecret) => {
|
|
6610
|
+
const getTokenRequestErrorPrefix = (operation, funcName, server, url, data, headers, clientId, clientSecret, responseReceived = true) => {
|
|
6588
6611
|
const stringify = (obj) => JSON.stringify(obj, null, 2);
|
|
6589
6612
|
const lines = [
|
|
6590
6613
|
`Error while ${operation} from ${url}`,
|
|
6591
6614
|
`Thrown by the @sasjs/adapter ${funcName} function.`
|
|
6592
6615
|
];
|
|
6616
|
+
// The request carries the credentials that minted the token: the header is the
|
|
6617
|
+
// client pair base64-encoded together, the body a refresh token or an
|
|
6618
|
+
// authorization code. A failure is pasted into tickets, so the values are
|
|
6619
|
+
// named and not printed (#895).
|
|
6593
6620
|
if (data) {
|
|
6621
|
+
const payload = (0, redactCredentials_1.redactPayload)(data);
|
|
6594
6622
|
lines.push('Payload:');
|
|
6595
|
-
lines.push(stringify(
|
|
6623
|
+
lines.push(typeof payload === 'string' ? payload : stringify(payload));
|
|
6596
6624
|
}
|
|
6597
6625
|
if (headers) {
|
|
6598
6626
|
lines.push('Headers:');
|
|
6599
|
-
lines.push(stringify(headers));
|
|
6627
|
+
lines.push(stringify((0, redactCredentials_1.redactHeaders)(headers)));
|
|
6600
6628
|
}
|
|
6629
|
+
// The client id names which client failed and is not a credential; the secret
|
|
6630
|
+
// beside it is, so it is stated as supplied rather than printed.
|
|
6601
6631
|
if (clientId)
|
|
6602
6632
|
lines.push(`ClientId: ${clientId}`);
|
|
6603
6633
|
if (clientSecret)
|
|
6604
|
-
lines.push(`ClientSecret: ${
|
|
6634
|
+
lines.push(`ClientSecret: ${redactCredentials_1.REDACTED}`);
|
|
6605
6635
|
lines.push('');
|
|
6606
|
-
lines.push(`${getResponseTitle(server)}`);
|
|
6636
|
+
lines.push(`${getResponseTitle(server, responseReceived)}`);
|
|
6607
6637
|
lines.push('');
|
|
6608
6638
|
return lines.join(`\n`);
|
|
6609
6639
|
};
|
|
6610
|
-
exports.
|
|
6640
|
+
exports.vV = getTokenRequestErrorPrefix;
|
|
6641
|
+
/**
|
|
6642
|
+
* The message for a failed token request: how the request was made, then what
|
|
6643
|
+
* came back.
|
|
6644
|
+
*
|
|
6645
|
+
* Every caller holds the error, so this is where "did the server answer?" is
|
|
6646
|
+
* decided - once. Threading a boolean through the optional parameters of
|
|
6647
|
+
* `getTokenRequestErrorPrefix` instead leaves the short call sites padding
|
|
6648
|
+
* arguments they do not have, which is how a later caller gets it wrong.
|
|
6649
|
+
*
|
|
6650
|
+
* @param error - the rejection from the request client.
|
|
6651
|
+
* @param operation - string describing operation ('fetching access token' or 'refreshing tokens').
|
|
6652
|
+
* @param funcName - name of the function that sent the request.
|
|
6653
|
+
* @param server - server type (SASVIYA or SASJS).
|
|
6654
|
+
* @param url - endpoint used to send the request.
|
|
6655
|
+
* @param data - request payload. Object and form-encoded payloads are redacted
|
|
6656
|
+
* field by field, at any depth; any other text body is reported as a shape
|
|
6657
|
+
* rather than printed.
|
|
6658
|
+
* @param headers - request headers. An authorization value keeps its scheme and
|
|
6659
|
+
* loses its credential.
|
|
6660
|
+
* @param clientId - client ID to authenticate with. Printed: it names which
|
|
6661
|
+
* client failed.
|
|
6662
|
+
* @param clientSecret - client secret to authenticate with. Replaced, never
|
|
6663
|
+
* printed; the report states that one was supplied.
|
|
6664
|
+
* @returns - the error, with the prefix in front of its message.
|
|
6665
|
+
*/
|
|
6666
|
+
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)));
|
|
6667
|
+
exports.tokenRequestErrorMessage = tokenRequestErrorMessage;
|
|
6611
6668
|
/**
|
|
6612
6669
|
* Parse error prefix to get response payload.
|
|
6670
|
+
*
|
|
6671
|
+
* A prefix built for a request that never reached the server carries the
|
|
6672
|
+
* transport's own message where the payload would be, so the split is made on
|
|
6673
|
+
* whichever title the prefix holds rather than assuming one.
|
|
6674
|
+
*
|
|
6613
6675
|
* @param prefix - error prefix generated by getTokenRequestErrorPrefix function.
|
|
6614
6676
|
* @param server - server type (SASVIYA or SASJS).
|
|
6615
6677
|
* @returns - response payload.
|
|
6616
6678
|
*/
|
|
6617
|
-
const getTokenRequestErrorPrefixResponse = (prefix, server) =>
|
|
6679
|
+
const getTokenRequestErrorPrefixResponse = (prefix, server) => {
|
|
6680
|
+
const receivedTitle = `${getResponseTitle(server, true)}\n`;
|
|
6681
|
+
if (prefix.includes(receivedTitle))
|
|
6682
|
+
return prefix.split(receivedTitle).pop();
|
|
6683
|
+
return prefix.split(`${getResponseTitle(server, false)}\n`).pop();
|
|
6684
|
+
};
|
|
6618
6685
|
__webpack_unused_export__ = getTokenRequestErrorPrefixResponse;
|
|
6619
6686
|
|
|
6620
6687
|
|
|
@@ -6931,6 +6998,202 @@ function openWebPage(url_1) {
|
|
|
6931
6998
|
}
|
|
6932
6999
|
|
|
6933
7000
|
|
|
7001
|
+
/***/ },
|
|
7002
|
+
|
|
7003
|
+
/***/ 6894
|
|
7004
|
+
(__unused_webpack_module, exports) {
|
|
7005
|
+
|
|
7006
|
+
"use strict";
|
|
7007
|
+
var __webpack_unused_export__;
|
|
7008
|
+
|
|
7009
|
+
__webpack_unused_export__ = ({ value: true });
|
|
7010
|
+
exports.redactPayload = exports.redactHeaders = exports.eP = exports.uE = exports.REDACTED = void 0;
|
|
7011
|
+
/**
|
|
7012
|
+
* What a failed token request may say about the request it sent.
|
|
7013
|
+
*
|
|
7014
|
+
* A token failure is read by a person, pasted into a ticket and captured in CI
|
|
7015
|
+
* logs, and the request behind it carries the credentials that minted it: an
|
|
7016
|
+
* `Authorization` header holding the client id and secret base64-encoded
|
|
7017
|
+
* together, a body holding a refresh token, and the authorization code itself.
|
|
7018
|
+
* Printing those turns one error report into a credential disclosure, so this
|
|
7019
|
+
* module names the values that are secret and replaces each with a marker.
|
|
7020
|
+
*
|
|
7021
|
+
* The marker is a fixed string, not an empty one, so a reader can tell "this was
|
|
7022
|
+
* supplied" from "this was not". Keys are matched case-insensitively.
|
|
7023
|
+
*/
|
|
7024
|
+
exports.REDACTED = '<redacted>';
|
|
7025
|
+
/**
|
|
7026
|
+
* The parameter names that carry a credential, in any of the spellings the
|
|
7027
|
+
* estate uses: OAuth's snake case, the adapter's camel case, and the headers a
|
|
7028
|
+
* server sets alongside a session.
|
|
7029
|
+
*/
|
|
7030
|
+
const SECRET_KEYS = [
|
|
7031
|
+
'authorization',
|
|
7032
|
+
'token',
|
|
7033
|
+
'cookie',
|
|
7034
|
+
'x-csrf-token',
|
|
7035
|
+
'x-xsrf-token',
|
|
7036
|
+
'client_secret',
|
|
7037
|
+
'clientsecret',
|
|
7038
|
+
'secret',
|
|
7039
|
+
'password',
|
|
7040
|
+
'passwd',
|
|
7041
|
+
'refresh_token',
|
|
7042
|
+
'refreshtoken',
|
|
7043
|
+
'access_token',
|
|
7044
|
+
'accesstoken',
|
|
7045
|
+
'id_token',
|
|
7046
|
+
'idtoken',
|
|
7047
|
+
'code'
|
|
7048
|
+
];
|
|
7049
|
+
/** A parameter name with the spellings that vary (case, hyphen, underscore) removed. */
|
|
7050
|
+
const normalise = (key) => key.toLowerCase().replace(/[\s_-]/g, '');
|
|
7051
|
+
/**
|
|
7052
|
+
* What a form-encoded decoder is allowed to read as a parameter name.
|
|
7053
|
+
*
|
|
7054
|
+
* Deliberately narrow: a name carrying `{`, `[`, `"`, `%`, `&`, whitespace or a
|
|
7055
|
+
* second `=` is not a parameter of a form-encoded body, it is text this module
|
|
7056
|
+
* cannot read - and a body it cannot read is reported as a shape, never printed.
|
|
7057
|
+
*/
|
|
7058
|
+
const PARAMETER_NAME = /^[A-Za-z0-9_.~[\]]+$/;
|
|
7059
|
+
/** Whether a parameter name carries a credential. */
|
|
7060
|
+
const isSecretKey = (key) => SECRET_KEYS.map(normalise).includes(normalise(key));
|
|
7061
|
+
exports.uE = isSecretKey;
|
|
7062
|
+
/**
|
|
7063
|
+
* An `Authorization` value with its scheme kept and its credential removed.
|
|
7064
|
+
*
|
|
7065
|
+
* The scheme stays because it is the part a reader diagnoses with: `Basic`
|
|
7066
|
+
* means a client pair, `Bearer` means a token, and the two fail in different
|
|
7067
|
+
* ways.
|
|
7068
|
+
*/
|
|
7069
|
+
const redactAuthorizationValue = (value) => {
|
|
7070
|
+
var _a;
|
|
7071
|
+
const scheme = (_a = /^(basic|bearer|negotiate|digest)\b/i.exec(String(value))) === null || _a === void 0 ? void 0 : _a[0];
|
|
7072
|
+
return scheme ? `${scheme} ${exports.REDACTED}` : exports.REDACTED;
|
|
7073
|
+
};
|
|
7074
|
+
exports.eP = redactAuthorizationValue;
|
|
7075
|
+
/** Request headers, with the credential-bearing ones redacted. */
|
|
7076
|
+
const redactHeaders = (headers) => Object.fromEntries(Object.entries(headers).map(([key, value]) => [
|
|
7077
|
+
key,
|
|
7078
|
+
(0, exports.uE)(key) ? (0, exports.eP)(value) : value
|
|
7079
|
+
]));
|
|
7080
|
+
exports.redactHeaders = redactHeaders;
|
|
7081
|
+
const MAX_DEPTH = 20;
|
|
7082
|
+
/**
|
|
7083
|
+
* A value, with secret-named keys redacted at any depth.
|
|
7084
|
+
*
|
|
7085
|
+
* Two guards belong here because this is where the walk happens, and both are
|
|
7086
|
+
* about a payload the reporter cannot print:
|
|
7087
|
+
*
|
|
7088
|
+
* - a byte view - a Buffer, a typed array, an ArrayBuffer - is a body, and walking
|
|
7089
|
+
* one as an object emits a numbered key per byte (`{"0":103,"1":114,...}`), the
|
|
7090
|
+
* body reproduced as clearly as the text it came from;
|
|
7091
|
+
* - a payload that refers to itself, or nests past `MAX_DEPTH`, would replace the
|
|
7092
|
+
* token failure with `RangeError: Maximum call stack size exceeded`. Both are
|
|
7093
|
+
* reported as a shape instead.
|
|
7094
|
+
*
|
|
7095
|
+
* `seen` holds the objects on the CURRENT path, not every object ever visited, so a
|
|
7096
|
+
* body that shares a sub-object between two keys is walked twice rather than
|
|
7097
|
+
* reported as circular - it is not.
|
|
7098
|
+
*/
|
|
7099
|
+
const redactValue = (value, seen = new WeakSet(), depth = 0) => {
|
|
7100
|
+
if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer)
|
|
7101
|
+
return 'binary body - values redacted';
|
|
7102
|
+
if (!value || typeof value !== 'object')
|
|
7103
|
+
return value;
|
|
7104
|
+
if (seen.has(value))
|
|
7105
|
+
return 'circular body - values redacted';
|
|
7106
|
+
if (depth >= MAX_DEPTH)
|
|
7107
|
+
return 'nested too deep - values redacted';
|
|
7108
|
+
seen.add(value);
|
|
7109
|
+
try {
|
|
7110
|
+
if (Array.isArray(value))
|
|
7111
|
+
return value.map((inner) => redactValue(inner, seen, depth + 1));
|
|
7112
|
+
return Object.fromEntries(Object.entries(value).map(([key, inner]) => [
|
|
7113
|
+
key,
|
|
7114
|
+
(0, exports.uE)(key) ? exports.REDACTED : redactValue(inner, seen, depth + 1)
|
|
7115
|
+
]));
|
|
7116
|
+
}
|
|
7117
|
+
finally {
|
|
7118
|
+
seen.delete(value);
|
|
7119
|
+
}
|
|
7120
|
+
};
|
|
7121
|
+
/**
|
|
7122
|
+
* A body that arrived as text, which a caller is free to pass: the parameter is
|
|
7123
|
+
* typed to admit one.
|
|
7124
|
+
*
|
|
7125
|
+
* Form-encoded text is rebuilt pair by pair so the parameters that are not
|
|
7126
|
+
* secrets stay readable, and anything else is reported as a shape rather than
|
|
7127
|
+
* echoed, because a body this module cannot read is a body it cannot redact.
|
|
7128
|
+
*
|
|
7129
|
+
* A JSON body is never form-encoded, whatever it contains. Base64 carries `=`
|
|
7130
|
+
* padding, so `{"client_secret":"YWJjWg=="}` splits into a key that is the
|
|
7131
|
+
* secret's own text and a value of `"}"` - the key is not a secret *name*, so no
|
|
7132
|
+
* key check catches it, and the secret is printed as though it were a parameter
|
|
7133
|
+
* name. Structured text therefore takes the shape branch on its opening
|
|
7134
|
+
* character, before any splitting.
|
|
7135
|
+
*/
|
|
7136
|
+
const redactText = (text) => {
|
|
7137
|
+
const trimmed = text.trim();
|
|
7138
|
+
if (!trimmed)
|
|
7139
|
+
return trimmed;
|
|
7140
|
+
if (/^[{[]/.test(trimmed))
|
|
7141
|
+
return 'text body - values redacted';
|
|
7142
|
+
// A linear test, not a regular expression: the obvious pattern for "pairs
|
|
7143
|
+
// joined by &" nests quantifiers and backtracks exponentially on a string like
|
|
7144
|
+
// `!=&!=&!=&...` (CodeQL js/redos, found on this branch).
|
|
7145
|
+
const pairs = trimmed.split('&');
|
|
7146
|
+
const isFormEncoded = !/\s/.test(trimmed) &&
|
|
7147
|
+
pairs.every((pair) => pair.indexOf('=') > 0) &&
|
|
7148
|
+
pairs.every((pair) => PARAMETER_NAME.test(pair.slice(0, pair.indexOf('='))));
|
|
7149
|
+
if (isFormEncoded) {
|
|
7150
|
+
const redacted = {};
|
|
7151
|
+
for (const pair of pairs) {
|
|
7152
|
+
const [key, ...rest] = pair.split('=');
|
|
7153
|
+
const value = rest.join('=');
|
|
7154
|
+
redacted[key] = (0, exports.uE)(key) ? exports.REDACTED : value;
|
|
7155
|
+
}
|
|
7156
|
+
return redacted;
|
|
7157
|
+
}
|
|
7158
|
+
// not form-encoded: a JSON string, a SAS log, an HTML page. It is not parsed
|
|
7159
|
+
// here because a half-parsed body is worse than a stated shape.
|
|
7160
|
+
return 'text body - values redacted';
|
|
7161
|
+
};
|
|
7162
|
+
/**
|
|
7163
|
+
* A request payload, with the credential-bearing values redacted.
|
|
7164
|
+
*
|
|
7165
|
+
* The shapes that reach this function, each handled on its own terms: a plain
|
|
7166
|
+
* object or array is walked, so a secret one level down is redacted like one at the
|
|
7167
|
+
* top; a byte view - a Buffer or any typed array - is reported as a shape, because
|
|
7168
|
+
* walking it emits a key per byte; `URLSearchParams` (the form the OAuth code
|
|
7169
|
+
* exchange is sent as) is rebuilt pair by pair; a string that parses as
|
|
7170
|
+
* `key=value&key=value` is rebuilt the same way; and multipart form data (the
|
|
7171
|
+
* refresh) is reported as its shape rather than its fields, because its parts are a
|
|
7172
|
+
* stream the request still needs.
|
|
7173
|
+
*
|
|
7174
|
+
* `redactValue` carries the byte-view and cycle guards, so they hold at every depth
|
|
7175
|
+
* rather than only here.
|
|
7176
|
+
*/
|
|
7177
|
+
const redactPayload = (data) => {
|
|
7178
|
+
if (!data)
|
|
7179
|
+
return data;
|
|
7180
|
+
if (typeof data === 'string')
|
|
7181
|
+
return redactText(data);
|
|
7182
|
+
const candidate = data;
|
|
7183
|
+
if (typeof candidate.getBoundary === 'function')
|
|
7184
|
+
return 'multipart form data - fields and values redacted';
|
|
7185
|
+
if (typeof candidate.entries === 'function' &&
|
|
7186
|
+
typeof candidate.get === 'function') {
|
|
7187
|
+
const redacted = {};
|
|
7188
|
+
for (const [key, value] of candidate.entries())
|
|
7189
|
+
redacted[key] = (0, exports.uE)(key) ? exports.REDACTED : value;
|
|
7190
|
+
return redacted;
|
|
7191
|
+
}
|
|
7192
|
+
return redactValue(candidate);
|
|
7193
|
+
};
|
|
7194
|
+
exports.redactPayload = redactPayload;
|
|
7195
|
+
|
|
7196
|
+
|
|
6934
7197
|
/***/ },
|
|
6935
7198
|
|
|
6936
7199
|
/***/ 6725
|
|
@@ -6949,7 +7212,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
6949
7212
|
};
|
|
6950
7213
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
6951
7214
|
exports.refreshTokensForSasjs = refreshTokensForSasjs;
|
|
6952
|
-
const error_1 = __webpack_require__(6340);
|
|
6953
7215
|
const getTokenRequestErrorPrefix_1 = __webpack_require__(1087);
|
|
6954
7216
|
const types_1 = __webpack_require__(3631);
|
|
6955
7217
|
const apiBasePath_1 = __webpack_require__(6838);
|
|
@@ -6975,7 +7237,7 @@ function refreshTokensForSasjs(requestClient_1, refreshToken_1) {
|
|
|
6975
7237
|
};
|
|
6976
7238
|
})
|
|
6977
7239
|
.catch((err) => {
|
|
6978
|
-
throw (0,
|
|
7240
|
+
throw (0, getTokenRequestErrorPrefix_1.tokenRequestErrorMessage)(err, 'refreshing tokens', 'refreshTokensForSasjs', types_1.ServerType.Sasjs, url);
|
|
6979
7241
|
});
|
|
6980
7242
|
return authResponse;
|
|
6981
7243
|
});
|
|
@@ -7004,7 +7266,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7004
7266
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7005
7267
|
exports.refreshTokensForViya = refreshTokensForViya;
|
|
7006
7268
|
const types_1 = __webpack_require__(3631);
|
|
7007
|
-
const error_1 = __webpack_require__(6340);
|
|
7008
7269
|
const form_data_1 = __importDefault(__webpack_require__(1894));
|
|
7009
7270
|
const utils_1 = __webpack_require__(9266);
|
|
7010
7271
|
const getTokenRequestErrorPrefix_1 = __webpack_require__(1087);
|
|
@@ -7035,7 +7296,7 @@ function refreshTokensForViya(requestClient, clientId, clientSecret, refreshToke
|
|
|
7035
7296
|
.post(url, formData, undefined, 'multipart/form-data; boundary=' + formData._boundary, headers)
|
|
7036
7297
|
.then((res) => res.result)
|
|
7037
7298
|
.catch((err) => {
|
|
7038
|
-
throw (0,
|
|
7299
|
+
throw (0, getTokenRequestErrorPrefix_1.tokenRequestErrorMessage)(err, 'refreshing tokens', 'refreshTokensForViya', types_1.ServerType.SasViya, url, formData, headers, clientId, clientSecret);
|
|
7039
7300
|
});
|
|
7040
7301
|
return authResponse;
|
|
7041
7302
|
});
|
|
@@ -8121,6 +8382,7 @@ const SAS9AuthError_1 = __webpack_require__(2079);
|
|
|
8121
8382
|
const utils_1 = __webpack_require__(9266);
|
|
8122
8383
|
const InvalidSASjsCsrfError_1 = __webpack_require__(4001);
|
|
8123
8384
|
const host_1 = __webpack_require__(5334);
|
|
8385
|
+
const responseReceived_1 = __webpack_require__(5775);
|
|
8124
8386
|
const isNode_1 = __webpack_require__(6308);
|
|
8125
8387
|
const mockReadiness_1 = __webpack_require__(2600);
|
|
8126
8388
|
const MockReadinessError_1 = __webpack_require__(314);
|
|
@@ -8415,19 +8677,19 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
8415
8677
|
throw (0, error_1.prefixMessage)(err, 'Error while executing callback in handleError. ');
|
|
8416
8678
|
});
|
|
8417
8679
|
}
|
|
8418
|
-
throw e;
|
|
8680
|
+
throw (0, responseReceived_1.markResponseReceived)(e, true);
|
|
8419
8681
|
}
|
|
8420
8682
|
else if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
|
|
8421
|
-
throw new errors_1.NotFoundError(response.config.url);
|
|
8683
|
+
throw (0, responseReceived_1.markResponseReceived)(new errors_1.NotFoundError(response.config.url), true);
|
|
8422
8684
|
}
|
|
8423
8685
|
else if ((response === null || response === void 0 ? void 0 : response.status) === 502) {
|
|
8424
8686
|
if (debug)
|
|
8425
|
-
throw new errors_1.InternalServerError();
|
|
8687
|
+
throw (0, responseReceived_1.markResponseReceived)(new errors_1.InternalServerError(), true);
|
|
8426
8688
|
else
|
|
8427
8689
|
return;
|
|
8428
8690
|
}
|
|
8429
8691
|
if (e.isAxiosError && e.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
|
|
8430
|
-
throw new errors_1.CertificateError(e.message);
|
|
8692
|
+
throw (0, responseReceived_1.markResponseReceived)(new errors_1.CertificateError(e.message), false);
|
|
8431
8693
|
}
|
|
8432
8694
|
if (e.isAxiosError &&
|
|
8433
8695
|
!response &&
|
|
@@ -8452,18 +8714,20 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
8452
8714
|
}
|
|
8453
8715
|
return yield callback();
|
|
8454
8716
|
}
|
|
8455
|
-
catch (
|
|
8456
|
-
// Session could not be recovered — surface LoginRequiredError
|
|
8457
|
-
|
|
8717
|
+
catch (retryError) {
|
|
8718
|
+
// Session could not be recovered — surface LoginRequiredError. The
|
|
8719
|
+
// retry itself may have reached the server and been refused, which is
|
|
8720
|
+
// not the same as never arriving: the marker follows the retry's own
|
|
8721
|
+
// answer, not the opaque network error that started this.
|
|
8722
|
+
throw (0, responseReceived_1.markResponseReceived)(new errors_1.LoginRequiredError(), (0, responseReceived_1.responseWasReceived)(retryError));
|
|
8458
8723
|
}
|
|
8459
8724
|
finally {
|
|
8460
8725
|
this.isRecoveringFromNetworkError = false;
|
|
8461
8726
|
}
|
|
8462
8727
|
}
|
|
8463
8728
|
if (e.message)
|
|
8464
|
-
throw e;
|
|
8465
|
-
|
|
8466
|
-
throw (0, error_1.prefixMessage)(e, 'Error while handling error. ');
|
|
8729
|
+
throw (0, responseReceived_1.markResponseReceived)(e, Boolean(response));
|
|
8730
|
+
throw (0, responseReceived_1.markResponseReceived)((0, error_1.prefixMessage)(e, 'Error while handling error. '), Boolean(response));
|
|
8467
8731
|
});
|
|
8468
8732
|
this.createHttpClient(baseUrl, httpsAgentOptions);
|
|
8469
8733
|
if (requestsLimit)
|
|
@@ -8732,7 +8996,27 @@ exports.RequestClient = RequestClient;
|
|
|
8732
8996
|
* included here.
|
|
8733
8997
|
*/
|
|
8734
8998
|
const isTokenRefreshUrl = (url) => !!url && /(^|\/)auth\/refresh(\?|$)/.test(url);
|
|
8999
|
+
/**
|
|
9000
|
+
* Raises the error a response status implies, marked as one built from a
|
|
9001
|
+
* response.
|
|
9002
|
+
*
|
|
9003
|
+
* The marking has to happen here: every error below is a new object carrying
|
|
9004
|
+
* the body, so the axios error - the thing that knew a response had arrived -
|
|
9005
|
+
* is gone by the time a caller catches it (sasjs/adapter#895). A 401 from a
|
|
9006
|
+
* refresh route is named by `throwForStatus` as a rejected refresh token
|
|
9007
|
+
* (sasjs/adapter#975); this marks it as an answer that arrived, so a transport
|
|
9008
|
+
* failure and a refusal are not reported with the same title.
|
|
9009
|
+
*/
|
|
8735
9010
|
const throwIfError = (response) => {
|
|
9011
|
+
try {
|
|
9012
|
+
throwForStatus(response);
|
|
9013
|
+
}
|
|
9014
|
+
catch (error) {
|
|
9015
|
+
throw (0, responseReceived_1.markResponseReceived)(error, true);
|
|
9016
|
+
}
|
|
9017
|
+
};
|
|
9018
|
+
exports.throwIfError = throwIfError;
|
|
9019
|
+
const throwForStatus = (response) => {
|
|
8736
9020
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
8737
9021
|
switch (response.status) {
|
|
8738
9022
|
case 400:
|
|
@@ -8784,7 +9068,6 @@ const throwIfError = (response) => {
|
|
|
8784
9068
|
throw error;
|
|
8785
9069
|
}
|
|
8786
9070
|
};
|
|
8787
|
-
exports.throwIfError = throwIfError;
|
|
8788
9071
|
const parseError = (data) => {
|
|
8789
9072
|
if (!data)
|
|
8790
9073
|
return null;
|
|
@@ -9436,6 +9719,78 @@ const waitForMockReadiness = (ready, config) => __awaiter(void 0, void 0, void 0
|
|
|
9436
9719
|
exports.waitForMockReadiness = waitForMockReadiness;
|
|
9437
9720
|
|
|
9438
9721
|
|
|
9722
|
+
/***/ },
|
|
9723
|
+
|
|
9724
|
+
/***/ 5775
|
|
9725
|
+
(__unused_webpack_module, exports) {
|
|
9726
|
+
|
|
9727
|
+
"use strict";
|
|
9728
|
+
var __webpack_unused_export__;
|
|
9729
|
+
|
|
9730
|
+
/**
|
|
9731
|
+
* Whether a failed request came back with an HTTP response.
|
|
9732
|
+
*
|
|
9733
|
+
* The request client turns a response into an error of its own - a 401 becomes a
|
|
9734
|
+
* `LoginRequiredError` carrying the body, a 404 a `NotFoundError` - so the axios
|
|
9735
|
+
* error, and with it the `response` property, is gone by the time a caller sees
|
|
9736
|
+
* the failure. That is why this cannot be inferred at the call site from the
|
|
9737
|
+
* error's shape: `throwIfError` has already replaced the shape.
|
|
9738
|
+
*
|
|
9739
|
+
* So the boundary stamps what it knows (`markResponseReceived`) and callers ask
|
|
9740
|
+
* this module. The `response` property is still the fallback, for errors that
|
|
9741
|
+
* never passed through the request client - but the marker wins when both are
|
|
9742
|
+
* present, because the boundary saw the response itself rather than a rebuilt
|
|
9743
|
+
* error that may or may not carry it.
|
|
9744
|
+
*/
|
|
9745
|
+
__webpack_unused_export__ = ({ value: true });
|
|
9746
|
+
exports.responseWasReceived = exports.markResponseReceived = void 0;
|
|
9747
|
+
/** The property the request client leaves on an error it built. */
|
|
9748
|
+
const MARKER = 'responseReceived';
|
|
9749
|
+
/**
|
|
9750
|
+
* Records on an error whether the request it reports on came back with a
|
|
9751
|
+
* response. Returns the same error, so a throw site reads `throw mark(...)`.
|
|
9752
|
+
* Marks are kept but hidden: the error travels to the caller, where a new
|
|
9753
|
+
* enumerable field would show up in a log, a `JSON.stringify`, or a
|
|
9754
|
+
* deep-equality assertion against an unmarked copy - a difference nothing to do
|
|
9755
|
+
* with the request, reported as though it were.
|
|
9756
|
+
*
|
|
9757
|
+
* A frozen error cannot take the mark; it is returned unchanged and
|
|
9758
|
+
* `responseWasReceived` falls back to whatever `response` the error carries.
|
|
9759
|
+
*/
|
|
9760
|
+
const markResponseReceived = (error, received) => {
|
|
9761
|
+
if (!error || (typeof error !== 'object' && typeof error !== 'function'))
|
|
9762
|
+
return error;
|
|
9763
|
+
try {
|
|
9764
|
+
Object.defineProperty(error, MARKER, {
|
|
9765
|
+
value: received,
|
|
9766
|
+
enumerable: false,
|
|
9767
|
+
configurable: true,
|
|
9768
|
+
writable: true
|
|
9769
|
+
});
|
|
9770
|
+
}
|
|
9771
|
+
catch (_a) {
|
|
9772
|
+
// not extensible: leave it unmarked rather than fail the request twice
|
|
9773
|
+
}
|
|
9774
|
+
return error;
|
|
9775
|
+
};
|
|
9776
|
+
exports.markResponseReceived = markResponseReceived;
|
|
9777
|
+
/**
|
|
9778
|
+
* Whether the failure behind this error came with an HTTP response.
|
|
9779
|
+
*
|
|
9780
|
+
* `false` is what a transport failure looks like: a wrong URL, a closed port, a
|
|
9781
|
+
* VPN that is down, a certificate that does not verify. The message that
|
|
9782
|
+
* accompanies such a failure is the transport's own (`connect ETIMEDOUT
|
|
9783
|
+
* 192.0.2.1:443`), not something a server said.
|
|
9784
|
+
*/
|
|
9785
|
+
const responseWasReceived = (error) => {
|
|
9786
|
+
const marked = error === null || error === void 0 ? void 0 : error.responseReceived;
|
|
9787
|
+
if (typeof marked === 'boolean')
|
|
9788
|
+
return marked;
|
|
9789
|
+
return Boolean(error === null || error === void 0 ? void 0 : error.response);
|
|
9790
|
+
};
|
|
9791
|
+
exports.responseWasReceived = responseWasReceived;
|
|
9792
|
+
|
|
9793
|
+
|
|
9439
9794
|
/***/ },
|
|
9440
9795
|
|
|
9441
9796
|
/***/ 5777
|
package/package.json
CHANGED
|
@@ -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;
|