@dexteel/mesf-core 3.11.1 → 3.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/index.esm.js +125 -150
- package/dist/services/ApiService.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -17,7 +17,6 @@ import MenuItem from '@material-ui/core/MenuItem';
|
|
|
17
17
|
import MenuList from '@material-ui/core/MenuList';
|
|
18
18
|
import Paper from '@material-ui/core/Paper';
|
|
19
19
|
import Grid from '@material-ui/core/Grid';
|
|
20
|
-
import axios from 'axios';
|
|
21
20
|
import PersonPinCircleIcon from '@material-ui/icons/PersonPinCircle';
|
|
22
21
|
import moment from 'moment';
|
|
23
22
|
import { withStyles, alpha, makeStyles, createStyles, useTheme } from '@material-ui/core/styles';
|
|
@@ -59,6 +58,7 @@ import TreeItem from '@material-ui/lab/TreeItem';
|
|
|
59
58
|
import TreeView from '@material-ui/lab/TreeView';
|
|
60
59
|
import { useSpring, animated } from 'react-spring';
|
|
61
60
|
import CardActions from '@material-ui/core/CardActions';
|
|
61
|
+
import axios from 'axios';
|
|
62
62
|
|
|
63
63
|
/******************************************************************************
|
|
64
64
|
Copyright (c) Microsoft Corporation.
|
|
@@ -4708,6 +4708,107 @@ var Configuration$1 = /** @class */ (function () {
|
|
|
4708
4708
|
}());
|
|
4709
4709
|
|
|
4710
4710
|
var base$2 = document.getElementsByTagName('base')[0].getAttribute('href') || '/';
|
|
4711
|
+
function renewToken() {
|
|
4712
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4713
|
+
var refreshToken, config, fd, response, token;
|
|
4714
|
+
return __generator(this, function (_a) {
|
|
4715
|
+
switch (_a.label) {
|
|
4716
|
+
case 0:
|
|
4717
|
+
refreshToken = localStorage.getItem("refreshToken");
|
|
4718
|
+
if (!refreshToken) {
|
|
4719
|
+
throw new Error('refresh token does not exist');
|
|
4720
|
+
}
|
|
4721
|
+
config = new Configuration$1();
|
|
4722
|
+
fd = new FormData();
|
|
4723
|
+
fd.append('refreshToken', refreshToken);
|
|
4724
|
+
return [4 /*yield*/, axios.post("".concat(config.API_AUTH_URL, "/refresh"), fd, {
|
|
4725
|
+
headers: {
|
|
4726
|
+
"Content-Type": 'application/json'
|
|
4727
|
+
},
|
|
4728
|
+
params: {
|
|
4729
|
+
refreshToken: refreshToken
|
|
4730
|
+
}
|
|
4731
|
+
})];
|
|
4732
|
+
case 1:
|
|
4733
|
+
response = _a.sent();
|
|
4734
|
+
token = response.data.result;
|
|
4735
|
+
if (token) {
|
|
4736
|
+
return [2 /*return*/, [token, refreshToken]];
|
|
4737
|
+
}
|
|
4738
|
+
else {
|
|
4739
|
+
throw new Error("Token is not valid");
|
|
4740
|
+
}
|
|
4741
|
+
}
|
|
4742
|
+
});
|
|
4743
|
+
});
|
|
4744
|
+
}
|
|
4745
|
+
function isUnauthorizedError(error) {
|
|
4746
|
+
var _a = error.response, status = _a.status; _a.statusText;
|
|
4747
|
+
return status === 401;
|
|
4748
|
+
}
|
|
4749
|
+
var axiosInstance = axios.create({
|
|
4750
|
+
headers: {
|
|
4751
|
+
Authorization: "Bearer ".concat(getTokenFromLS())
|
|
4752
|
+
}
|
|
4753
|
+
});
|
|
4754
|
+
var refreshingFunc;
|
|
4755
|
+
axiosInstance.interceptors.response.use(function (res) { return res; }, function (error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4756
|
+
var originalConfig, token, _a, newToken, newRefreshToken, innerError_1;
|
|
4757
|
+
return __generator(this, function (_b) {
|
|
4758
|
+
switch (_b.label) {
|
|
4759
|
+
case 0:
|
|
4760
|
+
originalConfig = error.config;
|
|
4761
|
+
if (originalConfig.headers.MESF_Retries === 1) {
|
|
4762
|
+
localStorage.removeItem("token");
|
|
4763
|
+
localStorage.removeItem("refreshToken");
|
|
4764
|
+
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
4765
|
+
}
|
|
4766
|
+
token = getTokenFromLS();
|
|
4767
|
+
if (!token || !isUnauthorizedError(error)) {
|
|
4768
|
+
return [2 /*return*/, Promise.reject(error)];
|
|
4769
|
+
}
|
|
4770
|
+
_b.label = 1;
|
|
4771
|
+
case 1:
|
|
4772
|
+
_b.trys.push([1, 7, 8, 9]);
|
|
4773
|
+
// the trick here, that `refreshingFunc` is global, e.g. 2 expired requests will get the same function pointer and await same function.
|
|
4774
|
+
if (!refreshingFunc)
|
|
4775
|
+
refreshingFunc = renewToken();
|
|
4776
|
+
return [4 /*yield*/, refreshingFunc];
|
|
4777
|
+
case 2:
|
|
4778
|
+
_a = _b.sent(), newToken = _a[0], newRefreshToken = _a[1];
|
|
4779
|
+
localStorage.setItem("token", newToken);
|
|
4780
|
+
localStorage.setItem("refreshToken", newRefreshToken);
|
|
4781
|
+
axiosInstance.defaults.headers.Authorization = "Bearer ".concat(newToken);
|
|
4782
|
+
originalConfig.headers.Authorization = "Bearer ".concat(newToken);
|
|
4783
|
+
originalConfig.headers.MESF_Retries = 1;
|
|
4784
|
+
_b.label = 3;
|
|
4785
|
+
case 3:
|
|
4786
|
+
_b.trys.push([3, 5, , 6]);
|
|
4787
|
+
return [4 /*yield*/, axios.request(originalConfig)];
|
|
4788
|
+
case 4: return [2 /*return*/, _b.sent()];
|
|
4789
|
+
case 5:
|
|
4790
|
+
innerError_1 = _b.sent();
|
|
4791
|
+
// if original req failed with 401 again - it means server returned not valid token for refresh request
|
|
4792
|
+
if (isUnauthorizedError(innerError_1)) {
|
|
4793
|
+
return [2 /*return*/, innerError_1];
|
|
4794
|
+
}
|
|
4795
|
+
return [2 /*return*/, innerError_1];
|
|
4796
|
+
case 6: return [3 /*break*/, 9];
|
|
4797
|
+
case 7:
|
|
4798
|
+
_b.sent();
|
|
4799
|
+
localStorage.removeItem("token");
|
|
4800
|
+
localStorage.removeItem("refreshToken");
|
|
4801
|
+
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
4802
|
+
return [3 /*break*/, 9];
|
|
4803
|
+
case 8:
|
|
4804
|
+
refreshingFunc = undefined;
|
|
4805
|
+
return [7 /*endfinally*/];
|
|
4806
|
+
case 9: return [2 /*return*/];
|
|
4807
|
+
}
|
|
4808
|
+
});
|
|
4809
|
+
}); }, {});
|
|
4810
|
+
|
|
4811
|
+
var base$1 = document.getElementsByTagName('base')[0].getAttribute('href') || '/';
|
|
4711
4812
|
var MESApiService = /** @class */ (function () {
|
|
4712
4813
|
function MESApiService() {
|
|
4713
4814
|
this.config = new Configuration$1();
|
|
@@ -4838,37 +4939,12 @@ var MESApiService = /** @class */ (function () {
|
|
|
4838
4939
|
};
|
|
4839
4940
|
MESApiService.prototype.loginWithWindowsAuthentication = function () {
|
|
4840
4941
|
return __awaiter(this, void 0, void 0, function () {
|
|
4841
|
-
var isError, data;
|
|
4842
|
-
var _this = this;
|
|
4843
4942
|
return __generator(this, function (_a) {
|
|
4844
|
-
this.
|
|
4845
|
-
|
|
4846
|
-
data = {};
|
|
4847
|
-
return [2 /*return*/, fetch(this.config.API_AUTH_URL + '/authenticate/windows', {
|
|
4848
|
-
method: "POST",
|
|
4849
|
-
mode: "cors",
|
|
4943
|
+
return [2 /*return*/, axiosInstance.post(this.config.API_AUTH_URL + '/authenticate/windows', {}, {
|
|
4944
|
+
withCredentials: true,
|
|
4850
4945
|
headers: {
|
|
4851
4946
|
"Content-Type": "application/json"
|
|
4852
|
-
}
|
|
4853
|
-
body: JSON.stringify(data)
|
|
4854
|
-
})["catch"](function (errorMsg) {
|
|
4855
|
-
throw new FetchError(errorMsg.message, 404, "ERR_CONNECTION_REFUSED");
|
|
4856
|
-
})
|
|
4857
|
-
.then(function (response) {
|
|
4858
|
-
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
4859
|
-
return response.json();
|
|
4860
|
-
})
|
|
4861
|
-
.then(function (object) {
|
|
4862
|
-
if (!isError.ok)
|
|
4863
|
-
throw new FetchError(isError.statusText, isError.status, object);
|
|
4864
|
-
return object;
|
|
4865
|
-
})["catch"](function (err) {
|
|
4866
|
-
_this.hasErrors = true;
|
|
4867
|
-
_this.error = err;
|
|
4868
|
-
return {
|
|
4869
|
-
hasErrors: true,
|
|
4870
|
-
error: err
|
|
4871
|
-
};
|
|
4947
|
+
}
|
|
4872
4948
|
})];
|
|
4873
4949
|
});
|
|
4874
4950
|
});
|
|
@@ -4929,7 +5005,7 @@ var MESApiService = /** @class */ (function () {
|
|
|
4929
5005
|
})
|
|
4930
5006
|
.then(function (response) {
|
|
4931
5007
|
if (response.status === 401) {
|
|
4932
|
-
window.location.href = "".concat(base$
|
|
5008
|
+
window.location.href = "".concat(base$1, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
4933
5009
|
}
|
|
4934
5010
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
4935
5011
|
return response.json();
|
|
@@ -4981,7 +5057,7 @@ var MESApiService = /** @class */ (function () {
|
|
|
4981
5057
|
})
|
|
4982
5058
|
.then(function (response) {
|
|
4983
5059
|
if (response.status === 401) {
|
|
4984
|
-
window.location.href = "".concat(base$
|
|
5060
|
+
window.location.href = "".concat(base$1, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
4985
5061
|
}
|
|
4986
5062
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
4987
5063
|
return response.json();
|
|
@@ -5036,7 +5112,7 @@ var MESApiService = /** @class */ (function () {
|
|
|
5036
5112
|
})
|
|
5037
5113
|
.then(function (response) {
|
|
5038
5114
|
if (response.status === 401) {
|
|
5039
|
-
window.location.href = "".concat(base$
|
|
5115
|
+
window.location.href = "".concat(base$1, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5040
5116
|
}
|
|
5041
5117
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
5042
5118
|
return response.json();
|
|
@@ -5089,7 +5165,7 @@ var MESApiService = /** @class */ (function () {
|
|
|
5089
5165
|
})
|
|
5090
5166
|
.then(function (response) {
|
|
5091
5167
|
if (response.status === 401) {
|
|
5092
|
-
window.location.href = "".concat(base$
|
|
5168
|
+
window.location.href = "".concat(base$1, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5093
5169
|
}
|
|
5094
5170
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
5095
5171
|
if (!isError.ok)
|
|
@@ -5158,7 +5234,7 @@ var MESApiService = /** @class */ (function () {
|
|
|
5158
5234
|
})
|
|
5159
5235
|
.then(function (response) {
|
|
5160
5236
|
if (response.status === 401) {
|
|
5161
|
-
window.location.href = "".concat(base$
|
|
5237
|
+
window.location.href = "".concat(base$1, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5162
5238
|
}
|
|
5163
5239
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
5164
5240
|
if (!isError.ok)
|
|
@@ -5809,23 +5885,25 @@ var LoginWithWindowsAuthentication = function () {
|
|
|
5809
5885
|
});
|
|
5810
5886
|
}); };
|
|
5811
5887
|
var login = useCallback(function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
5812
|
-
var apiService, response;
|
|
5888
|
+
var apiService, response, e_1;
|
|
5813
5889
|
return __generator(this, function (_a) {
|
|
5814
5890
|
switch (_a.label) {
|
|
5815
5891
|
case 0:
|
|
5816
5892
|
apiService = new MESApiService();
|
|
5817
5893
|
e.preventDefault();
|
|
5818
|
-
|
|
5894
|
+
_a.label = 1;
|
|
5819
5895
|
case 1:
|
|
5896
|
+
_a.trys.push([1, 3, , 4]);
|
|
5897
|
+
return [4 /*yield*/, apiService.loginWithWindowsAuthentication()];
|
|
5898
|
+
case 2:
|
|
5820
5899
|
response = _a.sent();
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
return [2 /*return*/];
|
|
5900
|
+
saveUserData(response.data);
|
|
5901
|
+
return [3 /*break*/, 4];
|
|
5902
|
+
case 3:
|
|
5903
|
+
e_1 = _a.sent();
|
|
5904
|
+
setError(e_1);
|
|
5905
|
+
return [3 /*break*/, 4];
|
|
5906
|
+
case 4: return [2 /*return*/];
|
|
5829
5907
|
}
|
|
5830
5908
|
});
|
|
5831
5909
|
}); }, [setShowError,
|
|
@@ -5833,7 +5911,6 @@ var LoginWithWindowsAuthentication = function () {
|
|
|
5833
5911
|
saveUserData]);
|
|
5834
5912
|
useEffect(function () {
|
|
5835
5913
|
checkIfEnabled().then(function () {
|
|
5836
|
-
console.log('done');
|
|
5837
5914
|
});
|
|
5838
5915
|
}, []);
|
|
5839
5916
|
if (windowsAuthIsEnabled)
|
|
@@ -5845,8 +5922,7 @@ var LoginWithWindowsAuthentication = function () {
|
|
|
5845
5922
|
React__default.createElement("strong", null, "Bad credentials"),
|
|
5846
5923
|
React__default.createElement("p", null,
|
|
5847
5924
|
" ",
|
|
5848
|
-
error
|
|
5849
|
-
(error.internalError.message === undefined ? error.internalError : error.internalError.message))),
|
|
5925
|
+
error)),
|
|
5850
5926
|
React__default.createElement("div", { className: "row" },
|
|
5851
5927
|
React__default.createElement("button", { className: "btn btn-primary mes-button-primary mx-auto col-md-12 mt-3 ", role: "button", onClick: login }, "Windows Auth"))));
|
|
5852
5928
|
return null;
|
|
@@ -6173,7 +6249,7 @@ var Navigation = function (_a) {
|
|
|
6173
6249
|
var css = "body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n background-color: #fafbfc !important;\n}\n.container-fluid-main{\n padding-right: 0px !important; \n padding-left: 0px !important;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n monospace;\n}\n\n.mes-primary-color {\n background-color: #479dc4 !important;\n}\n.mes-button-primary{\n background-color: #479dc4 !important;\n border-color: #479dc4 !important;\n}\n\n.mes-selectable-datagrid .MuiDataGrid-row{\n cursor: pointer;\n}\n\n.mes-menu-top .navbar-brand{\n color: #FFFF !important;\n}\n.mes-menu-top .nav-link {\n color: #FFFF !important;\n}\n.mes-menu-top .navbar-toggler {\n color: #FFFF !important;\n}\n.mes-menu-top .navbar-text {\n color: #FFFF !important;\n}\n.mes-footer-login{\n position: absolute;\n bottom: 0;\n width: 100%;\n height: 10em;\n line-height: 60px;\n text-align:center;\n}\n.mes-filter-datepicker{\n padding: unset !important;\n border-top-left-radius: 0 !important;\n border-bottom-left-radius: 0 !important;\n padding-top: 0.375rem !important;\n padding-bottom: 0.375rem !important;\n padding-left: 0.75rem !important;\n cursor: pointer !important;\n max-width: 120px;\n}\n.mes-filter-datetimepicker{\n max-width: 97px;\n}\n.mes-not-rounded{\n border-radius: unset !important;\n}\n\n.mes-numeric{\n text-align: right;\n}\n.mes-drag-over{\n border: 3px dotted #666;\n background-color: #479dc4 !important;\n}\n.mes-drag-start{\n border: 3px solid #666;\n}\n\n.mes-selectable{\n cursor: pointer !important;\n}\n\n.mes-custom-select{\n width: auto !important;\n padding: 0.375rem 0 0.375rem 0 !important;\n background: unset !important;\n font-family: inherit !important;\n}\n.mes-custom-select .MuiSelect-select{\n padding-left: 14px;\n}\n\n.mes-custom-select::before{\n border-bottom: unset !important;\n}\n.mes-custom-select::after{\n border-bottom: unset !important;\n}\n.mes-no-border{\n border: unset;\n}\n.mes-no-border:focus-visible {\n outline: unset;\n}\n.mes-div-submenu{\n border-right: 1px solid #cfdbe2; \n}\n.mes-submenu a{\n width: 100% !important;\n /* color: rgba(0, 0, 0, 0.87); */\n color: #479dc4\n}\n.mes-submenu .Mui-selected{\n border-right: 3px solid #479dc4; \n}\n.mes-menu-group{\n font-size: 20px;\n line-height: 1.1;\n color: #929292; \n font-weight: normal; \n}\n\n/********************MUI DATAGRID*****************************/\n.Mui-selected{\n font-weight: bolder !important;\n opacity: 1 !important;\n}\n\n.mes-upload-control{\n\n}\n.mes-upload-control .file-box{\n /* border : 1px solid black; */\n height : 100px;\n position: relative; \n}\n.mes-upload-control .file-detail{\n position: absolute;\n left: 0px;\n top: 0px; \n z-index: 1;\n height: 100%;\n width: 100%;\n}\n\n.mes-upload-control input[type=file]{\n left: 0px;\n top: 0px;\n opacity: 0;\n z-index: 10000;\n height: 100%;\n cursor: pointer;\n}\n.mes-upload-control table{\n width: 100%;\n}\n.mes-upload-control td{\n font-size: 0.8rem !important;\n max-width:0;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;\n}\n\n\n.input-group-text{\n background-color: #ced2cc !important;\n /* border: 1px solid #ced4da !important; */\n /* color: #000000 !important; */\n}\n\n\n\n\n.content-wrapper {\n padding: 15px;\n width: 100%;\n border-top: 1px solid rgba(0, 0, 0, 0.15);\n margin-top: -1px;\n}\n.content-wrapper > .unwrap {\n margin: -15px;\n}\n@media only screen and (min-width: 768px) {\n .content-wrapper > .unwrap {\n margin: -20px;\n }\n}\n.content-wrapper > h3,\n.content-wrapper > .content-heading {\n font-size: 24px;\n line-height: 1.1;\n color: #929292;\n margin: -15px;\n margin-bottom: 20px;\n padding: 15px;\n font-weight: normal;\n background-color: #fafbfc;\n border-bottom: 1px solid #cfdbe2;\n}\n.content-wrapper > h3 > small,\n.content-wrapper > .content-heading > small {\n display: block;\n font-size: 12px;\n color: #909fa7;\n}\n.content-wrapper > button,\n.content-wrapper > .btn {\n margin: 10px 10px 0 0;\n}\n.content-wrapper .container,\n.content-wrapper .container-fluid {\n padding-left: 0;\n padding-right: 0;\n}\n@media only screen and (min-width: 768px) {\n .content-wrapper {\n padding: 20px;\n }\n .content-wrapper > h3,\n .content-wrapper > .content-heading {\n margin: -20px;\n margin-bottom: 5px;\n padding: 15px;\n }\n .content-wrapper > button,\n .content-wrapper > .btn {\n margin: 0;\n }\n}\n\n @media print {\n .sidebar,\n .topnavbar,\n .offsidebar,\n .btn {\n display: none !important;\n width: 0 !important;\n height: 0 !important;\n }\n .wrapper,\n .wrapper > section,\n .content-wrapper {\n margin: 0 !important;\n /* remove margin used for sidebar and expand the content */\n padding: 0 !important;\n width: 100% !important;\n }\n .content-wrapper {\n overflow: hidden !important;\n }\n }\n ";
|
|
6174
6250
|
n(css,{});
|
|
6175
6251
|
|
|
6176
|
-
var base
|
|
6252
|
+
var base = document.getElementsByTagName('base')[0].getAttribute('href') || '/';
|
|
6177
6253
|
function MESFMain(_a) {
|
|
6178
6254
|
var authentication = _a.authentication, routes = _a.routes, navbar = _a.navbar, configurations = _a.configurations, _b = _a.showAreaSelector, showAreaSelector = _b === void 0 ? false : _b;
|
|
6179
6255
|
return (React__default.createElement(AuthProvider, { authConfig: authentication },
|
|
@@ -6183,113 +6259,12 @@ function MESFMain(_a) {
|
|
|
6183
6259
|
React__default.createElement(RouterContext.Provider, { value: routes },
|
|
6184
6260
|
React__default.createElement(NavbarContext.Provider, { value: navbar },
|
|
6185
6261
|
React__default.createElement(ConfigurationContext.Provider, { value: configurations },
|
|
6186
|
-
React__default.createElement(BrowserRouter, { basename: base
|
|
6262
|
+
React__default.createElement(BrowserRouter, { basename: base },
|
|
6187
6263
|
React__default.createElement(Routes, null,
|
|
6188
6264
|
React__default.createElement(Route, { path: "/logout", element: React__default.createElement(Logout, null) })),
|
|
6189
6265
|
React__default.createElement(Navigation, { showAreaSelector: showAreaSelector }))))))))));
|
|
6190
6266
|
}
|
|
6191
6267
|
|
|
6192
|
-
var base = document.getElementsByTagName('base')[0].getAttribute('href') || '/';
|
|
6193
|
-
function renewToken() {
|
|
6194
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
6195
|
-
var refreshToken, config, fd, response, token;
|
|
6196
|
-
return __generator(this, function (_a) {
|
|
6197
|
-
switch (_a.label) {
|
|
6198
|
-
case 0:
|
|
6199
|
-
refreshToken = localStorage.getItem("refreshToken");
|
|
6200
|
-
if (!refreshToken) {
|
|
6201
|
-
throw new Error('refresh token does not exist');
|
|
6202
|
-
}
|
|
6203
|
-
config = new Configuration$1();
|
|
6204
|
-
fd = new FormData();
|
|
6205
|
-
fd.append('refreshToken', refreshToken);
|
|
6206
|
-
return [4 /*yield*/, axios.post("".concat(config.API_AUTH_URL, "/refresh"), fd, {
|
|
6207
|
-
headers: {
|
|
6208
|
-
"Content-Type": 'application/json'
|
|
6209
|
-
},
|
|
6210
|
-
params: {
|
|
6211
|
-
refreshToken: refreshToken
|
|
6212
|
-
}
|
|
6213
|
-
})];
|
|
6214
|
-
case 1:
|
|
6215
|
-
response = _a.sent();
|
|
6216
|
-
token = response.data.result;
|
|
6217
|
-
if (token) {
|
|
6218
|
-
return [2 /*return*/, [token, refreshToken]];
|
|
6219
|
-
}
|
|
6220
|
-
else {
|
|
6221
|
-
throw new Error("Token is not valid");
|
|
6222
|
-
}
|
|
6223
|
-
}
|
|
6224
|
-
});
|
|
6225
|
-
});
|
|
6226
|
-
}
|
|
6227
|
-
function isUnauthorizedError(error) {
|
|
6228
|
-
var _a = error.response, status = _a.status; _a.statusText;
|
|
6229
|
-
return status === 401;
|
|
6230
|
-
}
|
|
6231
|
-
var axiosInstance = axios.create({
|
|
6232
|
-
headers: {
|
|
6233
|
-
Authorization: "Bearer ".concat(getTokenFromLS())
|
|
6234
|
-
}
|
|
6235
|
-
});
|
|
6236
|
-
var refreshingFunc;
|
|
6237
|
-
axiosInstance.interceptors.response.use(function (res) { return res; }, function (error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
6238
|
-
var originalConfig, token, _a, newToken, newRefreshToken, innerError_1;
|
|
6239
|
-
return __generator(this, function (_b) {
|
|
6240
|
-
switch (_b.label) {
|
|
6241
|
-
case 0:
|
|
6242
|
-
originalConfig = error.config;
|
|
6243
|
-
if (originalConfig.headers.MESF_Retries === 1) {
|
|
6244
|
-
localStorage.removeItem("token");
|
|
6245
|
-
localStorage.removeItem("refreshToken");
|
|
6246
|
-
window.location.href = "".concat(base, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
6247
|
-
}
|
|
6248
|
-
token = getTokenFromLS();
|
|
6249
|
-
if (!token || !isUnauthorizedError(error)) {
|
|
6250
|
-
return [2 /*return*/, Promise.reject(error)];
|
|
6251
|
-
}
|
|
6252
|
-
_b.label = 1;
|
|
6253
|
-
case 1:
|
|
6254
|
-
_b.trys.push([1, 7, 8, 9]);
|
|
6255
|
-
// the trick here, that `refreshingFunc` is global, e.g. 2 expired requests will get the same function pointer and await same function.
|
|
6256
|
-
if (!refreshingFunc)
|
|
6257
|
-
refreshingFunc = renewToken();
|
|
6258
|
-
return [4 /*yield*/, refreshingFunc];
|
|
6259
|
-
case 2:
|
|
6260
|
-
_a = _b.sent(), newToken = _a[0], newRefreshToken = _a[1];
|
|
6261
|
-
localStorage.setItem("token", newToken);
|
|
6262
|
-
localStorage.setItem("refreshToken", newRefreshToken);
|
|
6263
|
-
axiosInstance.defaults.headers.Authorization = "Bearer ".concat(newToken);
|
|
6264
|
-
originalConfig.headers.Authorization = "Bearer ".concat(newToken);
|
|
6265
|
-
originalConfig.headers.MESF_Retries = 1;
|
|
6266
|
-
_b.label = 3;
|
|
6267
|
-
case 3:
|
|
6268
|
-
_b.trys.push([3, 5, , 6]);
|
|
6269
|
-
return [4 /*yield*/, axios.request(originalConfig)];
|
|
6270
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
6271
|
-
case 5:
|
|
6272
|
-
innerError_1 = _b.sent();
|
|
6273
|
-
// if original req failed with 401 again - it means server returned not valid token for refresh request
|
|
6274
|
-
if (isUnauthorizedError(innerError_1)) {
|
|
6275
|
-
return [2 /*return*/, innerError_1];
|
|
6276
|
-
}
|
|
6277
|
-
return [2 /*return*/, innerError_1];
|
|
6278
|
-
case 6: return [3 /*break*/, 9];
|
|
6279
|
-
case 7:
|
|
6280
|
-
_b.sent();
|
|
6281
|
-
localStorage.removeItem("token");
|
|
6282
|
-
localStorage.removeItem("refreshToken");
|
|
6283
|
-
window.location.href = "".concat(base, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
6284
|
-
return [3 /*break*/, 9];
|
|
6285
|
-
case 8:
|
|
6286
|
-
refreshingFunc = undefined;
|
|
6287
|
-
return [7 /*endfinally*/];
|
|
6288
|
-
case 9: return [2 /*return*/];
|
|
6289
|
-
}
|
|
6290
|
-
});
|
|
6291
|
-
}); }, {});
|
|
6292
|
-
|
|
6293
6268
|
var useDefaultAreaId = function () {
|
|
6294
6269
|
var _a = useUserContext(), userId = _a.state.userId, setDefaultAreaId = _a.actions.setDefaultAreaId;
|
|
6295
6270
|
return function () {
|
|
@@ -28,7 +28,7 @@ export declare class MESApiService {
|
|
|
28
28
|
changePassword(userId: string, password: string): Promise<any>;
|
|
29
29
|
authenticate(userName: string, password: string): Promise<any>;
|
|
30
30
|
loginWithAzureAD(accessToken: string): Promise<any>;
|
|
31
|
-
loginWithWindowsAuthentication(): Promise<any
|
|
31
|
+
loginWithWindowsAuthentication(): Promise<import("axios").AxiosResponse<any, any>>;
|
|
32
32
|
uploadFiles(selectedFiles: File[], folderName?: string): Promise<any>;
|
|
33
33
|
call(procedure: string, parameters: any[], database?: string): Promise<any>;
|
|
34
34
|
callJSON(procedure: string, parameters: any[], database?: string): Promise<any>;
|