react-ecosistema-unp 1.6.0-pre.5 → 1.6.0-pre.7

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.
@@ -2,22 +2,21 @@ window.originalFetch = window.fetch.bind(window);
2
2
  let c = !1, h = null;
3
3
  const s = [];
4
4
  async function k() {
5
- const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, o = await window.originalFetch(e, {
5
+ const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, r = await window.originalFetch(e, {
6
6
  method: "POST",
7
7
  credentials: "include"
8
8
  });
9
- if (!o.ok)
10
- throw new Error("Error al refrescar token, status " + o.status);
11
- const n = await o.json();
9
+ if (!r.ok)
10
+ throw new Error("Error al refrescar token, status " + r.status);
11
+ const n = await r.json();
12
12
  if (!n.token)
13
13
  throw new Error("No se recibió token en la respuesta de refresh");
14
- const t = n.token;
15
- return sessionStorage.setItem("user_token", `Bearer ${t}`), `Bearer ${t}`;
14
+ return `${n.token}`;
16
15
  }
17
- window.fetch = async function(r, e) {
18
- const o = typeof r == "string" ? r : r.toString();
19
- if (o.includes("/auth/refresh_token") || o.includes("/auth/validate"))
20
- return window.originalFetch(r, e);
16
+ window.fetch = async function(t, e) {
17
+ const r = typeof t == "string" ? t : t.toString();
18
+ if (r.includes("/auth/refresh_token") || r.includes("/auth/validate"))
19
+ return window.originalFetch(t, e);
21
20
  e = e || {};
22
21
  const n = sessionStorage.getItem("user_token");
23
22
  e.headers = {
@@ -25,13 +24,13 @@ window.fetch = async function(r, e) {
25
24
  ...n ? { Authorization: n } : {}
26
25
  };
27
26
  try {
28
- const t = await window.originalFetch(r, e);
29
- return t.status !== 401 && !(await t.text()).includes("Signature has expired") ? t : new Promise((u, w) => {
30
- s.push({ input: r, init: e, resolve: u, reject: w }), c || (c = !0, h = k(), h.then((a) => {
31
- s.forEach(({ input: i, init: l, resolve: d, reject: f }) => {
27
+ const o = await window.originalFetch(t, e);
28
+ return o.status !== 401 && !(await o.text()).includes("Signature has expired") ? o : new Promise((l, w) => {
29
+ s.push({ input: t, init: e, resolve: l, reject: w }), c || (c = !0, h = k(), h.then((a) => {
30
+ s.forEach(({ input: i, init: u, resolve: d, reject: f }) => {
32
31
  const g = {
33
- ...l,
34
- headers: { ...l.headers, Authorization: a }
32
+ ...u,
33
+ headers: { ...u.headers, Authorization: a }
35
34
  };
36
35
  window.originalFetch(i, g).then(d).catch(f);
37
36
  });
@@ -41,7 +40,7 @@ window.fetch = async function(r, e) {
41
40
  s.length = 0, c = !1, h = null;
42
41
  }));
43
42
  });
44
- } catch (t) {
45
- return Promise.reject(t);
43
+ } catch (o) {
44
+ return Promise.reject(o);
46
45
  }
47
46
  };
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.6.0-pre.5",
5
+ "version": "1.6.0-pre.7",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {