react-ecosistema-unp 1.7.8 → 1.7.9-pre.2

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.
@@ -0,0 +1,7 @@
1
+ declare global {
2
+ interface Window {
3
+ originalFetch: typeof fetch;
4
+ }
5
+ }
6
+ declare const _default: {};
7
+ export default _default;
@@ -0,0 +1,56 @@
1
+ window.originalFetch = window.fetch.bind(window);
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, {
6
+ method: "POST",
7
+ credentials: "include"
8
+ });
9
+ if (!t.ok)
10
+ throw new Error("Error al refrescar token, status " + t.status);
11
+ return "Token refreshed";
12
+ }
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/"))
16
+ return window.originalFetch(o, e);
17
+ e = e || {};
18
+ const u = sessionStorage.getItem("user_token");
19
+ e.headers = {
20
+ ...e.headers,
21
+ ...u ? { Authorization: u } : {}
22
+ };
23
+ 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"))
30
+ return sessionStorage.removeItem("user_token"), setTimeout(() => {
31
+ window.location.href = a;
32
+ }, 1e3), r;
33
+ }
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 }) => {
37
+ const g = {
38
+ ...s,
39
+ headers: { ...s.headers, Authorization: sessionStorage.getItem("user_token") }
40
+ };
41
+ window.originalFetch(c, g).then(d).catch(f);
42
+ });
43
+ }).catch((c) => {
44
+ i.forEach(({ reject: s }) => s(c));
45
+ }).finally(() => {
46
+ i.length = 0, l = !1, h = null;
47
+ }));
48
+ });
49
+ } catch (a) {
50
+ return Promise.reject(a);
51
+ }
52
+ };
53
+ const k = {};
54
+ export {
55
+ k as default
56
+ };
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.8",
5
+ "version": "1.7.9-pre.2",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
@@ -36,7 +36,9 @@
36
36
  "./data": {
37
37
  "types": "./dist/lib/data.d.ts",
38
38
  "default": "./dist/data.js"
39
- }
39
+ },
40
+ "./styles/Bootstrap.css": "./dist/EcoStyles.css",
41
+ "./utils/fetch-interceptor/fetchInterceptor.ts": "./dist/fetchInterceptor.ts"
40
42
  },
41
43
  "files": [
42
44
  "dist"