rest-client-sdk 7.0.3 → 7.1.1
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/README.md +3 -0
- package/dist/index.es.js +22 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/types/RestClientSdkInterface.d.ts +1 -0
- package/dist/types/client/AbstractClient.d.ts +1 -0
- package/package.json +1 -1
- package/src/RestClientSdkInterface.ts +1 -0
- package/src/TokenStorage.ts +1 -1
- package/src/client/AbstractClient.ts +33 -12
package/README.md
CHANGED
|
@@ -119,6 +119,9 @@ const config = {
|
|
|
119
119
|
authorizationType: 'Bearer', // default to "Bearer", but can be "Basic" or anything
|
|
120
120
|
useDefaultParameters: true,
|
|
121
121
|
unitOfWorkEnabled: true, // if key is missing, UnitOfWork will be disabled by default
|
|
122
|
+
onRefreshTokenFailure: () => {
|
|
123
|
+
// do something when the refresh token fails
|
|
124
|
+
},
|
|
122
125
|
}; // path and scheme are mandatory
|
|
123
126
|
|
|
124
127
|
const sdk = new RestClientSdk(tokenStorage, config, mapping);
|
package/dist/index.es.js
CHANGED
|
@@ -1299,6 +1299,10 @@ var AbstractClient = /*#__PURE__*/function () {
|
|
|
1299
1299
|
if (accessTokenExpiresIn !== null && accessTokenExpiresIn <= EXPIRE_LIMIT_SECONDS) {
|
|
1300
1300
|
return _classPrivateFieldGet(_this3, _tokenStorage).refreshToken().then(function (refreshedTokenObject) {
|
|
1301
1301
|
return refreshedTokenObject.access_token;
|
|
1302
|
+
})["catch"](function (e) {
|
|
1303
|
+
_this3._handleRefreshTokenFailure(e);
|
|
1304
|
+
|
|
1305
|
+
throw e;
|
|
1302
1306
|
});
|
|
1303
1307
|
}
|
|
1304
1308
|
|
|
@@ -1326,6 +1330,10 @@ var AbstractClient = /*#__PURE__*/function () {
|
|
|
1326
1330
|
});
|
|
1327
1331
|
|
|
1328
1332
|
return _this4._fetchWithToken(input, updatedRequestParams);
|
|
1333
|
+
})["catch"](function (e) {
|
|
1334
|
+
_this4._handleRefreshTokenFailure(e);
|
|
1335
|
+
|
|
1336
|
+
throw e;
|
|
1329
1337
|
});
|
|
1330
1338
|
}
|
|
1331
1339
|
}, {
|
|
@@ -1431,6 +1439,19 @@ var AbstractClient = /*#__PURE__*/function () {
|
|
|
1431
1439
|
|
|
1432
1440
|
return object[idKey];
|
|
1433
1441
|
}
|
|
1442
|
+
}, {
|
|
1443
|
+
key: "_handleRefreshTokenFailure",
|
|
1444
|
+
value: function _handleRefreshTokenFailure(error) {
|
|
1445
|
+
var _this7 = this;
|
|
1446
|
+
|
|
1447
|
+
if (error instanceof OauthError) {
|
|
1448
|
+
_classPrivateFieldGet(this, _tokenStorage).logout().then(function () {
|
|
1449
|
+
if (_this7.sdk.config.onRefreshTokenFailure) {
|
|
1450
|
+
_this7.sdk.config.onRefreshTokenFailure(error);
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1434
1455
|
}]);
|
|
1435
1456
|
|
|
1436
1457
|
return AbstractClient;
|
|
@@ -2945,7 +2966,7 @@ var TokenStorage = /*#__PURE__*/function () {
|
|
|
2945
2966
|
return response.json().then(function (body) {
|
|
2946
2967
|
if (isOauthError(body)) {
|
|
2947
2968
|
// throw error if response body is an oauth error
|
|
2948
|
-
manageOauthError(body,
|
|
2969
|
+
manageOauthError(body, originalResponse);
|
|
2949
2970
|
} else if (response.status >= 400) {
|
|
2950
2971
|
// throw an error if response status code is an "error" status code
|
|
2951
2972
|
throw getHttpErrorFromResponse(originalResponse);
|