@sasjs/adapter 6.1.2 → 6.1.4
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/dist/minified_sas9.js +82 -10
- package/dist/sasjs-adapter.js +81 -9
- package/package.json +1 -1
- package/request/RequestClient.js +22 -5
- package/types/errors/RefreshTokenRejectedError.d.ts +26 -0
- package/types/errors/RefreshTokenRejectedError.js +46 -0
- package/types/errors/index.d.ts +1 -0
- package/types/errors/index.js +1 -0
package/dist/minified_sas9.js
CHANGED
|
@@ -2252,7 +2252,7 @@ exports.WebJobExecutor = void 0;
|
|
|
2252
2252
|
const errors_1 = __webpack_require__(7388);
|
|
2253
2253
|
const utils_1 = __webpack_require__(9266);
|
|
2254
2254
|
const JobExecutor_1 = __webpack_require__(1101);
|
|
2255
|
-
const parseWeboutResponse_1 = __webpack_require__(
|
|
2255
|
+
const parseWeboutResponse_1 = __webpack_require__(5259);
|
|
2256
2256
|
class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
|
|
2257
2257
|
constructor(serverUrl, serverType, jobsPath, requestClient) {
|
|
2258
2258
|
super(serverUrl, serverType);
|
|
@@ -2394,7 +2394,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
2394
2394
|
exports.throwIfError = exports.RequestClient = void 0;
|
|
2395
2395
|
const auth_1 = __webpack_require__(4879);
|
|
2396
2396
|
const errors_1 = __webpack_require__(7388);
|
|
2397
|
-
const parseWeboutResponse_1 = __webpack_require__(
|
|
2397
|
+
const parseWeboutResponse_1 = __webpack_require__(5259);
|
|
2398
2398
|
const error_1 = __webpack_require__(6340);
|
|
2399
2399
|
const SAS9AuthError_1 = __webpack_require__(2079);
|
|
2400
2400
|
const utils_1 = __webpack_require__(9266);
|
|
@@ -3000,8 +3000,19 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
3000
3000
|
}
|
|
3001
3001
|
}
|
|
3002
3002
|
exports.RequestClient = RequestClient;
|
|
3003
|
+
/**
|
|
3004
|
+
* Whether a url is a refresh-token endpoint, whichever server it belongs to.
|
|
3005
|
+
*
|
|
3006
|
+
* Matched on the path rather than on the server type because this runs where
|
|
3007
|
+
* the response is turned into an error, before any caller knows which client
|
|
3008
|
+
* made the request. `/auth/refresh` is SASjs Server's route; Viya's refresh
|
|
3009
|
+
* goes through `/SASLogon/oauth/token`, where a 401 means the client
|
|
3010
|
+
* credentials were refused rather than the refresh token, so it is not
|
|
3011
|
+
* included here.
|
|
3012
|
+
*/
|
|
3013
|
+
const isTokenRefreshUrl = (url) => !!url && /(^|\/)auth\/refresh(\?|$)/.test(url);
|
|
3003
3014
|
const throwIfError = (response) => {
|
|
3004
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3015
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3005
3016
|
switch (response.status) {
|
|
3006
3017
|
case 400:
|
|
3007
3018
|
if (typeof response.data === 'object' &&
|
|
@@ -3015,6 +3026,12 @@ const throwIfError = (response) => {
|
|
|
3015
3026
|
}
|
|
3016
3027
|
break;
|
|
3017
3028
|
case 401:
|
|
3029
|
+
// A 401 on the refresh route is the server refusing the credential that
|
|
3030
|
+
// was presented - the refresh token - not the caller failing to log in.
|
|
3031
|
+
// See RefreshTokenRejectedError for why the distinction matters.
|
|
3032
|
+
if (isTokenRefreshUrl((_a = response.config) === null || _a === void 0 ? void 0 : _a.url)) {
|
|
3033
|
+
throw new errors_1.RefreshTokenRejectedError(response.data);
|
|
3034
|
+
}
|
|
3018
3035
|
if (typeof response.data === 'object') {
|
|
3019
3036
|
throw new errors_1.LoginRequiredError(response.data);
|
|
3020
3037
|
}
|
|
@@ -3022,7 +3039,7 @@ const throwIfError = (response) => {
|
|
|
3022
3039
|
throw new errors_1.LoginRequiredError();
|
|
3023
3040
|
}
|
|
3024
3041
|
}
|
|
3025
|
-
if ((
|
|
3042
|
+
if ((_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.entityID) === null || _c === void 0 ? void 0 : _c.includes('login')) {
|
|
3026
3043
|
throw new errors_1.LoginRequiredError();
|
|
3027
3044
|
}
|
|
3028
3045
|
if (typeof response.data === 'string' &&
|
|
@@ -3031,14 +3048,14 @@ const throwIfError = (response) => {
|
|
|
3031
3048
|
}
|
|
3032
3049
|
if (typeof response.data === 'string' &&
|
|
3033
3050
|
(0, auth_1.isLogInRequired)(response.data) &&
|
|
3034
|
-
!((
|
|
3051
|
+
!((_e = (_d = response.config) === null || _d === void 0 ? void 0 : _d.url) === null || _e === void 0 ? void 0 : _e.includes('/SASLogon/login'))) {
|
|
3035
3052
|
throw new errors_1.LoginRequiredError();
|
|
3036
3053
|
}
|
|
3037
|
-
if ((
|
|
3054
|
+
if ((_f = response.data) === null || _f === void 0 ? void 0 : _f.auth_request) {
|
|
3038
3055
|
const authorizeRequestUrl = response.request.responseURL;
|
|
3039
3056
|
throw new errors_1.AuthorizeError(response.data.message, authorizeRequestUrl);
|
|
3040
3057
|
}
|
|
3041
|
-
if ((
|
|
3058
|
+
if ((_h = (_g = response.config) === null || _g === void 0 ? void 0 : _g.url) === null || _h === void 0 ? void 0 : _h.includes('sasAuthError')) {
|
|
3042
3059
|
throw new SAS9AuthError_1.SAS9AuthError();
|
|
3043
3060
|
}
|
|
3044
3061
|
const error = parseError(response.data);
|
|
@@ -4036,6 +4053,60 @@ class NotFoundError extends Error {
|
|
|
4036
4053
|
exports.NotFoundError = NotFoundError;
|
|
4037
4054
|
|
|
4038
4055
|
|
|
4056
|
+
/***/ },
|
|
4057
|
+
|
|
4058
|
+
/***/ 7640
|
|
4059
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
4060
|
+
|
|
4061
|
+
"use strict";
|
|
4062
|
+
|
|
4063
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4064
|
+
exports.RefreshTokenRejectedError = void 0;
|
|
4065
|
+
const LoginRequiredError_1 = __webpack_require__(3104);
|
|
4066
|
+
/**
|
|
4067
|
+
* The server rejected a refresh token.
|
|
4068
|
+
*
|
|
4069
|
+
* A 401 from the token endpoint is not the same answer as a 401 from a data
|
|
4070
|
+
* endpoint. The caller did present a credential - its refresh token - and the
|
|
4071
|
+
* server refused it, which means the pair on disk is dead and no amount of
|
|
4072
|
+
* retrying will revive it. Rendering that as "You must be logged in to access
|
|
4073
|
+
* this resource" points the reader at their login state when the thing to look
|
|
4074
|
+
* at is the stored refresh token.
|
|
4075
|
+
*
|
|
4076
|
+
* Both SASjs Server and SAS Viya issue single-use refresh tokens and compare
|
|
4077
|
+
* the presented token with the pair they currently hold, so a token that
|
|
4078
|
+
* another session has rotated - a browser tab, a second CLI run, a service
|
|
4079
|
+
* account - is refused even though its signature and expiry are still valid.
|
|
4080
|
+
* Re-use of a superseded token and expiry therefore produce the same answer,
|
|
4081
|
+
* and the message says both.
|
|
4082
|
+
*
|
|
4083
|
+
* Deliberately a subclass of {@link LoginRequiredError}: every caller that
|
|
4084
|
+
* treats a 401 as "obtain a new session" (the CLI among them) keeps working,
|
|
4085
|
+
* and only the explanation changes. `instanceof LoginRequiredError` remains a
|
|
4086
|
+
* valid check.
|
|
4087
|
+
*/
|
|
4088
|
+
class RefreshTokenRejectedError extends LoginRequiredError_1.LoginRequiredError {
|
|
4089
|
+
constructor(details) {
|
|
4090
|
+
super(details);
|
|
4091
|
+
// LoginRequiredError's constructor pins the prototype to its own class (the
|
|
4092
|
+
// ES5 subclassing fix). Re-pin it here or `instanceof
|
|
4093
|
+
// RefreshTokenRejectedError` is false on the error that was just thrown.
|
|
4094
|
+
Object.setPrototypeOf(this, RefreshTokenRejectedError.prototype);
|
|
4095
|
+
this.name = 'RefreshTokenRejectedError';
|
|
4096
|
+
const response = details === undefined || details === null
|
|
4097
|
+
? ''
|
|
4098
|
+
: `\nServer response: ${typeof details === 'string' ? details : JSON.stringify(details)}`;
|
|
4099
|
+
this.message =
|
|
4100
|
+
'Auth error: the server rejected the refresh token - it has expired, or it ' +
|
|
4101
|
+
'has already been replaced by a newer pair. Refresh tokens are single use, ' +
|
|
4102
|
+
'so a pair that another session, browser tab or CLI run has already ' +
|
|
4103
|
+
'refreshed can no longer be used. Authenticate again to obtain a new pair.' +
|
|
4104
|
+
response;
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
exports.RefreshTokenRejectedError = RefreshTokenRejectedError;
|
|
4108
|
+
|
|
4109
|
+
|
|
4039
4110
|
/***/ },
|
|
4040
4111
|
|
|
4041
4112
|
/***/ 5395
|
|
@@ -4174,6 +4245,7 @@ __exportStar(__webpack_require__(3104), exports);
|
|
|
4174
4245
|
__exportStar(__webpack_require__(314), exports);
|
|
4175
4246
|
__exportStar(__webpack_require__(1976), exports);
|
|
4176
4247
|
__exportStar(__webpack_require__(7403), exports);
|
|
4248
|
+
__exportStar(__webpack_require__(7640), exports);
|
|
4177
4249
|
__exportStar(__webpack_require__(5395), exports);
|
|
4178
4250
|
__exportStar(__webpack_require__(996), exports);
|
|
4179
4251
|
__exportStar(__webpack_require__(9997), exports);
|
|
@@ -4501,7 +4573,7 @@ exports.delay = delay;
|
|
|
4501
4573
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4502
4574
|
exports.extractWeboutBlob = exports.hasWeboutBlob = void 0;
|
|
4503
4575
|
const getValidJson_1 = __webpack_require__(5880);
|
|
4504
|
-
const parseWeboutResponse_1 = __webpack_require__(
|
|
4576
|
+
const parseWeboutResponse_1 = __webpack_require__(5259);
|
|
4505
4577
|
// Matches the script-constructed Blob that the JES web app uses to inline the
|
|
4506
4578
|
// webout: `new Blob([`{...}`], {type: 'application/json'})`. The type is
|
|
4507
4579
|
// text/plain on abort and error paths, where the JSON is wrapped in
|
|
@@ -4755,7 +4827,7 @@ __exportStar(__webpack_require__(8325), exports);
|
|
|
4755
4827
|
__exportStar(__webpack_require__(3617), exports);
|
|
4756
4828
|
__exportStar(__webpack_require__(7288), exports);
|
|
4757
4829
|
__exportStar(__webpack_require__(6024), exports);
|
|
4758
|
-
__exportStar(__webpack_require__(
|
|
4830
|
+
__exportStar(__webpack_require__(5259), exports);
|
|
4759
4831
|
__exportStar(__webpack_require__(8424), exports);
|
|
4760
4832
|
__exportStar(__webpack_require__(8720), exports);
|
|
4761
4833
|
__exportStar(__webpack_require__(8128), exports);
|
|
@@ -5203,7 +5275,7 @@ exports.parseSasViyaLogDebugResponse = parseSasViyaLogDebugResponse;
|
|
|
5203
5275
|
|
|
5204
5276
|
/***/ },
|
|
5205
5277
|
|
|
5206
|
-
/***/
|
|
5278
|
+
/***/ 5259
|
|
5207
5279
|
(__unused_webpack_module, exports, __webpack_require__) {
|
|
5208
5280
|
|
|
5209
5281
|
"use strict";
|
package/dist/sasjs-adapter.js
CHANGED
|
@@ -8115,7 +8115,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
8115
8115
|
exports.throwIfError = exports.RequestClient = void 0;
|
|
8116
8116
|
const auth_1 = __webpack_require__(4879);
|
|
8117
8117
|
const errors_1 = __webpack_require__(7388);
|
|
8118
|
-
const parseWeboutResponse_1 = __webpack_require__(
|
|
8118
|
+
const parseWeboutResponse_1 = __webpack_require__(5259);
|
|
8119
8119
|
const error_1 = __webpack_require__(6340);
|
|
8120
8120
|
const SAS9AuthError_1 = __webpack_require__(2079);
|
|
8121
8121
|
const utils_1 = __webpack_require__(9266);
|
|
@@ -8721,8 +8721,19 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
8721
8721
|
}
|
|
8722
8722
|
}
|
|
8723
8723
|
exports.RequestClient = RequestClient;
|
|
8724
|
+
/**
|
|
8725
|
+
* Whether a url is a refresh-token endpoint, whichever server it belongs to.
|
|
8726
|
+
*
|
|
8727
|
+
* Matched on the path rather than on the server type because this runs where
|
|
8728
|
+
* the response is turned into an error, before any caller knows which client
|
|
8729
|
+
* made the request. `/auth/refresh` is SASjs Server's route; Viya's refresh
|
|
8730
|
+
* goes through `/SASLogon/oauth/token`, where a 401 means the client
|
|
8731
|
+
* credentials were refused rather than the refresh token, so it is not
|
|
8732
|
+
* included here.
|
|
8733
|
+
*/
|
|
8734
|
+
const isTokenRefreshUrl = (url) => !!url && /(^|\/)auth\/refresh(\?|$)/.test(url);
|
|
8724
8735
|
const throwIfError = (response) => {
|
|
8725
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
8736
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
8726
8737
|
switch (response.status) {
|
|
8727
8738
|
case 400:
|
|
8728
8739
|
if (typeof response.data === 'object' &&
|
|
@@ -8736,6 +8747,12 @@ const throwIfError = (response) => {
|
|
|
8736
8747
|
}
|
|
8737
8748
|
break;
|
|
8738
8749
|
case 401:
|
|
8750
|
+
// A 401 on the refresh route is the server refusing the credential that
|
|
8751
|
+
// was presented - the refresh token - not the caller failing to log in.
|
|
8752
|
+
// See RefreshTokenRejectedError for why the distinction matters.
|
|
8753
|
+
if (isTokenRefreshUrl((_a = response.config) === null || _a === void 0 ? void 0 : _a.url)) {
|
|
8754
|
+
throw new errors_1.RefreshTokenRejectedError(response.data);
|
|
8755
|
+
}
|
|
8739
8756
|
if (typeof response.data === 'object') {
|
|
8740
8757
|
throw new errors_1.LoginRequiredError(response.data);
|
|
8741
8758
|
}
|
|
@@ -8743,7 +8760,7 @@ const throwIfError = (response) => {
|
|
|
8743
8760
|
throw new errors_1.LoginRequiredError();
|
|
8744
8761
|
}
|
|
8745
8762
|
}
|
|
8746
|
-
if ((
|
|
8763
|
+
if ((_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.entityID) === null || _c === void 0 ? void 0 : _c.includes('login')) {
|
|
8747
8764
|
throw new errors_1.LoginRequiredError();
|
|
8748
8765
|
}
|
|
8749
8766
|
if (typeof response.data === 'string' &&
|
|
@@ -8752,14 +8769,14 @@ const throwIfError = (response) => {
|
|
|
8752
8769
|
}
|
|
8753
8770
|
if (typeof response.data === 'string' &&
|
|
8754
8771
|
(0, auth_1.isLogInRequired)(response.data) &&
|
|
8755
|
-
!((
|
|
8772
|
+
!((_e = (_d = response.config) === null || _d === void 0 ? void 0 : _d.url) === null || _e === void 0 ? void 0 : _e.includes('/SASLogon/login'))) {
|
|
8756
8773
|
throw new errors_1.LoginRequiredError();
|
|
8757
8774
|
}
|
|
8758
|
-
if ((
|
|
8775
|
+
if ((_f = response.data) === null || _f === void 0 ? void 0 : _f.auth_request) {
|
|
8759
8776
|
const authorizeRequestUrl = response.request.responseURL;
|
|
8760
8777
|
throw new errors_1.AuthorizeError(response.data.message, authorizeRequestUrl);
|
|
8761
8778
|
}
|
|
8762
|
-
if ((
|
|
8779
|
+
if ((_h = (_g = response.config) === null || _g === void 0 ? void 0 : _g.url) === null || _h === void 0 ? void 0 : _h.includes('sasAuthError')) {
|
|
8763
8780
|
throw new SAS9AuthError_1.SAS9AuthError();
|
|
8764
8781
|
}
|
|
8765
8782
|
const error = parseError(response.data);
|
|
@@ -10039,6 +10056,60 @@ class NotFoundError extends Error {
|
|
|
10039
10056
|
exports.NotFoundError = NotFoundError;
|
|
10040
10057
|
|
|
10041
10058
|
|
|
10059
|
+
/***/ },
|
|
10060
|
+
|
|
10061
|
+
/***/ 7640
|
|
10062
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
10063
|
+
|
|
10064
|
+
"use strict";
|
|
10065
|
+
|
|
10066
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
10067
|
+
exports.RefreshTokenRejectedError = void 0;
|
|
10068
|
+
const LoginRequiredError_1 = __webpack_require__(3104);
|
|
10069
|
+
/**
|
|
10070
|
+
* The server rejected a refresh token.
|
|
10071
|
+
*
|
|
10072
|
+
* A 401 from the token endpoint is not the same answer as a 401 from a data
|
|
10073
|
+
* endpoint. The caller did present a credential - its refresh token - and the
|
|
10074
|
+
* server refused it, which means the pair on disk is dead and no amount of
|
|
10075
|
+
* retrying will revive it. Rendering that as "You must be logged in to access
|
|
10076
|
+
* this resource" points the reader at their login state when the thing to look
|
|
10077
|
+
* at is the stored refresh token.
|
|
10078
|
+
*
|
|
10079
|
+
* Both SASjs Server and SAS Viya issue single-use refresh tokens and compare
|
|
10080
|
+
* the presented token with the pair they currently hold, so a token that
|
|
10081
|
+
* another session has rotated - a browser tab, a second CLI run, a service
|
|
10082
|
+
* account - is refused even though its signature and expiry are still valid.
|
|
10083
|
+
* Re-use of a superseded token and expiry therefore produce the same answer,
|
|
10084
|
+
* and the message says both.
|
|
10085
|
+
*
|
|
10086
|
+
* Deliberately a subclass of {@link LoginRequiredError}: every caller that
|
|
10087
|
+
* treats a 401 as "obtain a new session" (the CLI among them) keeps working,
|
|
10088
|
+
* and only the explanation changes. `instanceof LoginRequiredError` remains a
|
|
10089
|
+
* valid check.
|
|
10090
|
+
*/
|
|
10091
|
+
class RefreshTokenRejectedError extends LoginRequiredError_1.LoginRequiredError {
|
|
10092
|
+
constructor(details) {
|
|
10093
|
+
super(details);
|
|
10094
|
+
// LoginRequiredError's constructor pins the prototype to its own class (the
|
|
10095
|
+
// ES5 subclassing fix). Re-pin it here or `instanceof
|
|
10096
|
+
// RefreshTokenRejectedError` is false on the error that was just thrown.
|
|
10097
|
+
Object.setPrototypeOf(this, RefreshTokenRejectedError.prototype);
|
|
10098
|
+
this.name = 'RefreshTokenRejectedError';
|
|
10099
|
+
const response = details === undefined || details === null
|
|
10100
|
+
? ''
|
|
10101
|
+
: `\nServer response: ${typeof details === 'string' ? details : JSON.stringify(details)}`;
|
|
10102
|
+
this.message =
|
|
10103
|
+
'Auth error: the server rejected the refresh token - it has expired, or it ' +
|
|
10104
|
+
'has already been replaced by a newer pair. Refresh tokens are single use, ' +
|
|
10105
|
+
'so a pair that another session, browser tab or CLI run has already ' +
|
|
10106
|
+
'refreshed can no longer be used. Authenticate again to obtain a new pair.' +
|
|
10107
|
+
response;
|
|
10108
|
+
}
|
|
10109
|
+
}
|
|
10110
|
+
exports.RefreshTokenRejectedError = RefreshTokenRejectedError;
|
|
10111
|
+
|
|
10112
|
+
|
|
10042
10113
|
/***/ },
|
|
10043
10114
|
|
|
10044
10115
|
/***/ 5395
|
|
@@ -10177,6 +10248,7 @@ __exportStar(__webpack_require__(3104), exports);
|
|
|
10177
10248
|
__exportStar(__webpack_require__(314), exports);
|
|
10178
10249
|
__exportStar(__webpack_require__(1976), exports);
|
|
10179
10250
|
__exportStar(__webpack_require__(7403), exports);
|
|
10251
|
+
__exportStar(__webpack_require__(7640), exports);
|
|
10180
10252
|
__exportStar(__webpack_require__(5395), exports);
|
|
10181
10253
|
__exportStar(__webpack_require__(996), exports);
|
|
10182
10254
|
__exportStar(__webpack_require__(9997), exports);
|
|
@@ -10504,7 +10576,7 @@ exports.delay = delay;
|
|
|
10504
10576
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
10505
10577
|
exports.extractWeboutBlob = exports.hasWeboutBlob = void 0;
|
|
10506
10578
|
const getValidJson_1 = __webpack_require__(5880);
|
|
10507
|
-
const parseWeboutResponse_1 = __webpack_require__(
|
|
10579
|
+
const parseWeboutResponse_1 = __webpack_require__(5259);
|
|
10508
10580
|
// Matches the script-constructed Blob that the JES web app uses to inline the
|
|
10509
10581
|
// webout: `new Blob([`{...}`], {type: 'application/json'})`. The type is
|
|
10510
10582
|
// text/plain on abort and error paths, where the JSON is wrapped in
|
|
@@ -10806,7 +10878,7 @@ __exportStar(__webpack_require__(8325), exports);
|
|
|
10806
10878
|
__exportStar(__webpack_require__(3617), exports);
|
|
10807
10879
|
__exportStar(__webpack_require__(7288), exports);
|
|
10808
10880
|
__exportStar(__webpack_require__(6024), exports);
|
|
10809
|
-
__exportStar(__webpack_require__(
|
|
10881
|
+
__exportStar(__webpack_require__(5259), exports);
|
|
10810
10882
|
__exportStar(__webpack_require__(8424), exports);
|
|
10811
10883
|
__exportStar(__webpack_require__(8720), exports);
|
|
10812
10884
|
__exportStar(__webpack_require__(8128), exports);
|
|
@@ -11300,7 +11372,7 @@ exports.parseSasViyaLogDebugResponse = parseSasViyaLogDebugResponse;
|
|
|
11300
11372
|
|
|
11301
11373
|
/***/ },
|
|
11302
11374
|
|
|
11303
|
-
/***/
|
|
11375
|
+
/***/ 5259
|
|
11304
11376
|
(__unused_webpack_module, exports, __webpack_require__) {
|
|
11305
11377
|
|
|
11306
11378
|
"use strict";
|
package/package.json
CHANGED
package/request/RequestClient.js
CHANGED
|
@@ -618,8 +618,19 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
618
618
|
}
|
|
619
619
|
}
|
|
620
620
|
exports.RequestClient = RequestClient;
|
|
621
|
+
/**
|
|
622
|
+
* Whether a url is a refresh-token endpoint, whichever server it belongs to.
|
|
623
|
+
*
|
|
624
|
+
* Matched on the path rather than on the server type because this runs where
|
|
625
|
+
* the response is turned into an error, before any caller knows which client
|
|
626
|
+
* made the request. `/auth/refresh` is SASjs Server's route; Viya's refresh
|
|
627
|
+
* goes through `/SASLogon/oauth/token`, where a 401 means the client
|
|
628
|
+
* credentials were refused rather than the refresh token, so it is not
|
|
629
|
+
* included here.
|
|
630
|
+
*/
|
|
631
|
+
const isTokenRefreshUrl = (url) => !!url && /(^|\/)auth\/refresh(\?|$)/.test(url);
|
|
621
632
|
const throwIfError = (response) => {
|
|
622
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
633
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
623
634
|
switch (response.status) {
|
|
624
635
|
case 400:
|
|
625
636
|
if (typeof response.data === 'object' &&
|
|
@@ -633,6 +644,12 @@ const throwIfError = (response) => {
|
|
|
633
644
|
}
|
|
634
645
|
break;
|
|
635
646
|
case 401:
|
|
647
|
+
// A 401 on the refresh route is the server refusing the credential that
|
|
648
|
+
// was presented - the refresh token - not the caller failing to log in.
|
|
649
|
+
// See RefreshTokenRejectedError for why the distinction matters.
|
|
650
|
+
if (isTokenRefreshUrl((_a = response.config) === null || _a === void 0 ? void 0 : _a.url)) {
|
|
651
|
+
throw new errors_1.RefreshTokenRejectedError(response.data);
|
|
652
|
+
}
|
|
636
653
|
if (typeof response.data === 'object') {
|
|
637
654
|
throw new errors_1.LoginRequiredError(response.data);
|
|
638
655
|
}
|
|
@@ -640,7 +657,7 @@ const throwIfError = (response) => {
|
|
|
640
657
|
throw new errors_1.LoginRequiredError();
|
|
641
658
|
}
|
|
642
659
|
}
|
|
643
|
-
if ((
|
|
660
|
+
if ((_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.entityID) === null || _c === void 0 ? void 0 : _c.includes('login')) {
|
|
644
661
|
throw new errors_1.LoginRequiredError();
|
|
645
662
|
}
|
|
646
663
|
if (typeof response.data === 'string' &&
|
|
@@ -649,14 +666,14 @@ const throwIfError = (response) => {
|
|
|
649
666
|
}
|
|
650
667
|
if (typeof response.data === 'string' &&
|
|
651
668
|
(0, auth_1.isLogInRequired)(response.data) &&
|
|
652
|
-
!((
|
|
669
|
+
!((_e = (_d = response.config) === null || _d === void 0 ? void 0 : _d.url) === null || _e === void 0 ? void 0 : _e.includes('/SASLogon/login'))) {
|
|
653
670
|
throw new errors_1.LoginRequiredError();
|
|
654
671
|
}
|
|
655
|
-
if ((
|
|
672
|
+
if ((_f = response.data) === null || _f === void 0 ? void 0 : _f.auth_request) {
|
|
656
673
|
const authorizeRequestUrl = response.request.responseURL;
|
|
657
674
|
throw new errors_1.AuthorizeError(response.data.message, authorizeRequestUrl);
|
|
658
675
|
}
|
|
659
|
-
if ((
|
|
676
|
+
if ((_h = (_g = response.config) === null || _g === void 0 ? void 0 : _g.url) === null || _h === void 0 ? void 0 : _h.includes('sasAuthError')) {
|
|
660
677
|
throw new SAS9AuthError_1.SAS9AuthError();
|
|
661
678
|
}
|
|
662
679
|
const error = parseError(response.data);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LoginRequiredError } from './LoginRequiredError';
|
|
2
|
+
/**
|
|
3
|
+
* The server rejected a refresh token.
|
|
4
|
+
*
|
|
5
|
+
* A 401 from the token endpoint is not the same answer as a 401 from a data
|
|
6
|
+
* endpoint. The caller did present a credential - its refresh token - and the
|
|
7
|
+
* server refused it, which means the pair on disk is dead and no amount of
|
|
8
|
+
* retrying will revive it. Rendering that as "You must be logged in to access
|
|
9
|
+
* this resource" points the reader at their login state when the thing to look
|
|
10
|
+
* at is the stored refresh token.
|
|
11
|
+
*
|
|
12
|
+
* Both SASjs Server and SAS Viya issue single-use refresh tokens and compare
|
|
13
|
+
* the presented token with the pair they currently hold, so a token that
|
|
14
|
+
* another session has rotated - a browser tab, a second CLI run, a service
|
|
15
|
+
* account - is refused even though its signature and expiry are still valid.
|
|
16
|
+
* Re-use of a superseded token and expiry therefore produce the same answer,
|
|
17
|
+
* and the message says both.
|
|
18
|
+
*
|
|
19
|
+
* Deliberately a subclass of {@link LoginRequiredError}: every caller that
|
|
20
|
+
* treats a 401 as "obtain a new session" (the CLI among them) keeps working,
|
|
21
|
+
* and only the explanation changes. `instanceof LoginRequiredError` remains a
|
|
22
|
+
* valid check.
|
|
23
|
+
*/
|
|
24
|
+
export declare class RefreshTokenRejectedError extends LoginRequiredError {
|
|
25
|
+
constructor(details?: any);
|
|
26
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RefreshTokenRejectedError = void 0;
|
|
4
|
+
const LoginRequiredError_1 = require("./LoginRequiredError");
|
|
5
|
+
/**
|
|
6
|
+
* The server rejected a refresh token.
|
|
7
|
+
*
|
|
8
|
+
* A 401 from the token endpoint is not the same answer as a 401 from a data
|
|
9
|
+
* endpoint. The caller did present a credential - its refresh token - and the
|
|
10
|
+
* server refused it, which means the pair on disk is dead and no amount of
|
|
11
|
+
* retrying will revive it. Rendering that as "You must be logged in to access
|
|
12
|
+
* this resource" points the reader at their login state when the thing to look
|
|
13
|
+
* at is the stored refresh token.
|
|
14
|
+
*
|
|
15
|
+
* Both SASjs Server and SAS Viya issue single-use refresh tokens and compare
|
|
16
|
+
* the presented token with the pair they currently hold, so a token that
|
|
17
|
+
* another session has rotated - a browser tab, a second CLI run, a service
|
|
18
|
+
* account - is refused even though its signature and expiry are still valid.
|
|
19
|
+
* Re-use of a superseded token and expiry therefore produce the same answer,
|
|
20
|
+
* and the message says both.
|
|
21
|
+
*
|
|
22
|
+
* Deliberately a subclass of {@link LoginRequiredError}: every caller that
|
|
23
|
+
* treats a 401 as "obtain a new session" (the CLI among them) keeps working,
|
|
24
|
+
* and only the explanation changes. `instanceof LoginRequiredError` remains a
|
|
25
|
+
* valid check.
|
|
26
|
+
*/
|
|
27
|
+
class RefreshTokenRejectedError extends LoginRequiredError_1.LoginRequiredError {
|
|
28
|
+
constructor(details) {
|
|
29
|
+
super(details);
|
|
30
|
+
// LoginRequiredError's constructor pins the prototype to its own class (the
|
|
31
|
+
// ES5 subclassing fix). Re-pin it here or `instanceof
|
|
32
|
+
// RefreshTokenRejectedError` is false on the error that was just thrown.
|
|
33
|
+
Object.setPrototypeOf(this, RefreshTokenRejectedError.prototype);
|
|
34
|
+
this.name = 'RefreshTokenRejectedError';
|
|
35
|
+
const response = details === undefined || details === null
|
|
36
|
+
? ''
|
|
37
|
+
: `\nServer response: ${typeof details === 'string' ? details : JSON.stringify(details)}`;
|
|
38
|
+
this.message =
|
|
39
|
+
'Auth error: the server rejected the refresh token - it has expired, or it ' +
|
|
40
|
+
'has already been replaced by a newer pair. Refresh tokens are single use, ' +
|
|
41
|
+
'so a pair that another session, browser tab or CLI run has already ' +
|
|
42
|
+
'refreshed can no longer be used. Authenticate again to obtain a new pair.' +
|
|
43
|
+
response;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.RefreshTokenRejectedError = RefreshTokenRejectedError;
|
package/types/errors/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './LoginRequiredError';
|
|
|
12
12
|
export * from './MockReadinessError';
|
|
13
13
|
export * from './NoSessionStateError';
|
|
14
14
|
export * from './NotFoundError';
|
|
15
|
+
export * from './RefreshTokenRejectedError';
|
|
15
16
|
export * from './RootFolderNotFoundError';
|
|
16
17
|
export * from './UnsafeRedirectError';
|
|
17
18
|
export * from './WeboutResponseError';
|
package/types/errors/index.js
CHANGED
|
@@ -28,6 +28,7 @@ __exportStar(require("./LoginRequiredError"), exports);
|
|
|
28
28
|
__exportStar(require("./MockReadinessError"), exports);
|
|
29
29
|
__exportStar(require("./NoSessionStateError"), exports);
|
|
30
30
|
__exportStar(require("./NotFoundError"), exports);
|
|
31
|
+
__exportStar(require("./RefreshTokenRejectedError"), exports);
|
|
31
32
|
__exportStar(require("./RootFolderNotFoundError"), exports);
|
|
32
33
|
__exportStar(require("./UnsafeRedirectError"), exports);
|
|
33
34
|
__exportStar(require("./WeboutResponseError"), exports);
|