react-ecosistema-unp 1.7.13 → 1.7.14

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.
@@ -1,17 +1,18 @@
1
1
  window.originalFetch = window.fetch.bind(window);
2
2
  let l = !1, h = null;
3
- const s = [];
3
+ const c = [];
4
4
  async function k() {
5
- const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, i = await window.originalFetch(e, {
5
+ const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, t = await window.originalFetch(e, {
6
6
  method: "POST",
7
7
  credentials: "include"
8
8
  });
9
- if (!i.ok)
10
- throw new Error("Error al refrescar token, status " + i.status);
11
- return "Token refreshed";
9
+ if (!t.ok)
10
+ throw new Error("Error al refrescar token, status " + t.status);
11
+ return console.warn("Token refrescado"), "Token refreshed";
12
12
  }
13
13
  window.fetch = async function(o, e) {
14
- if ((typeof o == "string" ? o : o.toString()).includes("/api-auth/"))
14
+ const t = typeof o == "string" ? o : o.toString();
15
+ if (console.log("Petición fetchInterceptor Librería:", t), t.includes("/api-auth/"))
15
16
  return window.originalFetch(o, e);
16
17
  e = e || {};
17
18
  const u = sessionStorage.getItem("user_token");
@@ -20,33 +21,33 @@ window.fetch = async function(o, e) {
20
21
  ...u ? { Authorization: u } : {}
21
22
  };
22
23
  try {
23
- const a = `${window.location.protocol}//${window.location.host}/`, t = await window.originalFetch(o, e);
24
- if (t.status !== 401) {
25
- const r = await t.clone().text();
26
- if (!r.includes("Signature has expired"))
27
- return t;
28
- if (r.includes("Invalid or expired token"))
29
- return sessionStorage.removeItem("user_token"), setTimeout(() => {
30
- window.location.href = a;
31
- }, 1e3), t;
24
+ const i = `${window.location.protocol}//${window.location.host}/`, r = await window.originalFetch(o, e);
25
+ if (r.status !== 401) {
26
+ const n = await r.clone().text();
27
+ if (!n.includes("Signature has expired"))
28
+ return r;
29
+ if (n.includes("Invalid or expired token"))
30
+ return console.warn("El token expiró"), sessionStorage.removeItem("user_token"), setTimeout(() => {
31
+ window.location.href = i;
32
+ }, 1e3), r;
32
33
  }
33
- return new Promise((w, r) => {
34
- s.push({ input: o, init: e, resolve: w, reject: r }), l || (l = !0, h = k(), h.then(() => {
35
- s.forEach(({ input: c, init: n, resolve: d, reject: f }) => {
34
+ return new Promise((w, n) => {
35
+ c.push({ input: o, init: e, resolve: w, reject: n }), l || (l = !0, h = k(), h.then(() => {
36
+ c.forEach(({ input: a, init: s, resolve: d, reject: f }) => {
36
37
  const g = {
37
- ...n,
38
- headers: { ...n.headers, Authorization: sessionStorage.getItem("user_token") }
38
+ ...s,
39
+ headers: { ...s.headers, Authorization: sessionStorage.getItem("user_token") }
39
40
  };
40
- window.originalFetch(c, g).then(d).catch(f);
41
+ window.originalFetch(a, g).then(d).catch(f);
41
42
  });
42
- }).catch((c) => {
43
- s.forEach(({ reject: n }) => n(c));
43
+ }).catch((a) => {
44
+ c.forEach(({ reject: s }) => s(a));
44
45
  }).finally(() => {
45
- s.length = 0, l = !1, h = null;
46
+ c.length = 0, l = !1, h = null;
46
47
  }));
47
48
  });
48
- } catch (a) {
49
- return Promise.reject(a);
49
+ } catch (i) {
50
+ return Promise.reject(i);
50
51
  }
51
52
  };
52
53
  const p = {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-ecosistema-unp",
3
3
  "author": "Ecosistema de Información - Unidad Nacional de Protección",
4
4
  "private": false,
5
- "version": "1.7.13",
5
+ "version": "1.7.14",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {