react-ecosistema-unp 1.7.0-pre.4 → 1.7.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.
@@ -1,24 +1,26 @@
1
1
  import { FinSesionService as r } from "../services/FinSesionService.js";
2
2
  import { y as a } from "../../index-BUe3EJDH.js";
3
- import { useState as c, useEffect as m } from "react";
4
- import { j as l } from "../../index-CuHybtft.js";
3
+ import { useState as c, useEffect as l } from "react";
4
+ import { j as m } from "../../index-CuHybtft.js";
5
5
  const p = () => {
6
- const [e, t] = c(null), n = `${window.location.protocol}//${window.location.host}/`;
7
- return m(() => {
6
+ const [e, i] = c(null), s = `${window.location.protocol}//${window.location.host}/`;
7
+ return l(() => {
8
8
  const o = sessionStorage.getItem("user_token");
9
9
  if (o) {
10
- const s = l(o);
11
- t(s);
10
+ const n = m(o);
11
+ i(n);
12
12
  }
13
13
  }, []), { FinSesion: () => {
14
14
  a.promise(
15
- new Promise(async (o, s) => {
15
+ new Promise(async (o, n) => {
16
16
  try {
17
- await r((e == null ? void 0 : e.datos_basicos.username) || "", n), sessionStorage.removeItem("user_token"), setTimeout(() => {
18
- o(!0), window.location.href = n;
17
+ await r((e == null ? void 0 : e.datos_basicos.username) || "", s), o(!0);
18
+ } catch (t) {
19
+ n(t);
20
+ } finally {
21
+ sessionStorage.removeItem("user_token"), setTimeout(() => {
22
+ window.location.href = s;
19
23
  }, 1e3);
20
- } catch (i) {
21
- s(i);
22
24
  }
23
25
  }),
24
26
  {
@@ -2,8 +2,17 @@ import { default as React, ReactNode } from 'react';
2
2
  export type ConnectionStatus = 'connected' | 'connecting' | 'disconnected';
3
3
  interface WebSocketContextType {
4
4
  connectionStatus: ConnectionStatus;
5
+ /**
6
+ * @deprecated función experimental, no se recomienda su uso.
7
+ */
5
8
  connectWebSocket: (url: string) => void;
9
+ /**
10
+ * @deprecated función experimental, no se recomienda su uso.
11
+ */
6
12
  disconnectWebSocket: () => void;
13
+ /**
14
+ * @deprecated función experimental, no se recomienda su uso.
15
+ */
7
16
  sendWebSocketMessage: (data: any) => void;
8
17
  }
9
18
  export declare const WebSocketProvider: React.FC<{
@@ -1,14 +1,14 @@
1
- import { jsx as h } from "react/jsx-runtime";
2
- import { useState as m, useEffect as p } from "react";
3
- import { useNavigate as w, useLocation as u, Outlet as k } from "react-router-dom";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import { useState as h, useEffect as u } from "react";
3
+ import { useNavigate as p, useLocation as w, Outlet as k } from "react-router-dom";
4
4
  import { j as v } from "../../index-CuHybtft.js";
5
- const V = () => {
6
- const [i, e] = m(!1), r = w(), c = u(), o = `${window.location.protocol}//${window.location.host}/`;
7
- return p(() => {
5
+ const $ = () => {
6
+ const [r, t] = h(!1), i = p(), c = w(), e = `${window.location.protocol}//${window.location.host}/`;
7
+ return u(() => {
8
8
  (async () => {
9
9
  try {
10
10
  if ((await fetch(
11
- `${o}api-auth/auth/validate_jwt/`,
11
+ `${e}api-auth/auth/validate_jwt/`,
12
12
  {
13
13
  method: "POST",
14
14
  headers: {
@@ -17,25 +17,24 @@ const V = () => {
17
17
  credentials: "include"
18
18
  }
19
19
  )).ok) {
20
- const n = sessionStorage.getItem("user_token");
21
- if (n) {
22
- const l = v(n).datos_basicos.servicios.map((t) => t.url).filter((t) => !!t), s = c.pathname, d = l.map(
23
- (t) => t.startsWith("/") ? t : `/${t}`
24
- ), f = s.startsWith("/") ? s : `/${s}`;
25
- d.some(
26
- (t) => f.startsWith(t)
27
- ) ? e(!0) : (e(!1), window.location.href = o);
20
+ const a = sessionStorage.getItem("user_token");
21
+ if (a) {
22
+ const l = v(a).datos_basicos.servicios.map((o) => o.url).filter((o) => !!o), s = c.pathname, m = l.map(
23
+ (o) => o.startsWith("/") ? o : `/${o}`
24
+ ), d = s.startsWith("/") ? s : `/${s}`;
25
+ m.some(
26
+ (o) => d.startsWith(o)
27
+ ) ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = e);
28
28
  } else
29
- e(!1), window.location.href = o;
29
+ t(!1), sessionStorage.removeItem("user_token"), window.location.href = e;
30
30
  } else
31
- window.location.href = o;
32
- } catch (a) {
33
- console.error("Validation error:", a), window.location.href = o;
34
- } finally {
31
+ sessionStorage.removeItem("user_token"), window.location.href = e;
32
+ } catch (n) {
33
+ console.error("Validation error:", n), sessionStorage.removeItem("user_token"), window.location.href = e;
35
34
  }
36
35
  })();
37
- }, [r]), i ? /* @__PURE__ */ h(k, {}) : null;
36
+ }, [i]), r ? /* @__PURE__ */ f(k, {}) : null;
38
37
  };
39
38
  export {
40
- V as ProtectedRoute
39
+ $ as ProtectedRoute
41
40
  };
@@ -1,13 +1,13 @@
1
- import { jsx as a } from "react/jsx-runtime";
2
- import { useState as i, useEffect as s } from "react";
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { useState as a, useEffect as i } from "react";
3
3
  import { useNavigate as l, Outlet as c } from "react-router-dom";
4
- const h = () => {
5
- const [e, n] = i(!1), r = l(), o = `${window.location.protocol}//${window.location.host}/`;
6
- return s(() => {
4
+ const f = () => {
5
+ const [t, r] = a(!1), n = l(), e = `${window.location.protocol}//${window.location.host}/`;
6
+ return i(() => {
7
7
  (async () => {
8
8
  try {
9
9
  if ((await fetch(
10
- `${o}/auth/validate/`,
10
+ `${e}api-auth/auth/validate_jwt/`,
11
11
  {
12
12
  method: "POST",
13
13
  headers: {
@@ -16,16 +16,15 @@ const h = () => {
16
16
  credentials: "include"
17
17
  }
18
18
  )).ok)
19
- n(!0);
19
+ r(!0);
20
20
  else
21
- return window.location.href = o;
22
- } catch (t) {
23
- return console.error("Validation error:", t), window.location.href = o;
24
- } finally {
21
+ return sessionStorage.removeItem("user_token"), window.location.href = e;
22
+ } catch (o) {
23
+ return console.error("Validation error:", o), sessionStorage.removeItem("user_token"), window.location.href = e;
25
24
  }
26
25
  })();
27
- }, [r]), e ? /* @__PURE__ */ a(c, {}) : null;
26
+ }, [n]), t ? /* @__PURE__ */ s(c, {}) : null;
28
27
  };
29
28
  export {
30
- h as UserRoute
29
+ f as UserRoute
31
30
  };
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.0-pre.4",
5
+ "version": "1.7.0-pre.7",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {