@dexteel/mesf-core 3.11.7 → 3.11.9
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 +127 -121
- package/dist/services/ApiService.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -4707,109 +4707,7 @@ var Configuration$1 = /** @class */ (function () {
|
|
|
4707
4707
|
return Configuration;
|
|
4708
4708
|
}());
|
|
4709
4709
|
|
|
4710
|
-
var _a;
|
|
4711
4710
|
var base$2 = document.getElementsByTagName('base')[0].getAttribute('href') || '/';
|
|
4712
|
-
function renewToken() {
|
|
4713
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
4714
|
-
var refreshToken, config, fd, response, token;
|
|
4715
|
-
return __generator(this, function (_a) {
|
|
4716
|
-
switch (_a.label) {
|
|
4717
|
-
case 0:
|
|
4718
|
-
refreshToken = localStorage.getItem("refreshToken");
|
|
4719
|
-
if (!refreshToken) {
|
|
4720
|
-
throw new Error('refresh token does not exist');
|
|
4721
|
-
}
|
|
4722
|
-
config = new Configuration$1();
|
|
4723
|
-
fd = new FormData();
|
|
4724
|
-
fd.append('refreshToken', refreshToken);
|
|
4725
|
-
return [4 /*yield*/, axios.post("".concat(config.API_AUTH_URL, "/refresh"), fd, {
|
|
4726
|
-
headers: {
|
|
4727
|
-
"Content-Type": 'application/json'
|
|
4728
|
-
},
|
|
4729
|
-
params: {
|
|
4730
|
-
refreshToken: refreshToken
|
|
4731
|
-
}
|
|
4732
|
-
})];
|
|
4733
|
-
case 1:
|
|
4734
|
-
response = _a.sent();
|
|
4735
|
-
token = response.data.result;
|
|
4736
|
-
if (token) {
|
|
4737
|
-
return [2 /*return*/, [token, refreshToken]];
|
|
4738
|
-
}
|
|
4739
|
-
else {
|
|
4740
|
-
throw new Error("Token is not valid");
|
|
4741
|
-
}
|
|
4742
|
-
}
|
|
4743
|
-
});
|
|
4744
|
-
});
|
|
4745
|
-
}
|
|
4746
|
-
function isUnauthorizedError(error) {
|
|
4747
|
-
var _a = error.response, status = _a.status; _a.statusText;
|
|
4748
|
-
return status === 401;
|
|
4749
|
-
}
|
|
4750
|
-
var axiosInstance = axios.create({
|
|
4751
|
-
headers: {
|
|
4752
|
-
Authorization: "Bearer ".concat((_a = localStorage.getItem('token')) !== null && _a !== void 0 ? _a : '')
|
|
4753
|
-
}
|
|
4754
|
-
});
|
|
4755
|
-
var refreshingFunc;
|
|
4756
|
-
axiosInstance.interceptors.response.use(function (res) { return res; }, function (error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4757
|
-
var originalConfig, token, _a, newToken, newRefreshToken, innerError_1;
|
|
4758
|
-
return __generator(this, function (_b) {
|
|
4759
|
-
switch (_b.label) {
|
|
4760
|
-
case 0:
|
|
4761
|
-
originalConfig = error.config;
|
|
4762
|
-
if (originalConfig.headers.MESF_Retries === 1) {
|
|
4763
|
-
localStorage.removeItem("token");
|
|
4764
|
-
localStorage.removeItem("refreshToken");
|
|
4765
|
-
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
4766
|
-
}
|
|
4767
|
-
token = getTokenFromLS();
|
|
4768
|
-
if (!token || !isUnauthorizedError(error)) {
|
|
4769
|
-
return [2 /*return*/, Promise.reject(error)];
|
|
4770
|
-
}
|
|
4771
|
-
_b.label = 1;
|
|
4772
|
-
case 1:
|
|
4773
|
-
_b.trys.push([1, 7, 8, 9]);
|
|
4774
|
-
// the trick here, that `refreshingFunc` is global, e.g. 2 expired requests will get the same function pointer and await same function.
|
|
4775
|
-
if (!refreshingFunc)
|
|
4776
|
-
refreshingFunc = renewToken();
|
|
4777
|
-
return [4 /*yield*/, refreshingFunc];
|
|
4778
|
-
case 2:
|
|
4779
|
-
_a = _b.sent(), newToken = _a[0], newRefreshToken = _a[1];
|
|
4780
|
-
localStorage.setItem("token", newToken);
|
|
4781
|
-
localStorage.setItem("refreshToken", newRefreshToken);
|
|
4782
|
-
axiosInstance.defaults.headers.Authorization = "Bearer ".concat(newToken);
|
|
4783
|
-
originalConfig.headers.Authorization = "Bearer ".concat(newToken);
|
|
4784
|
-
originalConfig.headers.MESF_Retries = 1;
|
|
4785
|
-
_b.label = 3;
|
|
4786
|
-
case 3:
|
|
4787
|
-
_b.trys.push([3, 5, , 6]);
|
|
4788
|
-
return [4 /*yield*/, axios.request(originalConfig)];
|
|
4789
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
4790
|
-
case 5:
|
|
4791
|
-
innerError_1 = _b.sent();
|
|
4792
|
-
// if original req failed with 401 again - it means server returned not valid token for refresh request
|
|
4793
|
-
if (isUnauthorizedError(innerError_1)) {
|
|
4794
|
-
return [2 /*return*/, innerError_1];
|
|
4795
|
-
}
|
|
4796
|
-
return [2 /*return*/, innerError_1];
|
|
4797
|
-
case 6: return [3 /*break*/, 9];
|
|
4798
|
-
case 7:
|
|
4799
|
-
_b.sent();
|
|
4800
|
-
localStorage.removeItem("token");
|
|
4801
|
-
localStorage.removeItem("refreshToken");
|
|
4802
|
-
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
4803
|
-
return [3 /*break*/, 9];
|
|
4804
|
-
case 8:
|
|
4805
|
-
refreshingFunc = undefined;
|
|
4806
|
-
return [7 /*endfinally*/];
|
|
4807
|
-
case 9: return [2 /*return*/];
|
|
4808
|
-
}
|
|
4809
|
-
});
|
|
4810
|
-
}); }, {});
|
|
4811
|
-
|
|
4812
|
-
var base$1 = document.getElementsByTagName('base')[0].getAttribute('href') || '/';
|
|
4813
4711
|
var MESApiService = /** @class */ (function () {
|
|
4814
4712
|
function MESApiService() {
|
|
4815
4713
|
this.config = new Configuration$1();
|
|
@@ -4941,11 +4839,14 @@ var MESApiService = /** @class */ (function () {
|
|
|
4941
4839
|
MESApiService.prototype.loginWithWindowsAuthentication = function () {
|
|
4942
4840
|
return __awaiter(this, void 0, void 0, function () {
|
|
4943
4841
|
return __generator(this, function (_a) {
|
|
4944
|
-
return [2 /*return*/,
|
|
4945
|
-
|
|
4842
|
+
return [2 /*return*/, fetch(this.config.API_AUTH_URL + '/authenticate/windows', {
|
|
4843
|
+
method: "POST",
|
|
4844
|
+
mode: "cors",
|
|
4845
|
+
credentials: 'include',
|
|
4946
4846
|
headers: {
|
|
4947
4847
|
"Content-Type": "application/json"
|
|
4948
|
-
}
|
|
4848
|
+
},
|
|
4849
|
+
body: JSON.stringify({})
|
|
4949
4850
|
})];
|
|
4950
4851
|
});
|
|
4951
4852
|
});
|
|
@@ -5005,8 +4906,8 @@ var MESApiService = /** @class */ (function () {
|
|
|
5005
4906
|
throw new FetchError(errorMsg.message, 404, "ERR_CONNECTION_REFUSED");
|
|
5006
4907
|
})
|
|
5007
4908
|
.then(function (response) {
|
|
5008
|
-
if (response.status === 401) {
|
|
5009
|
-
window.location.href = "".concat(base$
|
|
4909
|
+
if (response.status === 499 || response.status === 401) {
|
|
4910
|
+
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5010
4911
|
}
|
|
5011
4912
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
5012
4913
|
return response.json();
|
|
@@ -5057,8 +4958,8 @@ var MESApiService = /** @class */ (function () {
|
|
|
5057
4958
|
throw new FetchError(errorMsg.message, 404, "ERR_CONNECTION_REFUSED");
|
|
5058
4959
|
})
|
|
5059
4960
|
.then(function (response) {
|
|
5060
|
-
if (response.status === 401) {
|
|
5061
|
-
window.location.href = "".concat(base$
|
|
4961
|
+
if (response.status === 499 || response.status === 401) {
|
|
4962
|
+
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5062
4963
|
}
|
|
5063
4964
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
5064
4965
|
return response.json();
|
|
@@ -5112,8 +5013,8 @@ var MESApiService = /** @class */ (function () {
|
|
|
5112
5013
|
throw new FetchError(errorMsg.message, 404, "ERR_CONNECTION_REFUSED");
|
|
5113
5014
|
})
|
|
5114
5015
|
.then(function (response) {
|
|
5115
|
-
if (response.status === 401) {
|
|
5116
|
-
window.location.href = "".concat(base$
|
|
5016
|
+
if (response.status === 499 || response.status === 401) {
|
|
5017
|
+
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5117
5018
|
}
|
|
5118
5019
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
5119
5020
|
return response.json();
|
|
@@ -5165,8 +5066,8 @@ var MESApiService = /** @class */ (function () {
|
|
|
5165
5066
|
throw new FetchError(errorMsg.message, 404, "ERR_CONNECTION_REFUSED");
|
|
5166
5067
|
})
|
|
5167
5068
|
.then(function (response) {
|
|
5168
|
-
if (response.status === 401) {
|
|
5169
|
-
window.location.href = "".concat(base$
|
|
5069
|
+
if (response.status === 499 || response.status === 401) {
|
|
5070
|
+
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5170
5071
|
}
|
|
5171
5072
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
5172
5073
|
if (!isError.ok)
|
|
@@ -5234,8 +5135,8 @@ var MESApiService = /** @class */ (function () {
|
|
|
5234
5135
|
throw new FetchError(errorMsg.message, 404, "ERR_CONNECTION_REFUSED");
|
|
5235
5136
|
})
|
|
5236
5137
|
.then(function (response) {
|
|
5237
|
-
if (response.status === 401) {
|
|
5238
|
-
window.location.href = "".concat(base$
|
|
5138
|
+
if (response.status === 499 || response.status === 401) {
|
|
5139
|
+
window.location.href = "".concat(base$2, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5239
5140
|
}
|
|
5240
5141
|
isError = { ok: response.ok, status: response.status, statusText: response.statusText };
|
|
5241
5142
|
if (!isError.ok)
|
|
@@ -5489,6 +5390,108 @@ var UserProvider = function (_a) {
|
|
|
5489
5390
|
return (React__default.createElement(UserContext.Provider, { value: { state: state, actions: actions } }, children));
|
|
5490
5391
|
};
|
|
5491
5392
|
|
|
5393
|
+
var _a;
|
|
5394
|
+
var base$1 = document.getElementsByTagName('base')[0].getAttribute('href') || '/';
|
|
5395
|
+
function renewToken() {
|
|
5396
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5397
|
+
var refreshToken, config, fd, response, token;
|
|
5398
|
+
return __generator(this, function (_a) {
|
|
5399
|
+
switch (_a.label) {
|
|
5400
|
+
case 0:
|
|
5401
|
+
refreshToken = localStorage.getItem("refreshToken");
|
|
5402
|
+
if (!refreshToken) {
|
|
5403
|
+
throw new Error('refresh token does not exist');
|
|
5404
|
+
}
|
|
5405
|
+
config = new Configuration$1();
|
|
5406
|
+
fd = new FormData();
|
|
5407
|
+
fd.append('refreshToken', refreshToken);
|
|
5408
|
+
return [4 /*yield*/, axios.post("".concat(config.API_AUTH_URL, "/refresh"), fd, {
|
|
5409
|
+
headers: {
|
|
5410
|
+
"Content-Type": 'application/json'
|
|
5411
|
+
},
|
|
5412
|
+
params: {
|
|
5413
|
+
refreshToken: refreshToken
|
|
5414
|
+
}
|
|
5415
|
+
})];
|
|
5416
|
+
case 1:
|
|
5417
|
+
response = _a.sent();
|
|
5418
|
+
token = response.data.result;
|
|
5419
|
+
if (token) {
|
|
5420
|
+
return [2 /*return*/, [token, refreshToken]];
|
|
5421
|
+
}
|
|
5422
|
+
else {
|
|
5423
|
+
throw new Error("Token is not valid");
|
|
5424
|
+
}
|
|
5425
|
+
}
|
|
5426
|
+
});
|
|
5427
|
+
});
|
|
5428
|
+
}
|
|
5429
|
+
function isUnauthorizedError(error) {
|
|
5430
|
+
var status = error.response.status;
|
|
5431
|
+
return status === 499 || status === 499; // custom status code
|
|
5432
|
+
}
|
|
5433
|
+
var axiosInstance = axios.create({
|
|
5434
|
+
headers: {
|
|
5435
|
+
Authorization: "Bearer ".concat((_a = localStorage.getItem('token')) !== null && _a !== void 0 ? _a : '')
|
|
5436
|
+
}
|
|
5437
|
+
});
|
|
5438
|
+
var refreshingFunc;
|
|
5439
|
+
axiosInstance.interceptors.response.use(function (res) { return res; }, function (error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
5440
|
+
var originalConfig, token, _a, newToken, newRefreshToken, innerError_1;
|
|
5441
|
+
return __generator(this, function (_b) {
|
|
5442
|
+
switch (_b.label) {
|
|
5443
|
+
case 0:
|
|
5444
|
+
originalConfig = error.config;
|
|
5445
|
+
if (originalConfig.headers.MESF_Retries === 1) {
|
|
5446
|
+
localStorage.removeItem("token");
|
|
5447
|
+
localStorage.removeItem("refreshToken");
|
|
5448
|
+
window.location.href = "".concat(base$1, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5449
|
+
}
|
|
5450
|
+
token = getTokenFromLS();
|
|
5451
|
+
if (!token || !isUnauthorizedError(error)) {
|
|
5452
|
+
return [2 /*return*/, Promise.reject(error)];
|
|
5453
|
+
}
|
|
5454
|
+
_b.label = 1;
|
|
5455
|
+
case 1:
|
|
5456
|
+
_b.trys.push([1, 7, 8, 9]);
|
|
5457
|
+
// the trick here, that `refreshingFunc` is global, e.g. 2 expired requests will get the same function pointer and await same function.
|
|
5458
|
+
if (!refreshingFunc)
|
|
5459
|
+
refreshingFunc = renewToken();
|
|
5460
|
+
return [4 /*yield*/, refreshingFunc];
|
|
5461
|
+
case 2:
|
|
5462
|
+
_a = _b.sent(), newToken = _a[0], newRefreshToken = _a[1];
|
|
5463
|
+
localStorage.setItem("token", newToken);
|
|
5464
|
+
localStorage.setItem("refreshToken", newRefreshToken);
|
|
5465
|
+
axiosInstance.defaults.headers.Authorization = "Bearer ".concat(newToken);
|
|
5466
|
+
originalConfig.headers.Authorization = "Bearer ".concat(newToken);
|
|
5467
|
+
originalConfig.headers.MESF_Retries = 1;
|
|
5468
|
+
_b.label = 3;
|
|
5469
|
+
case 3:
|
|
5470
|
+
_b.trys.push([3, 5, , 6]);
|
|
5471
|
+
return [4 /*yield*/, axios.request(originalConfig)];
|
|
5472
|
+
case 4: return [2 /*return*/, _b.sent()];
|
|
5473
|
+
case 5:
|
|
5474
|
+
innerError_1 = _b.sent();
|
|
5475
|
+
// if original req failed with 499 again - it means server returned not valid token for refresh request
|
|
5476
|
+
if (isUnauthorizedError(innerError_1)) {
|
|
5477
|
+
return [2 /*return*/, innerError_1];
|
|
5478
|
+
}
|
|
5479
|
+
return [2 /*return*/, innerError_1];
|
|
5480
|
+
case 6: return [3 /*break*/, 9];
|
|
5481
|
+
case 7:
|
|
5482
|
+
_b.sent();
|
|
5483
|
+
localStorage.removeItem("token");
|
|
5484
|
+
localStorage.removeItem("refreshToken");
|
|
5485
|
+
window.location.href = "".concat(base$1, "logout?message=Session%20expired&redirectTo=").concat(window.location.href);
|
|
5486
|
+
return [3 /*break*/, 9];
|
|
5487
|
+
case 8:
|
|
5488
|
+
refreshingFunc = undefined;
|
|
5489
|
+
return [7 /*endfinally*/];
|
|
5490
|
+
case 9: return [2 /*return*/];
|
|
5491
|
+
}
|
|
5492
|
+
});
|
|
5493
|
+
}); }, {});
|
|
5494
|
+
|
|
5492
5495
|
var getTokenFromLS = function () {
|
|
5493
5496
|
return localStorage.getItem('token');
|
|
5494
5497
|
};
|
|
@@ -5887,7 +5890,7 @@ var LoginWithWindowsAuthentication = function () {
|
|
|
5887
5890
|
});
|
|
5888
5891
|
}); };
|
|
5889
5892
|
var login = useCallback(function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
5890
|
-
var apiService, response, e_1;
|
|
5893
|
+
var apiService, response, data, e_1;
|
|
5891
5894
|
return __generator(this, function (_a) {
|
|
5892
5895
|
switch (_a.label) {
|
|
5893
5896
|
case 0:
|
|
@@ -5895,18 +5898,21 @@ var LoginWithWindowsAuthentication = function () {
|
|
|
5895
5898
|
e.preventDefault();
|
|
5896
5899
|
_a.label = 1;
|
|
5897
5900
|
case 1:
|
|
5898
|
-
_a.trys.push([1,
|
|
5901
|
+
_a.trys.push([1, 4, , 5]);
|
|
5899
5902
|
return [4 /*yield*/, apiService.loginWithWindowsAuthentication()];
|
|
5900
5903
|
case 2:
|
|
5901
5904
|
response = _a.sent();
|
|
5902
|
-
|
|
5903
|
-
return [3 /*break*/, 4];
|
|
5905
|
+
return [4 /*yield*/, response.json()];
|
|
5904
5906
|
case 3:
|
|
5907
|
+
data = _a.sent();
|
|
5908
|
+
saveUserData(data);
|
|
5909
|
+
return [3 /*break*/, 5];
|
|
5910
|
+
case 4:
|
|
5905
5911
|
e_1 = _a.sent();
|
|
5906
5912
|
setShowError(true);
|
|
5907
5913
|
setError(e_1.toString());
|
|
5908
|
-
return [3 /*break*/,
|
|
5909
|
-
case
|
|
5914
|
+
return [3 /*break*/, 5];
|
|
5915
|
+
case 5: return [2 /*return*/];
|
|
5910
5916
|
}
|
|
5911
5917
|
});
|
|
5912
5918
|
}); }, [setShowError,
|
|
@@ -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<
|
|
31
|
+
loginWithWindowsAuthentication(): Promise<Response>;
|
|
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>;
|