jclib-ui 1.0.290 → 1.0.292
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/jclib-ui.es.js
CHANGED
|
@@ -4232,6 +4232,7 @@ const initConfig = {
|
|
|
4232
4232
|
version: "",
|
|
4233
4233
|
ident: "",
|
|
4234
4234
|
loginRoute: "/",
|
|
4235
|
+
refreshRoute: "",
|
|
4235
4236
|
isProductionMode: true,
|
|
4236
4237
|
withCredentials: false,
|
|
4237
4238
|
getToken: () => "",
|
|
@@ -5707,6 +5708,33 @@ function MessageNoConection() {
|
|
|
5707
5708
|
] })
|
|
5708
5709
|
] });
|
|
5709
5710
|
}
|
|
5711
|
+
let renovando = null;
|
|
5712
|
+
function ehRotaDeRefresh(config, apiConfig) {
|
|
5713
|
+
const url = String((config == null ? void 0 : config.url) || "");
|
|
5714
|
+
return url === apiConfig.refreshRoute || url.endsWith(apiConfig.refreshRoute);
|
|
5715
|
+
}
|
|
5716
|
+
async function renovarSessao(error, apiConfig, config) {
|
|
5717
|
+
var _a;
|
|
5718
|
+
if (!(apiConfig == null ? void 0 : apiConfig.refreshRoute)) return false;
|
|
5719
|
+
if (((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status) !== 401) return false;
|
|
5720
|
+
if (config == null ? void 0 : config._retry) return false;
|
|
5721
|
+
if (ehRotaDeRefresh(config, apiConfig)) return false;
|
|
5722
|
+
if (!renovando) {
|
|
5723
|
+
renovando = axios.post(apiConfig.refreshRoute, null, {
|
|
5724
|
+
baseURL: apiConfig.baseURL,
|
|
5725
|
+
timeout: apiConfig.timeout,
|
|
5726
|
+
withCredentials: true
|
|
5727
|
+
}).finally(() => {
|
|
5728
|
+
renovando = null;
|
|
5729
|
+
});
|
|
5730
|
+
}
|
|
5731
|
+
try {
|
|
5732
|
+
await renovando;
|
|
5733
|
+
return true;
|
|
5734
|
+
} catch {
|
|
5735
|
+
return false;
|
|
5736
|
+
}
|
|
5737
|
+
}
|
|
5710
5738
|
const initialRequestInfo = {
|
|
5711
5739
|
isError: false,
|
|
5712
5740
|
//deprecated
|
|
@@ -5772,7 +5800,16 @@ function useApi(initialConfig = {}) {
|
|
|
5772
5800
|
finalConfig.onBefore(finalConfig);
|
|
5773
5801
|
}
|
|
5774
5802
|
try {
|
|
5775
|
-
|
|
5803
|
+
let res;
|
|
5804
|
+
try {
|
|
5805
|
+
res = await axios({ ...finalConfig, signal: controller.signal });
|
|
5806
|
+
} catch (err) {
|
|
5807
|
+
if (!await renovarSessao(err, globalApiConfig, finalConfig)) {
|
|
5808
|
+
throw err;
|
|
5809
|
+
}
|
|
5810
|
+
finalConfig._retry = true;
|
|
5811
|
+
res = await axios({ ...finalConfig, signal: controller.signal });
|
|
5812
|
+
}
|
|
5776
5813
|
if (globalApiConfig.afterRequest) {
|
|
5777
5814
|
globalApiConfig.afterRequest(res);
|
|
5778
5815
|
}
|
|
@@ -5813,8 +5850,8 @@ function useApi(initialConfig = {}) {
|
|
|
5813
5850
|
}
|
|
5814
5851
|
case 401: {
|
|
5815
5852
|
response.message = "Servidor requer autenticação!";
|
|
5816
|
-
if (globalApiConfig.setToken) {
|
|
5817
|
-
globalApiConfig.setToken("");
|
|
5853
|
+
if (globalApiConfig == null ? void 0 : globalApiConfig.setToken) {
|
|
5854
|
+
globalApiConfig == null ? void 0 : globalApiConfig.setToken("");
|
|
5818
5855
|
}
|
|
5819
5856
|
history.push(globalApiConfig.loginRoute);
|
|
5820
5857
|
break;
|