react-ecosistema-unp 1.8.0-pre.7 → 1.8.0-pre.8
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.
- package/dist/auth/hooks/useFinalizarSesion.js +5 -34
- package/dist/shared/app-list/AppList.js +10 -11
- package/dist/shared/iconos-sistema/logout-button/LogoutButton.js +3 -3
- package/dist/shared/menu-lateral/MenuLateral.js +3 -4
- package/dist/useFinalizarSesion-DXrrb8G5.js +84 -0
- package/dist/utils/components/ProtectedRoute.js +30 -35
- package/dist/utils/eco-provider/EcoContext.js +2 -3
- package/package.json +1 -1
- package/dist/index-CuHybtft.js +0 -51
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
const d = () => {
|
|
6
|
-
const [o, r] = c(null), n = `${window.location.protocol}//${window.location.host}/`;
|
|
7
|
-
return l(() => {
|
|
8
|
-
const e = localStorage.getItem("access_token");
|
|
9
|
-
if (e) {
|
|
10
|
-
const t = m(e);
|
|
11
|
-
r(t);
|
|
12
|
-
}
|
|
13
|
-
}, []), { FinSesion: () => {
|
|
14
|
-
a.promise(
|
|
15
|
-
new Promise(async (e, t) => {
|
|
16
|
-
try {
|
|
17
|
-
await i((o == null ? void 0 : o.user.username) || "", n), e(!0);
|
|
18
|
-
} catch (s) {
|
|
19
|
-
t(s);
|
|
20
|
-
} finally {
|
|
21
|
-
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), setTimeout(() => {
|
|
22
|
-
window.location.href = n;
|
|
23
|
-
}, 1e3);
|
|
24
|
-
}
|
|
25
|
-
}),
|
|
26
|
-
{
|
|
27
|
-
pending: "Finalizando sesión...",
|
|
28
|
-
success: "Sesión finalizada con éxito",
|
|
29
|
-
error: "Error al finalizar la sesión"
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
} };
|
|
33
|
-
};
|
|
1
|
+
import "../services/FinSesionService.js";
|
|
2
|
+
import "../../index-BUe3EJDH.js";
|
|
3
|
+
import "react";
|
|
4
|
+
import { u as t } from "../../useFinalizarSesion-DXrrb8G5.js";
|
|
34
5
|
export {
|
|
35
|
-
|
|
6
|
+
t as useFinalizarSesion
|
|
36
7
|
};
|
|
@@ -3,30 +3,29 @@ import { useState as d, useEffect as h } from "react";
|
|
|
3
3
|
import { F as n, f as u, g as f, h as v, i as z } from "../../index-D3WseyJh.js";
|
|
4
4
|
import { z as N } from "../../index-DDjnZyBf.js";
|
|
5
5
|
import { G as g } from "../../iconBase-LROS5hdG.js";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import '../../assets/AppList.css';function b(s) {
|
|
6
|
+
import { N as w } from "../../NavDropdown-ei8eIwIE.js";
|
|
7
|
+
import '../../assets/AppList.css';function U(s) {
|
|
9
8
|
return g({ tag: "svg", attr: { fill: "currentColor", viewBox: "0 0 16 16" }, child: [{ tag: "path", attr: { d: "M1 2a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1zM1 7a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1zM1 12a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1z" }, child: [] }] })(s);
|
|
10
9
|
}
|
|
11
|
-
const
|
|
10
|
+
const b = {
|
|
12
11
|
Usuario: /* @__PURE__ */ o(n, { size: 24, className: "icon-app-2" }),
|
|
13
12
|
"Asesor(a) poblacional": /* @__PURE__ */ o(u, { size: 24, className: "icon-app-2" }),
|
|
14
13
|
Radicador: /* @__PURE__ */ o(f, { size: 24, className: "icon-app-2" }),
|
|
15
14
|
"Reparto poblacional": /* @__PURE__ */ o(v, { size: 24, className: "icon-app-2" }),
|
|
16
15
|
Digitador: /* @__PURE__ */ o(z, { size: 24, className: "icon-app-2" })
|
|
17
|
-
},
|
|
16
|
+
}, F = {
|
|
18
17
|
Usuario: "Mi perfil",
|
|
19
18
|
"Asesor(a) poblacional": "Asesoría",
|
|
20
19
|
Radicador: "Radicación",
|
|
21
20
|
"Reparto poblacional": "Reparto",
|
|
22
21
|
Digitador: "Digitación"
|
|
23
|
-
},
|
|
22
|
+
}, M = () => {
|
|
24
23
|
const [s, l] = d([]), e = location.pathname, c = e.startsWith("/") ? e : `/${e}`;
|
|
25
24
|
h(() => {
|
|
26
25
|
const a = localStorage.getItem("auth_state");
|
|
27
26
|
if (a)
|
|
28
27
|
try {
|
|
29
|
-
const i =
|
|
28
|
+
const i = JSON.parse(a);
|
|
30
29
|
l(i.user.servicios);
|
|
31
30
|
} catch (i) {
|
|
32
31
|
console.error("Error al decodificar el token:", i);
|
|
@@ -37,16 +36,16 @@ const F = {
|
|
|
37
36
|
window.location.href = i;
|
|
38
37
|
};
|
|
39
38
|
return /* @__PURE__ */ o(
|
|
40
|
-
|
|
39
|
+
w,
|
|
41
40
|
{
|
|
42
|
-
title: /* @__PURE__ */ o(
|
|
41
|
+
title: /* @__PURE__ */ o(U, { className: "icono-app" }),
|
|
43
42
|
align: "end",
|
|
44
43
|
children: /* @__PURE__ */ o("div", { style: {
|
|
45
44
|
fontWeight: "400",
|
|
46
45
|
padding: "1rem"
|
|
47
46
|
}, children: /* @__PURE__ */ r("div", { className: "grid-container", children: [
|
|
48
47
|
s.filter((a) => !(a.url === "unp/ecosistema/usuario" && a.rol === "Usuario")).map(({ rol: a, url: i }) => {
|
|
49
|
-
const p =
|
|
48
|
+
const p = b[a] || /* @__PURE__ */ o(N, { size: 24, className: "icon-app-2" }), m = F[a] || a;
|
|
50
49
|
return /* @__PURE__ */ r(
|
|
51
50
|
"div",
|
|
52
51
|
{
|
|
@@ -77,5 +76,5 @@ const F = {
|
|
|
77
76
|
);
|
|
78
77
|
};
|
|
79
78
|
export {
|
|
80
|
-
|
|
79
|
+
M as AppList
|
|
81
80
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { u as t } from "../../../useFinalizarSesion-DXrrb8G5.js";
|
|
3
3
|
import { y as i } from "../../../index-DDjnZyBf.js";
|
|
4
|
-
import '../../../assets/LogoutButton.css';const
|
|
4
|
+
import '../../../assets/LogoutButton.css';const m = () => {
|
|
5
5
|
const { FinSesion: o } = t();
|
|
6
6
|
return /* @__PURE__ */ r(i, { className: "icono-logout", onClick: o });
|
|
7
7
|
};
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
m as LogoutButton
|
|
10
10
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { jsx as a, Fragment as g, jsxs as e } from "react/jsx-runtime";
|
|
2
2
|
import { useState as o, useEffect as d } from "react";
|
|
3
3
|
import { useNavigate as H } from "react-router-dom";
|
|
4
|
-
import { j as u } from "../../
|
|
5
|
-
import { useFinalizarSesion as C } from "../../auth/hooks/useFinalizarSesion.js";
|
|
4
|
+
import { u as C, j as u } from "../../useFinalizarSesion-DXrrb8G5.js";
|
|
6
5
|
import { urlBase as L, urlCertificadoLaboral as S } from "../../utils/Url.js";
|
|
7
6
|
import "../../auth/contexts/AuthContex.js";
|
|
8
7
|
import '../../assets/EcoModalStyles.css';import '../../assets/Modal.css';import '../../assets/ContenedorVentana.css';import '../../assets/IconoTooltip.css';import '../../assets/ItemsModal.css';import '../../assets/Paginador.css';import '../../assets/ContenidoModal.css';import '../../assets/Encabezado.css';import '../../assets/SeccionTarjetaLectura.css';import '../../assets/Logo.css';import '../../assets/TarjetaLectura.css';import '../../assets/ContenedorTarjeta.css';import '../../assets/Bootstrap.css';import '../../assets/Tarjeta.css';import '../../assets/UnpHistorico.css';import '../../assets/MenuLateral.css';/* empty css */
|
|
@@ -68,7 +67,7 @@ function G(t) {
|
|
|
68
67
|
function W(t) {
|
|
69
68
|
return i({ tag: "svg", attr: { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, child: [{ tag: "path", attr: { d: "M17.8 19.2 16 11l3.5-3.5C21 6 21.5 4 21 3c-1-.5-3 0-4.5 1.5L13 8 4.8 6.2c-.5-.1-.9.1-1.1.5l-.3.5c-.2.5-.1 1 .3 1.3L9 12l-2 3H4l-1 1 3 2 2 3 1-1v-3l3-2 3.5 5.3c.3.4.8.5 1.3.3l.5-.2c.4-.3.6-.7.5-1.2z" }, child: [] }] })(t);
|
|
70
69
|
}
|
|
71
|
-
const
|
|
70
|
+
const b1 = ({ onToggle: t, isOpen: c, showConnectionStatus: x }) => {
|
|
72
71
|
const [N, f] = o(!0), [m, p] = o(null), k = c ? "sidebar-bar-panel open" : "sidebar-bar-panel", w = H(), { FinSesion: b } = C(), { connectionStatus: v } = A(), [z, l] = o(!1), [M, n] = o(""), h = `${window.location.host}`;
|
|
73
72
|
if (d(() => {
|
|
74
73
|
const r = localStorage.getItem("access_token");
|
|
@@ -305,5 +304,5 @@ const z1 = ({ onToggle: t, isOpen: c, showConnectionStatus: x }) => {
|
|
|
305
304
|
] }) });
|
|
306
305
|
};
|
|
307
306
|
export {
|
|
308
|
-
|
|
307
|
+
b1 as MenuLateral
|
|
309
308
|
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { FinSesionService as c } from "./auth/services/FinSesionService.js";
|
|
2
|
+
import { y as l } from "./index-BUe3EJDH.js";
|
|
3
|
+
import { useState as d, useEffect as u } from "react";
|
|
4
|
+
class s extends Error {
|
|
5
|
+
}
|
|
6
|
+
s.prototype.name = "InvalidTokenError";
|
|
7
|
+
function p(t) {
|
|
8
|
+
return decodeURIComponent(atob(t).replace(/(.)/g, (e, r) => {
|
|
9
|
+
let o = r.charCodeAt(0).toString(16).toUpperCase();
|
|
10
|
+
return o.length < 2 && (o = "0" + o), "%" + o;
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
function f(t) {
|
|
14
|
+
let e = t.replace(/-/g, "+").replace(/_/g, "/");
|
|
15
|
+
switch (e.length % 4) {
|
|
16
|
+
case 0:
|
|
17
|
+
break;
|
|
18
|
+
case 2:
|
|
19
|
+
e += "==";
|
|
20
|
+
break;
|
|
21
|
+
case 3:
|
|
22
|
+
e += "=";
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
throw new Error("base64 string is not of the correct length");
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return p(e);
|
|
29
|
+
} catch {
|
|
30
|
+
return atob(e);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function m(t, e) {
|
|
34
|
+
if (typeof t != "string")
|
|
35
|
+
throw new s("Invalid token specified: must be a string");
|
|
36
|
+
e || (e = {});
|
|
37
|
+
const r = e.header === !0 ? 0 : 1, o = t.split(".")[r];
|
|
38
|
+
if (typeof o != "string")
|
|
39
|
+
throw new s(`Invalid token specified: missing part #${r + 1}`);
|
|
40
|
+
let n;
|
|
41
|
+
try {
|
|
42
|
+
n = f(o);
|
|
43
|
+
} catch (a) {
|
|
44
|
+
throw new s(`Invalid token specified: invalid base64 for part #${r + 1} (${a.message})`);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(n);
|
|
48
|
+
} catch (a) {
|
|
49
|
+
throw new s(`Invalid token specified: invalid json for part #${r + 1} (${a.message})`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const k = () => {
|
|
53
|
+
const [t, e] = d(null), r = `${window.location.protocol}//${window.location.host}/`;
|
|
54
|
+
return u(() => {
|
|
55
|
+
const n = localStorage.getItem("access_token");
|
|
56
|
+
if (n) {
|
|
57
|
+
const a = m(n);
|
|
58
|
+
e(a);
|
|
59
|
+
}
|
|
60
|
+
}, []), { FinSesion: () => {
|
|
61
|
+
l.promise(
|
|
62
|
+
new Promise(async (n, a) => {
|
|
63
|
+
try {
|
|
64
|
+
await c((t == null ? void 0 : t.user.username) || "", r), n(!0);
|
|
65
|
+
} catch (i) {
|
|
66
|
+
a(i);
|
|
67
|
+
} finally {
|
|
68
|
+
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), setTimeout(() => {
|
|
69
|
+
window.location.href = r;
|
|
70
|
+
}, 1e3);
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
{
|
|
74
|
+
pending: "Finalizando sesión...",
|
|
75
|
+
success: "Sesión finalizada con éxito",
|
|
76
|
+
error: "Error al finalizar la sesión"
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
} };
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
m as j,
|
|
83
|
+
k as u
|
|
84
|
+
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { jsx as g } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useLocation as
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const l = await fetch(`${r}api-auth/auth/refresh_token/`, {
|
|
2
|
+
import { useState as S, useEffect as v } from "react";
|
|
3
|
+
import { useLocation as p, Outlet as I } from "react-router-dom";
|
|
4
|
+
const T = () => {
|
|
5
|
+
const [k, o] = S(!1), h = p(), s = `${window.location.protocol}//${window.location.host}/`, c = `${window.location.host}`, w = async () => {
|
|
6
|
+
const l = await fetch(`${s}api-auth/auth/refresh_token/`, {
|
|
8
7
|
method: "POST",
|
|
9
8
|
headers: {
|
|
10
9
|
"Content-Type": "application/json",
|
|
@@ -13,54 +12,50 @@ const E = () => {
|
|
|
13
12
|
credentials: "include"
|
|
14
13
|
});
|
|
15
14
|
if (l.ok) {
|
|
16
|
-
const
|
|
17
|
-
return localStorage.setItem("access_token",
|
|
15
|
+
const r = (await l.json()).token;
|
|
16
|
+
return localStorage.setItem("access_token", r), !0;
|
|
18
17
|
} else
|
|
19
18
|
throw new Error("Error al refrescar token de Microsoft");
|
|
20
19
|
};
|
|
21
|
-
return
|
|
20
|
+
return v(() => {
|
|
22
21
|
const l = async () => {
|
|
23
22
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
console.warn("Inicio de la validación de roles: ", o);
|
|
29
|
-
const u = w(o).user.servicios.map((e) => e.url).filter((e) => !!e), a = h.pathname, n = u.map(
|
|
23
|
+
if (localStorage.getItem("access_token")) {
|
|
24
|
+
const r = localStorage.getItem("auth_state");
|
|
25
|
+
if (r) {
|
|
26
|
+
const f = JSON.parse(r).user.servicios.map((e) => e.url).filter((e) => !!e), a = h.pathname, n = f.map(
|
|
30
27
|
(e) => e.startsWith("/") ? e : `/${e}`
|
|
31
|
-
),
|
|
28
|
+
), m = a.startsWith("/") ? a : `/${a}`;
|
|
32
29
|
n.some(
|
|
33
|
-
(e) =>
|
|
34
|
-
) ?
|
|
30
|
+
(e) => m.startsWith(e)
|
|
31
|
+
) ? o(!0) : (console.warn("No hay match con los roles del usuario"), o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s);
|
|
35
32
|
} else
|
|
36
|
-
|
|
33
|
+
o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s;
|
|
37
34
|
} else
|
|
38
|
-
throw
|
|
35
|
+
throw new Error("Token inválido");
|
|
39
36
|
} catch {
|
|
40
|
-
console.warn("Inicio del try-catch");
|
|
41
37
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const a = w(m).user.servicios.map((t) => t.url).filter((t) => !!t), n = h.pathname, d = a.map(
|
|
38
|
+
if (await w()) {
|
|
39
|
+
const i = localStorage.getItem("auth_state");
|
|
40
|
+
if (i) {
|
|
41
|
+
const a = JSON.parse(i).user.servicios.map((t) => t.url).filter((t) => !!t), n = h.pathname, m = a.map(
|
|
47
42
|
(t) => t.startsWith("/") ? t : `/${t}`
|
|
48
|
-
),
|
|
49
|
-
|
|
50
|
-
(t) =>
|
|
51
|
-
) ?
|
|
43
|
+
), u = n.startsWith("/") ? n : `/${n}`;
|
|
44
|
+
m.some(
|
|
45
|
+
(t) => u.startsWith(t)
|
|
46
|
+
) ? o(!0) : (o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s);
|
|
52
47
|
} else
|
|
53
|
-
|
|
48
|
+
o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s;
|
|
54
49
|
} else
|
|
55
50
|
throw new Error("No se pudo refrescar el token.");
|
|
56
51
|
} catch {
|
|
57
|
-
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href =
|
|
52
|
+
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s, o(!1);
|
|
58
53
|
}
|
|
59
54
|
}
|
|
60
55
|
};
|
|
61
|
-
c.includes("ecosistemadesarrollo") || c.includes("ecosistemapruebas") || c.includes("ecosistemaprov") || c.includes("ecosistema") ? l() : (console.warn("ProtectedRoute is disabled in the local development environment."),
|
|
62
|
-
}, []), k ? /* @__PURE__ */ g(
|
|
56
|
+
c.includes("ecosistemadesarrollo") || c.includes("ecosistemapruebas") || c.includes("ecosistemaprov") || c.includes("ecosistema") ? l() : (console.warn("ProtectedRoute is disabled in the local development environment."), o(!0));
|
|
57
|
+
}, []), k ? /* @__PURE__ */ g(I, {}) : null;
|
|
63
58
|
};
|
|
64
59
|
export {
|
|
65
|
-
|
|
60
|
+
T as ProtectedRoute
|
|
66
61
|
};
|
|
@@ -2,7 +2,6 @@ import { jsx as r } from "react/jsx-runtime";
|
|
|
2
2
|
import { AuthProvider as t } from "../../auth/contexts/AuthContex.js";
|
|
3
3
|
import "react";
|
|
4
4
|
import "react-router-dom";
|
|
5
|
-
import "../../index-CuHybtft.js";
|
|
6
5
|
import '../../assets/EcoModalStyles.css';import '../../assets/Modal.css';import '../../assets/ContenedorVentana.css';import '../../assets/IconoTooltip.css';import '../../assets/ItemsModal.css';import '../../assets/Paginador.css';import '../../assets/ContenidoModal.css';import '../../assets/Encabezado.css';import '../../assets/SeccionTarjetaLectura.css';import '../../assets/Logo.css';import '../../assets/TarjetaLectura.css';import '../../assets/ContenedorTarjeta.css';import '../../assets/Bootstrap.css';import '../../assets/Tarjeta.css';import '../../assets/UnpHistorico.css';/* empty css */
|
|
7
6
|
/* empty css */
|
|
8
7
|
/* empty css */
|
|
@@ -25,7 +24,7 @@ import "../../index-BrykDZgK.js";
|
|
|
25
24
|
import "../../Animacion-ThNL9iiY.js";
|
|
26
25
|
import "../../index-BUe3EJDH.js";
|
|
27
26
|
import { WebSocketProvider as i } from "../websocket-manager/WebSocketContext.js";
|
|
28
|
-
const
|
|
27
|
+
const z = ({ children: o }) => /* @__PURE__ */ r(t, { children: /* @__PURE__ */ r(i, { children: o }) });
|
|
29
28
|
export {
|
|
30
|
-
|
|
29
|
+
z as EcoProvider
|
|
31
30
|
};
|
package/package.json
CHANGED
package/dist/index-CuHybtft.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
class o extends Error {
|
|
2
|
-
}
|
|
3
|
-
o.prototype.name = "InvalidTokenError";
|
|
4
|
-
function i(t) {
|
|
5
|
-
return decodeURIComponent(atob(t).replace(/(.)/g, (e, r) => {
|
|
6
|
-
let n = r.charCodeAt(0).toString(16).toUpperCase();
|
|
7
|
-
return n.length < 2 && (n = "0" + n), "%" + n;
|
|
8
|
-
}));
|
|
9
|
-
}
|
|
10
|
-
function s(t) {
|
|
11
|
-
let e = t.replace(/-/g, "+").replace(/_/g, "/");
|
|
12
|
-
switch (e.length % 4) {
|
|
13
|
-
case 0:
|
|
14
|
-
break;
|
|
15
|
-
case 2:
|
|
16
|
-
e += "==";
|
|
17
|
-
break;
|
|
18
|
-
case 3:
|
|
19
|
-
e += "=";
|
|
20
|
-
break;
|
|
21
|
-
default:
|
|
22
|
-
throw new Error("base64 string is not of the correct length");
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
return i(e);
|
|
26
|
-
} catch {
|
|
27
|
-
return atob(e);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function d(t, e) {
|
|
31
|
-
if (typeof t != "string")
|
|
32
|
-
throw new o("Invalid token specified: must be a string");
|
|
33
|
-
e || (e = {});
|
|
34
|
-
const r = e.header === !0 ? 0 : 1, n = t.split(".")[r];
|
|
35
|
-
if (typeof n != "string")
|
|
36
|
-
throw new o(`Invalid token specified: missing part #${r + 1}`);
|
|
37
|
-
let c;
|
|
38
|
-
try {
|
|
39
|
-
c = s(n);
|
|
40
|
-
} catch (a) {
|
|
41
|
-
throw new o(`Invalid token specified: invalid base64 for part #${r + 1} (${a.message})`);
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
return JSON.parse(c);
|
|
45
|
-
} catch (a) {
|
|
46
|
-
throw new o(`Invalid token specified: invalid json for part #${r + 1} (${a.message})`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
d as j
|
|
51
|
-
};
|