react-ecosistema-unp 1.7.9-pre.3 → 1.7.9-pre.5

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,18 +1,17 @@
1
1
  window.originalFetch = window.fetch.bind(window);
2
2
  let l = !1, h = null;
3
- const i = [];
4
- async function p() {
5
- const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, t = await window.originalFetch(e, {
3
+ const s = [];
4
+ async function k() {
5
+ const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, i = await window.originalFetch(e, {
6
6
  method: "POST",
7
7
  credentials: "include"
8
8
  });
9
- if (!t.ok)
10
- throw new Error("Error al refrescar token, status " + t.status);
9
+ if (!i.ok)
10
+ throw new Error("Error al refrescar token, status " + i.status);
11
11
  return "Token refreshed";
12
12
  }
13
13
  window.fetch = async function(o, e) {
14
- const t = typeof o == "string" ? o : o.toString();
15
- if (console.log("URL petición librería:", t), t.includes("/api-auth/"))
14
+ if ((typeof o == "string" ? o : o.toString()).includes("/api-auth/"))
16
15
  return window.originalFetch(o, e);
17
16
  e = e || {};
18
17
  const u = sessionStorage.getItem("user_token");
@@ -21,36 +20,36 @@ window.fetch = async function(o, e) {
21
20
  ...u ? { Authorization: u } : {}
22
21
  };
23
22
  try {
24
- const a = `${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"))
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"))
30
29
  return sessionStorage.removeItem("user_token"), setTimeout(() => {
31
30
  window.location.href = a;
32
- }, 1e3), r;
31
+ }, 1e3), t;
33
32
  }
34
- return new Promise((w, n) => {
35
- i.push({ input: o, init: e, resolve: w, reject: n }), l || (l = !0, h = p(), h.then(() => {
36
- i.forEach(({ input: c, init: s, resolve: d, reject: f }) => {
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 }) => {
37
36
  const g = {
38
- ...s,
39
- headers: { ...s.headers, Authorization: sessionStorage.getItem("user_token") }
37
+ ...n,
38
+ headers: { ...n.headers, Authorization: sessionStorage.getItem("user_token") }
40
39
  };
41
40
  window.originalFetch(c, g).then(d).catch(f);
42
41
  });
43
42
  }).catch((c) => {
44
- i.forEach(({ reject: s }) => s(c));
43
+ s.forEach(({ reject: n }) => n(c));
45
44
  }).finally(() => {
46
- i.length = 0, l = !1, h = null;
45
+ s.length = 0, l = !1, h = null;
47
46
  }));
48
47
  });
49
48
  } catch (a) {
50
49
  return Promise.reject(a);
51
50
  }
52
51
  };
53
- const k = {};
52
+ const p = {};
54
53
  export {
55
- k as default
54
+ p as default
56
55
  };
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.9-pre.3",
5
+ "version": "1.7.9-pre.5",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
@@ -37,7 +37,8 @@
37
37
  "types": "./dist/lib/data.d.ts",
38
38
  "default": "./dist/data.js"
39
39
  },
40
- "./utils/fetch-interceptor/fetchInterceptor.ts": "./dist/utils/fetch-interceptor/fetchInterceptor.ts"
40
+ "./styles/EcoStyles.css": "./dist/assets/Bootstrap.css",
41
+ "./utils/fetchInterceptor.js": "./dist/utils/fetch-interceptor/fetchInterceptor.js"
41
42
  },
42
43
  "files": [
43
44
  "dist"