react-ecosistema-unp 1.3.0-pre-release.5 → 1.3.0-pre-release.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.
@@ -1,16 +1,16 @@
1
1
  import { jsx as m } from "react/jsx-runtime";
2
2
  import { useState as p, useEffect as h } from "react";
3
- import { useNavigate as k, useLocation as T, Outlet as v } from "react-router-dom";
4
- import { urlAuthDev as A, urlAuthTest as U, urlAuthProd as g, urlAuthLocal as j } from "../Url.js";
5
- import { j as y } from "../../index-CuHybtft.js";
6
- const D = ({ server: o }) => {
7
- const [l, s] = p(!1), t = k(), c = T();
8
- let e;
9
- return o === "dev" ? e = A : o === "test" ? e = U : o === "prod" ? e = g : e = j, h(() => {
3
+ import { useNavigate as w, useLocation as k, Outlet as T } from "react-router-dom";
4
+ import { urlAuthDev as v, urlAuthTest as A, urlAuthProd as U, urlAuthLocal as g } from "../Url.js";
5
+ import { j } from "../../index-CuHybtft.js";
6
+ const D = ({ server: e }) => {
7
+ const [l, s] = p(!1), t = w(), c = k();
8
+ let o;
9
+ return e === "dev" ? o = v : e === "test" ? o = A : e === "prod" ? o = U : o = g, h(() => {
10
10
  (async () => {
11
11
  try {
12
12
  if ((await fetch(
13
- `${e}/auth/validate/`,
13
+ `${o}/auth/validate/`,
14
14
  {
15
15
  method: "POST",
16
16
  headers: {
@@ -21,23 +21,20 @@ const D = ({ server: o }) => {
21
21
  )).ok) {
22
22
  const i = sessionStorage.getItem("user_token");
23
23
  if (i) {
24
- const u = y(i).datos_basicos.rutas, r = c.pathname, d = u.map(
25
- (a) => a.startsWith("/") ? a : `/${a}`
26
- ), f = r.startsWith("/") ? r : `/${r}`;
27
- if (d.includes(f))
28
- s(!0);
29
- else
30
- return s(!1), t("/");
24
+ const d = j(i).datos_basicos.rutas, a = c.pathname, u = d.map(
25
+ (n) => n.startsWith("/") ? n : `/${n}`
26
+ ), f = a.startsWith("/") ? a : `/${a}`;
27
+ u.includes(f) ? s(!0) : (s(!1), t("/"), window.location.reload());
31
28
  } else
32
- return s(!1), t("/");
29
+ s(!1), t("/"), window.location.reload();
33
30
  } else
34
- return t("/");
35
- } catch (n) {
36
- return console.error("Validation error:", n), t("/");
31
+ t("/"), window.location.reload();
32
+ } catch (r) {
33
+ console.error("Validation error:", r), t("/"), window.location.reload();
37
34
  } finally {
38
35
  }
39
36
  })();
40
- }, [t]), l ? /* @__PURE__ */ m(v, {}) : null;
37
+ }, [t]), l ? /* @__PURE__ */ m(T, {}) : null;
41
38
  };
42
39
  export {
43
40
  D as ProtectedRoute
@@ -1,39 +1,46 @@
1
- import { jsx as p } from "react/jsx-runtime";
2
- import { useRef as l, useCallback as x, useEffect as W } from "react";
1
+ import { jsx as W } from "react/jsx-runtime";
2
+ import { useRef as i, useEffect as x } from "react";
3
3
  import { L as k } from "../../index-Cs6Q8pv4.js";
4
- import { useWebSocketContext as N } from "./WebSocketProvider.js";
4
+ import { useWebSocketContext as C } from "./WebSocketProvider.js";
5
5
  import '../../assets/WebSocketManager.css';const z = ({
6
- urlWs: u,
7
- handlers: i,
8
- socketKey: o,
9
- autoReconnect: f = !0,
10
- maxReconnectAttempts: g = 5
6
+ urlWs: f,
7
+ handlers: m,
8
+ socketKey: e,
9
+ autoReconnect: d = !0,
10
+ maxReconnectAttempts: S = 5
11
11
  }) => {
12
- const e = l(null), c = l(0), { setSocket: S, setStatus: t, removeSocket: m } = N(), s = l(!1), a = x(() => {
13
- e.current && e.current.close(), console.log(`Conectando WebSocket: ${o}`), t(o, "connecting"), e.current = new WebSocket(u), e.current.onopen = () => {
14
- console.log("WebSocket conectado."), c.current = 0, s.current = !0, S(o, e.current), t(o, "connected");
15
- }, e.current.onmessage = (r) => {
16
- console.log("Mensaje recibido:", r.data);
17
- try {
18
- const n = JSON.parse(r.data), d = i.find((b) => b.message === n.message);
19
- d ? d.action(n) : console.warn("No se encontró handler para el mensaje:", n.message);
20
- } catch (n) {
21
- console.error("Error procesando mensaje:", n);
22
- }
23
- }, e.current.onclose = () => {
24
- if (console.log("WebSocket cerrado."), t(o, "disconnected"), m(o), f && c.current < g && s.current) {
25
- const r = Math.min(3e4, 1e3 * 2 ** c.current);
26
- console.log(`Reintentando conexión en ${r / 1e3}s...`), setTimeout(() => {
27
- c.current += 1, a();
28
- }, r);
29
- } else s.current ? console.error("No se realizará más reconexiones. Máximo alcanzado.") : console.error("Nunca se logró conectar. No se realizarán reconexiones.");
30
- }, e.current.onerror = (r) => {
31
- console.error("Error en WebSocket:", r), t(o, "error");
12
+ const r = i(null), a = i(0), u = i(!1), { setSocket: g, setStatus: t, removeSocket: l } = C();
13
+ return x(() => {
14
+ let c = !1;
15
+ const b = () => {
16
+ r.current && (r.current.readyState === WebSocket.OPEN || r.current.readyState === WebSocket.CONNECTING) && r.current.close(), console.log(`Conectando WebSocket: ${e}`), t(e, "connecting");
17
+ const o = new WebSocket(f);
18
+ r.current = o, o.onopen = () => {
19
+ c || (console.log("WebSocket conectado."), a.current = 0, u.current = !0, g(e, o), t(e, "connected"));
20
+ }, o.onmessage = (n) => {
21
+ if (!c)
22
+ try {
23
+ const s = JSON.parse(n.data), p = m.find((N) => N.message === s.message);
24
+ p ? p.action(s) : console.warn("No se encontró handler para el mensaje:", s.message);
25
+ } catch (s) {
26
+ console.error("Error procesando mensaje:", s);
27
+ }
28
+ }, o.onerror = (n) => {
29
+ c || (console.error("Error en WebSocket:", n), t(e, "error"));
30
+ }, o.onclose = () => {
31
+ if (!c)
32
+ if (console.log("WebSocket cerrado."), t(e, "disconnected"), l(e), d && a.current < S && u.current) {
33
+ const n = Math.min(3e4, 1e3 * 2 ** a.current);
34
+ console.log(`Reintentando conexión en ${n / 1e3}s...`), setTimeout(() => {
35
+ a.current += 1, b();
36
+ }, n);
37
+ } else u.current ? console.error("No se realizará más reconexiones. Máximo alcanzado.") : console.error("Nunca se logró conectar. No se realizarán reconexiones.");
38
+ };
32
39
  };
33
- }, [u, i]);
34
- return W(() => (a(), () => {
35
- e.current && (e.current.close(), m(o));
36
- }), [a]), /* @__PURE__ */ p(k, {});
40
+ return b(), () => {
41
+ c = !0, r.current && (r.current.close(), l(e));
42
+ };
43
+ }, [f, m, e, d, S, g, t, l]), /* @__PURE__ */ W(k, {});
37
44
  };
38
45
  export {
39
46
  z as WebSocketManager
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.3.0-pre-release.5",
5
+ "version": "1.3.0-pre-release.7",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {