thm-p3-configurator 0.0.339 → 0.0.341
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.
|
@@ -28,6 +28,37 @@ const sessionClient = _axios.default.create({
|
|
|
28
28
|
withCredentials: true
|
|
29
29
|
});
|
|
30
30
|
let refreshPromise = null;
|
|
31
|
+
const syncRuntimeSession = function syncRuntimeSession() {
|
|
32
|
+
var _payload$branch$entit, _payload$branch;
|
|
33
|
+
let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
34
|
+
if (!(payload !== null && payload !== void 0 && payload.authenticated)) {
|
|
35
|
+
_AuthRuntime.authRuntime.clear();
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
_AuthRuntime.authRuntime.setCsrfToken(payload.csrfToken || null);
|
|
39
|
+
_AuthRuntime.authRuntime.setActiveBranchId((_payload$branch$entit = (_payload$branch = payload.branch) === null || _payload$branch === void 0 ? void 0 : _payload$branch.entityId) !== null && _payload$branch$entit !== void 0 ? _payload$branch$entit : null);
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
const refreshSession = () => {
|
|
43
|
+
if (!refreshPromise) {
|
|
44
|
+
refreshPromise = sessionClient('api/v1/auth', {
|
|
45
|
+
method: 'PUT'
|
|
46
|
+
}).then(response => {
|
|
47
|
+
syncRuntimeSession((response === null || response === void 0 ? void 0 : response.data) || {});
|
|
48
|
+
return response;
|
|
49
|
+
}).finally(() => {
|
|
50
|
+
refreshPromise = null;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return refreshPromise;
|
|
54
|
+
};
|
|
55
|
+
const resyncSession = async () => {
|
|
56
|
+
const response = await sessionClient('api/v1/auth/session', {
|
|
57
|
+
method: 'GET'
|
|
58
|
+
});
|
|
59
|
+
syncRuntimeSession((response === null || response === void 0 ? void 0 : response.data) || {});
|
|
60
|
+
return response;
|
|
61
|
+
};
|
|
31
62
|
const attachSessionHeaders = function attachSessionHeaders() {
|
|
32
63
|
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
33
64
|
config.headers = config.headers || {};
|
|
@@ -60,18 +91,15 @@ authenticatedClient.interceptors.response.use(response => response, async error
|
|
|
60
91
|
return Promise.reject(error);
|
|
61
92
|
}
|
|
62
93
|
originalRequest._retry = true;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
refreshPromise = null;
|
|
72
|
-
});
|
|
94
|
+
try {
|
|
95
|
+
await refreshSession();
|
|
96
|
+
} catch (refreshError) {
|
|
97
|
+
var _sessionResponse$data;
|
|
98
|
+
const sessionResponse = await resyncSession().catch(() => null);
|
|
99
|
+
if (!(sessionResponse !== null && sessionResponse !== void 0 && (_sessionResponse$data = sessionResponse.data) !== null && _sessionResponse$data !== void 0 && _sessionResponse$data.authenticated)) {
|
|
100
|
+
return Promise.reject(refreshError);
|
|
101
|
+
}
|
|
73
102
|
}
|
|
74
|
-
await refreshPromise;
|
|
75
103
|
return authenticatedClient(originalRequest);
|
|
76
104
|
});
|
|
77
105
|
const authenticatedProxyApi = exports.authenticatedProxyApi = {
|
|
@@ -99,9 +127,7 @@ const authenticatedProxyApi = exports.authenticatedProxyApi = {
|
|
|
99
127
|
getCountries: () => authenticatedClient("api/v1/countries", {
|
|
100
128
|
method: 'GET'
|
|
101
129
|
}),
|
|
102
|
-
putRefreshToken: () =>
|
|
103
|
-
method: 'PUT'
|
|
104
|
-
}),
|
|
130
|
+
putRefreshToken: () => refreshSession(),
|
|
105
131
|
getArticleGroups: articleTypeId => authenticatedClient("api/v1/articles/groups/".concat(articleTypeId), {
|
|
106
132
|
method: 'GET'
|
|
107
133
|
}),
|
|
@@ -479,8 +479,9 @@ const useOrderDataQuery = exports.useOrderDataQuery = function useOrderDataQuery
|
|
|
479
479
|
} = (0, _AuthSessionContext.useAuthSession)();
|
|
480
480
|
const orderQueryKey = (0, _queryKeyFactory.getOrderQueryKey)(normalizedOrderParams);
|
|
481
481
|
const serializedOrderParams = (0, _queryKeyFactory.serializeOrderParams)(normalizedOrderParams);
|
|
482
|
+
const hasOrderInput = (licensePlate === null || licensePlate === void 0 ? void 0 : licensePlate.length) > 5 || !!(model !== null && model !== void 0 && model.length);
|
|
482
483
|
const orderQuery = (0, _reactQuery.useQuery)(orderQueryKey, {
|
|
483
|
-
enabled:
|
|
484
|
+
enabled: hasOrderInput && (!APP_CONFIG.internal || initialized),
|
|
484
485
|
keepPreviousData: true,
|
|
485
486
|
queryFn: async () => {
|
|
486
487
|
var _response$data;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useSessionContextReady = void 0;
|
|
8
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _AuthRuntime = require("../__services__/AuthRuntime");
|
|
11
|
+
const useSessionContextReady = () => {
|
|
12
|
+
const [isReady, setIsReady] = (0, _react.useState)(_AuthRuntime.authRuntime.isSessionContextReady());
|
|
13
|
+
(0, _react.useEffect)(() => _AuthRuntime.authRuntime.subscribeSessionContextReady(setIsReady), []);
|
|
14
|
+
return isReady;
|
|
15
|
+
};
|
|
16
|
+
exports.useSessionContextReady = useSessionContextReady;
|