add PermissionProvider to BiProvider
This commit is contained in:
parent
578b07626e
commit
f5412599a3
202
dist/index.js
vendored
202
dist/index.js
vendored
@ -5,33 +5,33 @@ import { IoChevronForwardOutline as O, IoChevronBackOutline as W } from "react-i
|
|||||||
import te from "keycloak-js";
|
import te from "keycloak-js";
|
||||||
import { useQuery as ne } from "@tanstack/react-query";
|
import { useQuery as ne } from "@tanstack/react-query";
|
||||||
import re from "axios";
|
import re from "axios";
|
||||||
const Ee = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => String(e).replace(/\d/g, (t) => "۰۱۲۳۴۵۶۷۸۹"[Number(t)]), D = (e) => String(e).replace(/[۰-۹]/g, (n) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(n))), De = ({
|
const De = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => String(e).replace(/\d/g, (t) => "۰۱۲۳۴۵۶۷۸۹"[Number(t)]), D = (e) => String(e).replace(/[۰-۹]/g, (n) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(n))), Ke = ({
|
||||||
currentPage: e,
|
currentPage: e,
|
||||||
totalPages: t,
|
totalPages: t,
|
||||||
totalCount: n,
|
totalCount: n,
|
||||||
onPageChange: l
|
onPageChange: l
|
||||||
}) => {
|
}) => {
|
||||||
const [u, s] = v(p(e)), [i, o] = v(!1), [d, c] = v(null), b = N(null), y = [.../* @__PURE__ */ new Set([1, e, t])].filter(
|
const [c, s] = v(p(e)), [i, o] = v(!1), [d, u] = v(null), b = N(null), y = [.../* @__PURE__ */ new Set([1, e, t])].filter(
|
||||||
(r) => r >= 1 && r <= t
|
(r) => r >= 1 && r <= t
|
||||||
);
|
);
|
||||||
C(() => {
|
C(() => {
|
||||||
if (d !== null) {
|
if (d !== null) {
|
||||||
e === d && (c(null), o(!1), s(p(e)));
|
e === d && (u(null), o(!1), s(p(e)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i || s(p(e));
|
i || s(p(e));
|
||||||
}, [e, i, d]), C(() => {
|
}, [e, i, d]), C(() => {
|
||||||
if (!i || !u || d !== null) return;
|
if (!i || !c || d !== null) return;
|
||||||
const r = parseInt(D(u), 10);
|
const r = parseInt(D(c), 10);
|
||||||
if (isNaN(r)) return;
|
if (isNaN(r)) return;
|
||||||
const h = setTimeout(() => {
|
const h = setTimeout(() => {
|
||||||
var w;
|
var w;
|
||||||
const m = Math.min(Math.max(r, 1), t);
|
const m = Math.min(Math.max(r, 1), t);
|
||||||
m !== e ? (c(m), s(p(m)), l(m)) : (o(!1), s(p(e))), (w = b.current) == null || w.blur();
|
m !== e ? (u(m), s(p(m)), l(m)) : (o(!1), s(p(e))), (w = b.current) == null || w.blur();
|
||||||
}, 1e3);
|
}, 1e3);
|
||||||
return () => clearTimeout(h);
|
return () => clearTimeout(h);
|
||||||
}, [
|
}, [
|
||||||
u,
|
c,
|
||||||
i,
|
i,
|
||||||
d,
|
d,
|
||||||
t,
|
t,
|
||||||
@ -40,13 +40,13 @@ const Ee = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => S
|
|||||||
]);
|
]);
|
||||||
const A = () => {
|
const A = () => {
|
||||||
var m, w;
|
var m, w;
|
||||||
const r = parseInt(D(u), 10);
|
const r = parseInt(D(c), 10);
|
||||||
if (isNaN(r)) {
|
if (isNaN(r)) {
|
||||||
s(p(e)), o(!1), c(null), (m = b.current) == null || m.blur();
|
s(p(e)), o(!1), u(null), (m = b.current) == null || m.blur();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const h = Math.min(Math.max(r, 1), t);
|
const h = Math.min(Math.max(r, 1), t);
|
||||||
h !== e ? (c(h), s(p(h)), l(h)) : (s(p(e)), o(!1), c(null)), (w = b.current) == null || w.blur();
|
h !== e ? (u(h), s(p(h)), l(h)) : (s(p(e)), o(!1), u(null)), (w = b.current) == null || w.blur();
|
||||||
};
|
};
|
||||||
return t === 0 || !n ? null : /* @__PURE__ */ I(
|
return t === 0 || !n ? null : /* @__PURE__ */ I(
|
||||||
k,
|
k,
|
||||||
@ -109,16 +109,16 @@ const Ee = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => S
|
|||||||
inputMode: "numeric",
|
inputMode: "numeric",
|
||||||
placeholder: "صفحه",
|
placeholder: "صفحه",
|
||||||
w: "56px",
|
w: "56px",
|
||||||
value: u,
|
value: c,
|
||||||
onFocus: () => {
|
onFocus: () => {
|
||||||
o(!0), c(null), s("");
|
o(!0), u(null), s("");
|
||||||
},
|
},
|
||||||
onChange: (r) => {
|
onChange: (r) => {
|
||||||
const h = r.target.value, m = D(h).replace(/\D/g, "");
|
const h = r.target.value, m = D(h).replace(/\D/g, "");
|
||||||
s(p(m));
|
s(p(m));
|
||||||
},
|
},
|
||||||
onBlur: () => {
|
onBlur: () => {
|
||||||
u || (s(p(e)), o(!1), c(null));
|
c || (s(p(e)), o(!1), u(null));
|
||||||
},
|
},
|
||||||
onKeyDown: (r) => {
|
onKeyDown: (r) => {
|
||||||
r.key === "Enter" && A();
|
r.key === "Enter" && A();
|
||||||
@ -138,33 +138,33 @@ const Ee = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => S
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, Ke = ({
|
}, Ne = ({
|
||||||
currentPage: e,
|
currentPage: e,
|
||||||
totalPages: t,
|
totalPages: t,
|
||||||
totalCount: n,
|
totalCount: n,
|
||||||
onPageChange: l
|
onPageChange: l
|
||||||
}) => {
|
}) => {
|
||||||
const [u, s] = v(p(e)), [i, o] = v(!1), [d, c] = v(null), b = N(null), y = Array.from(
|
const [c, s] = v(p(e)), [i, o] = v(!1), [d, u] = v(null), b = N(null), y = Array.from(
|
||||||
/* @__PURE__ */ new Set([1, e, e + 1, t])
|
/* @__PURE__ */ new Set([1, e, e + 1, t])
|
||||||
).filter((r) => r >= 1 && r <= t).sort((r, h) => r - h);
|
).filter((r) => r >= 1 && r <= t).sort((r, h) => r - h);
|
||||||
C(() => {
|
C(() => {
|
||||||
if (d !== null) {
|
if (d !== null) {
|
||||||
e === d && (c(null), o(!1), s(p(e)));
|
e === d && (u(null), o(!1), s(p(e)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i || s(p(e));
|
i || s(p(e));
|
||||||
}, [e, i, d]), C(() => {
|
}, [e, i, d]), C(() => {
|
||||||
if (!i || !u || d !== null) return;
|
if (!i || !c || d !== null) return;
|
||||||
const r = parseInt(D(u), 10);
|
const r = parseInt(D(c), 10);
|
||||||
if (isNaN(r)) return;
|
if (isNaN(r)) return;
|
||||||
const h = setTimeout(() => {
|
const h = setTimeout(() => {
|
||||||
var w;
|
var w;
|
||||||
const m = Math.min(Math.max(r, 1), t);
|
const m = Math.min(Math.max(r, 1), t);
|
||||||
m !== e ? (c(m), s(p(m)), l(m)) : (o(!1), s(p(e))), (w = b.current) == null || w.blur();
|
m !== e ? (u(m), s(p(m)), l(m)) : (o(!1), s(p(e))), (w = b.current) == null || w.blur();
|
||||||
}, 1e3);
|
}, 1e3);
|
||||||
return () => clearTimeout(h);
|
return () => clearTimeout(h);
|
||||||
}, [
|
}, [
|
||||||
u,
|
c,
|
||||||
i,
|
i,
|
||||||
d,
|
d,
|
||||||
t,
|
t,
|
||||||
@ -173,13 +173,13 @@ const Ee = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => S
|
|||||||
]);
|
]);
|
||||||
const A = () => {
|
const A = () => {
|
||||||
var m, w;
|
var m, w;
|
||||||
const r = parseInt(D(u), 10);
|
const r = parseInt(D(c), 10);
|
||||||
if (isNaN(r)) {
|
if (isNaN(r)) {
|
||||||
s(p(e)), o(!1), c(null), (m = b.current) == null || m.blur();
|
s(p(e)), o(!1), u(null), (m = b.current) == null || m.blur();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const h = Math.min(Math.max(r, 1), t);
|
const h = Math.min(Math.max(r, 1), t);
|
||||||
h !== e ? (c(h), s(p(h)), l(h)) : (s(p(e)), o(!1), c(null)), (w = b.current) == null || w.blur();
|
h !== e ? (u(h), s(p(h)), l(h)) : (s(p(e)), o(!1), u(null)), (w = b.current) == null || w.blur();
|
||||||
};
|
};
|
||||||
return t === 0 || !n ? null : /* @__PURE__ */ I(
|
return t === 0 || !n ? null : /* @__PURE__ */ I(
|
||||||
k,
|
k,
|
||||||
@ -247,16 +247,16 @@ const Ee = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => S
|
|||||||
inputMode: "numeric",
|
inputMode: "numeric",
|
||||||
placeholder: "صفحه",
|
placeholder: "صفحه",
|
||||||
w: "100px",
|
w: "100px",
|
||||||
value: u,
|
value: c,
|
||||||
onFocus: () => {
|
onFocus: () => {
|
||||||
o(!0), c(null), s("");
|
o(!0), u(null), s("");
|
||||||
},
|
},
|
||||||
onChange: (r) => {
|
onChange: (r) => {
|
||||||
const h = r.target.value, m = D(h).replace(/\D/g, "");
|
const h = r.target.value, m = D(h).replace(/\D/g, "");
|
||||||
s(p(m));
|
s(p(m));
|
||||||
},
|
},
|
||||||
onBlur: () => {
|
onBlur: () => {
|
||||||
u || (s(p(e)), o(!1), c(null));
|
c || (s(p(e)), o(!1), u(null));
|
||||||
},
|
},
|
||||||
onKeyDown: (r) => {
|
onKeyDown: (r) => {
|
||||||
r.key === "Enter" && A();
|
r.key === "Enter" && A();
|
||||||
@ -276,45 +276,45 @@ const Ee = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => S
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, Ne = ({
|
}, Te = ({
|
||||||
currentPage: e,
|
currentPage: e,
|
||||||
totalPages: t,
|
totalPages: t,
|
||||||
totalCount: n,
|
totalCount: n,
|
||||||
onPageChange: l
|
onPageChange: l
|
||||||
}) => {
|
}) => {
|
||||||
const [u, s] = v(""), [i, o] = v(!1), [d, c] = v(null), b = N(null), y = d ?? e, A = E(
|
const [c, s] = v(""), [i, o] = v(!1), [d, u] = v(null), b = N(null), y = d ?? e, A = E(
|
||||||
(x) => {
|
(x) => {
|
||||||
const B = Math.min(Math.max(x, 1), t);
|
const B = Math.min(Math.max(x, 1), t);
|
||||||
o(!1), s(""), c(null), B !== e && l(B);
|
o(!1), s(""), u(null), B !== e && l(B);
|
||||||
},
|
},
|
||||||
[e, t, l]
|
[e, t, l]
|
||||||
), r = E(() => {
|
), r = E(() => {
|
||||||
if (!u) {
|
if (!c) {
|
||||||
o(!1), s(""), c(null);
|
o(!1), s(""), u(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const x = parseInt(D(u), 10);
|
const x = parseInt(D(c), 10);
|
||||||
if (isNaN(x)) {
|
if (isNaN(x)) {
|
||||||
o(!1), s(""), c(null);
|
o(!1), s(""), u(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const B = Math.min(Math.max(x, 1), t);
|
const B = Math.min(Math.max(x, 1), t);
|
||||||
o(!1), s(""), B !== e ? (c(B), l(B)) : c(null);
|
o(!1), s(""), B !== e ? (u(B), l(B)) : u(null);
|
||||||
}, [u, e, t, l]);
|
}, [c, e, t, l]);
|
||||||
C(() => {
|
C(() => {
|
||||||
var x;
|
var x;
|
||||||
i && ((x = b.current) == null || x.focus());
|
i && ((x = b.current) == null || x.focus());
|
||||||
}, [i]), C(() => {
|
}, [i]), C(() => {
|
||||||
d !== null && e === d && c(null);
|
d !== null && e === d && u(null);
|
||||||
}, [e, d]), C(() => {
|
}, [e, d]), C(() => {
|
||||||
if (!i || !u) return;
|
if (!i || !c) return;
|
||||||
const x = setTimeout(() => {
|
const x = setTimeout(() => {
|
||||||
r();
|
r();
|
||||||
}, 1e3);
|
}, 1e3);
|
||||||
return () => clearTimeout(x);
|
return () => clearTimeout(x);
|
||||||
}, [u, i, r]);
|
}, [c, i, r]);
|
||||||
const h = () => {
|
const h = () => {
|
||||||
c(null), s(""), o(!0);
|
u(null), s(""), o(!0);
|
||||||
}, m = (x, B = !1) => /* @__PURE__ */ a(
|
}, m = (x, B = !1) => /* @__PURE__ */ a(
|
||||||
R,
|
R,
|
||||||
{
|
{
|
||||||
@ -364,16 +364,16 @@ const Ee = (e) => new Intl.NumberFormat("fa-IR").format(Number(e)), p = (e) => S
|
|||||||
inputMode: "numeric",
|
inputMode: "numeric",
|
||||||
placeholder: "صفحه",
|
placeholder: "صفحه",
|
||||||
w: "48px",
|
w: "48px",
|
||||||
value: u,
|
value: c,
|
||||||
onChange: (x) => {
|
onChange: (x) => {
|
||||||
const B = x.target.value, X = D(B).replace(/\D/g, "");
|
const B = x.target.value, X = D(B).replace(/\D/g, "");
|
||||||
s(p(X));
|
s(p(X));
|
||||||
},
|
},
|
||||||
onBlur: () => {
|
onBlur: () => {
|
||||||
u ? r() : (s(""), o(!1), c(null));
|
c ? r() : (s(""), o(!1), u(null));
|
||||||
},
|
},
|
||||||
onKeyDown: (x) => {
|
onKeyDown: (x) => {
|
||||||
x.key === "Enter" && r(), x.key === "Escape" && (s(""), o(!1), c(null));
|
x.key === "Enter" && r(), x.key === "Escape" && (s(""), o(!1), u(null));
|
||||||
},
|
},
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
color: "#1D2939",
|
color: "#1D2939",
|
||||||
@ -405,7 +405,7 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
url: e,
|
url: e,
|
||||||
realm: t,
|
realm: t,
|
||||||
clientId: n
|
clientId: n
|
||||||
})), f), se = (e) => (V = e, V), le = () => j, G = () => !!(f != null && f.authenticated), T = () => (f == null ? void 0 : f.token) ?? null, q = async (e = 30) => f ? f.updateToken(e) : !1, H = (e) => f == null ? void 0 : f.logout(e), Te = (e) => f == null ? void 0 : f.login(e), J = ({ config: e, initOptions: t = {} } = {}) => {
|
})), f), se = (e) => (V = e, V), le = () => j, G = () => !!(f != null && f.authenticated), T = () => (f == null ? void 0 : f.token) ?? null, q = async (e = 30) => f ? f.updateToken(e) : !1, H = (e) => f == null ? void 0 : f.logout(e), _e = (e) => f == null ? void 0 : f.login(e), J = ({ config: e, initOptions: t = {} } = {}) => {
|
||||||
const n = e ?? V;
|
const n = e ?? V;
|
||||||
if (!(n != null && n.url) || !(n != null && n.realm) || !(n != null && n.clientId))
|
if (!(n != null && n.url) || !(n != null && n.realm) || !(n != null && n.clientId))
|
||||||
throw new Error("Keycloak config is required.");
|
throw new Error("Keycloak config is required.");
|
||||||
@ -416,8 +416,8 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
checkLoginIframe: !1,
|
checkLoginIframe: !1,
|
||||||
flow: "implicit",
|
flow: "implicit",
|
||||||
...t
|
...t
|
||||||
}).then((u) => (j = !0, u)).catch((u) => {
|
}).then((c) => (j = !0, c)).catch((c) => {
|
||||||
throw j = !0, u;
|
throw j = !0, c;
|
||||||
})), F;
|
})), F;
|
||||||
}, ce = ({
|
}, ce = ({
|
||||||
children: e,
|
children: e,
|
||||||
@ -425,13 +425,13 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
initOptions: n,
|
initOptions: n,
|
||||||
loading: l = null
|
loading: l = null
|
||||||
}) => {
|
}) => {
|
||||||
const [u, s] = v(!1), [i, o] = v(!1), [d, c] = v(null), b = N(!1), y = E(() => {
|
const [c, s] = v(!1), [i, o] = v(!1), [d, u] = v(null), b = N(!1), y = E(() => {
|
||||||
f && (o(!!f.authenticated), c(f.token ?? null));
|
f && (o(!!f.authenticated), u(f.token ?? null));
|
||||||
}, []);
|
}, []);
|
||||||
C(() => (b.current = !0, J({ config: t, initOptions: n }).then((w) => {
|
C(() => (b.current = !0, J({ config: t, initOptions: n }).then((w) => {
|
||||||
b.current && (o(!!w), c((f == null ? void 0 : f.token) ?? null), s(!0));
|
b.current && (o(!!w), u((f == null ? void 0 : f.token) ?? null), s(!0));
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
b.current && (o(!1), c(null), s(!0));
|
b.current && (o(!1), u(null), s(!0));
|
||||||
}), () => {
|
}), () => {
|
||||||
b.current = !1;
|
b.current = !1;
|
||||||
}), [t, n]);
|
}), [t, n]);
|
||||||
@ -444,34 +444,34 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
[y]
|
[y]
|
||||||
), m = _(
|
), m = _(
|
||||||
() => ({
|
() => ({
|
||||||
initialized: u,
|
initialized: c,
|
||||||
authenticated: i,
|
authenticated: i,
|
||||||
token: d,
|
token: d,
|
||||||
login: A,
|
login: A,
|
||||||
logout: r,
|
logout: r,
|
||||||
updateToken: h
|
updateToken: h
|
||||||
}),
|
}),
|
||||||
[u, i, d, A, r, h]
|
[c, i, d, A, r, h]
|
||||||
);
|
);
|
||||||
return u ? /* @__PURE__ */ a(ie.Provider, { value: m, children: e }) : l;
|
return c ? /* @__PURE__ */ a(ie.Provider, { value: m, children: e }) : l;
|
||||||
}, Q = $(null), M = "permissions", ue = (e) => (e == null ? void 0 : e.storageKey) || M, _e = ({
|
}, Q = $(null), M = "permissions", ue = (e) => (e == null ? void 0 : e.storageKey) || M, ae = ({
|
||||||
user: e = null,
|
user: e = null,
|
||||||
children: t,
|
children: t,
|
||||||
config: n,
|
config: n,
|
||||||
loading: l = /* @__PURE__ */ a("div", { children: "Loading permissions..." }),
|
loading: l = /* @__PURE__ */ a("div", { children: "Loading permissions..." }),
|
||||||
errorFallback: u = /* @__PURE__ */ a("div", { children: "Error loading permissions" })
|
errorFallback: c = /* @__PURE__ */ a("div", { children: "Error loading permissions" })
|
||||||
}) => {
|
}) => {
|
||||||
const s = ue(n), [i, o] = v(
|
const s = ue(n), [i, o] = v(
|
||||||
() => ae(s)
|
() => de(s)
|
||||||
), { data: d, isLoading: c, error: b } = me(n), y = d ?? i;
|
), { data: d, isLoading: u, error: b } = be(n), y = d ?? i;
|
||||||
C(() => {
|
C(() => {
|
||||||
d && (de(s, d), o(d));
|
d && (fe(s, d), o(d));
|
||||||
}, [d, s]);
|
}, [d, s]);
|
||||||
const A = _(
|
const A = _(
|
||||||
() => fe(y),
|
() => pe(y),
|
||||||
[y]
|
[y]
|
||||||
), r = E(
|
), r = E(
|
||||||
(w = "") => pe(A, w),
|
(w = "") => he(A, w),
|
||||||
[A]
|
[A]
|
||||||
), h = E((w = "") => !r(w), [r]), m = _(
|
), h = E((w = "") => !r(w), [r]), m = _(
|
||||||
() => ({
|
() => ({
|
||||||
@ -479,13 +479,13 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
can: r,
|
can: r,
|
||||||
cannot: h,
|
cannot: h,
|
||||||
permissions: y,
|
permissions: y,
|
||||||
isLoading: c,
|
isLoading: u,
|
||||||
error: b
|
error: b
|
||||||
}),
|
}),
|
||||||
[e, r, h, y, c, b]
|
[e, r, h, y, u, b]
|
||||||
);
|
);
|
||||||
return b && !y ? u : c && !y ? l : /* @__PURE__ */ a(Q.Provider, { value: m, children: t });
|
return b && !y ? c : u && !y ? l : /* @__PURE__ */ a(Q.Provider, { value: m, children: t });
|
||||||
}, ae = (e = M) => {
|
}, de = (e = M) => {
|
||||||
if (!(typeof window > "u"))
|
if (!(typeof window > "u"))
|
||||||
try {
|
try {
|
||||||
const t = localStorage.getItem(e);
|
const t = localStorage.getItem(e);
|
||||||
@ -493,7 +493,7 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, de = (e = M, t) => {
|
}, fe = (e = M, t) => {
|
||||||
if (!(typeof window > "u"))
|
if (!(typeof window > "u"))
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(e, JSON.stringify(t));
|
localStorage.setItem(e, JSON.stringify(t));
|
||||||
@ -505,7 +505,7 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
localStorage.removeItem(e);
|
localStorage.removeItem(e);
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
}, fe = (e) => e ? new Set(e.map((t) => t.name)) : /* @__PURE__ */ new Set(), pe = (e, t = "") => {
|
}, pe = (e) => e ? new Set(e.map((t) => t.name)) : /* @__PURE__ */ new Set(), he = (e, t = "") => {
|
||||||
if (!t) return !1;
|
if (!t) return !1;
|
||||||
if (e.has(t) || [...e].some((l) => l.startsWith(t))) return !0;
|
if (e.has(t) || [...e].some((l) => l.startsWith(t))) return !0;
|
||||||
let n = t;
|
let n = t;
|
||||||
@ -515,7 +515,7 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
}, Y = {
|
}, Y = {
|
||||||
all: ["permissions"],
|
all: ["permissions"],
|
||||||
list: (e) => [...Y.all, e]
|
list: (e) => [...Y.all, e]
|
||||||
}, he = async (e) => {
|
}, me = async (e) => {
|
||||||
if (!(e != null && e.url) || !(e != null && e.clientId))
|
if (!(e != null && e.url) || !(e != null && e.clientId))
|
||||||
throw new Error("Permission config requires url and clientId.");
|
throw new Error("Permission config requires url and clientId.");
|
||||||
const t = T(), n = new URL(e.url);
|
const t = T(), n = new URL(e.url);
|
||||||
@ -534,9 +534,9 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
if (!e)
|
if (!e)
|
||||||
throw new Error("usePermission must be used within PermissionProvider");
|
throw new Error("usePermission must be used within PermissionProvider");
|
||||||
return e;
|
return e;
|
||||||
}, me = (e) => ne({
|
}, be = (e) => ne({
|
||||||
queryKey: Y.list(e == null ? void 0 : e.clientId),
|
queryKey: Y.list(e == null ? void 0 : e.clientId),
|
||||||
queryFn: () => he(e),
|
queryFn: () => me(e),
|
||||||
enabled: !!(e != null && e.url) && !!(e != null && e.clientId) && G(),
|
enabled: !!(e != null && e.url) && !!(e != null && e.clientId) && G(),
|
||||||
staleTime: 1 / 0,
|
staleTime: 1 / 0,
|
||||||
refetchOnWindowFocus: !1,
|
refetchOnWindowFocus: !1,
|
||||||
@ -558,12 +558,12 @@ const ie = $(null), oe = ({ url: e, realm: t, clientId: n }) => (f || (f = new t
|
|||||||
}, [n, t]), e;
|
}, [n, t]), e;
|
||||||
};
|
};
|
||||||
let z = null;
|
let z = null;
|
||||||
const be = (e) => {
|
const we = (e) => {
|
||||||
const { api: t } = e, n = re.create({
|
const { api: t } = e, n = re.create({
|
||||||
baseURL: t.baseUrl
|
baseURL: t.baseUrl
|
||||||
}), l = async () => {
|
}), l = async () => {
|
||||||
(!le() || !G()) && await J();
|
(!le() || !G()) && await J();
|
||||||
}, u = async (i) => {
|
}, c = async (i) => {
|
||||||
await l();
|
await l();
|
||||||
let o = T();
|
let o = T();
|
||||||
if (o) {
|
if (o) {
|
||||||
@ -584,10 +584,10 @@ const be = (e) => {
|
|||||||
o._retry = !0;
|
o._retry = !0;
|
||||||
try {
|
try {
|
||||||
await q(30);
|
await q(30);
|
||||||
const c = T();
|
const u = T();
|
||||||
return o.headers = {
|
return o.headers = {
|
||||||
...o.headers,
|
...o.headers,
|
||||||
Authorization: `Bearer ${c}`
|
Authorization: `Bearer ${u}`
|
||||||
}, n(o);
|
}, n(o);
|
||||||
} catch {
|
} catch {
|
||||||
H({ redirectUri: window.location.origin });
|
H({ redirectUri: window.location.origin });
|
||||||
@ -595,13 +595,13 @@ const be = (e) => {
|
|||||||
}
|
}
|
||||||
return Promise.reject(i);
|
return Promise.reject(i);
|
||||||
};
|
};
|
||||||
return n.interceptors.request.use(u), n.interceptors.response.use(
|
return n.interceptors.request.use(c), n.interceptors.response.use(
|
||||||
(i) => i,
|
(i) => i,
|
||||||
s
|
s
|
||||||
), {
|
), {
|
||||||
api: n
|
api: n
|
||||||
};
|
};
|
||||||
}, we = (e) => (z = be(e), z), ye = () => {
|
}, ye = (e) => (z = we(e), z), xe = () => {
|
||||||
if (!z)
|
if (!z)
|
||||||
throw new Error("api is not configured. Call configureApi(config) first.");
|
throw new Error("api is not configured. Call configureApi(config) first.");
|
||||||
return z.api;
|
return z.api;
|
||||||
@ -609,16 +609,16 @@ const be = (e) => {
|
|||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
get(e, t) {
|
get(e, t) {
|
||||||
return ye()[t];
|
return xe()[t];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
function xe() {
|
function ve() {
|
||||||
const [e, t] = v(!1), n = N(null);
|
const [e, t] = v(!1), n = N(null);
|
||||||
return C(() => {
|
return C(() => {
|
||||||
if (process.env.NODE_ENV !== "production") return;
|
if (process.env.NODE_ENV !== "production") return;
|
||||||
let l;
|
let l;
|
||||||
const u = async () => {
|
const c = async () => {
|
||||||
const i = await fetch(`/version.json?t=${Date.now()}`, {
|
const i = await fetch(`/version.json?t=${Date.now()}`, {
|
||||||
cache: "no-store"
|
cache: "no-store"
|
||||||
});
|
});
|
||||||
@ -629,9 +629,9 @@ function xe() {
|
|||||||
};
|
};
|
||||||
return (async () => {
|
return (async () => {
|
||||||
try {
|
try {
|
||||||
n.current = await u(), l = setInterval(async () => {
|
n.current = await c(), l = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const i = await u();
|
const i = await c();
|
||||||
n.current && i !== n.current && (t(!0), clearInterval(l));
|
n.current && i !== n.current && (t(!0), clearInterval(l));
|
||||||
} catch (i) {
|
} catch (i) {
|
||||||
console.error("Update check failed:", i);
|
console.error("Update check failed:", i);
|
||||||
@ -667,12 +667,12 @@ function je({
|
|||||||
apiBaseUrl: t,
|
apiBaseUrl: t,
|
||||||
keycloakClientId: n,
|
keycloakClientId: n,
|
||||||
permissionClientId: l,
|
permissionClientId: l,
|
||||||
loading: u = /* @__PURE__ */ a(ee, {}),
|
loading: c = /* @__PURE__ */ a(ee, {}),
|
||||||
updateChecker: s = !0,
|
updateChecker: s = !0,
|
||||||
updateCheckerProps: i,
|
updateCheckerProps: i,
|
||||||
keycloakUrl: o = "https://auth.ibagher.ir",
|
keycloakUrl: o = "https://auth.ibagher.ir",
|
||||||
keycloakRealm: d = "bi",
|
keycloakRealm: d = "bi",
|
||||||
permissionUrl: c = "https://api.d.aiengines.ir/user_api/v1/permissions/list"
|
permissionUrl: u = "https://api.d.aiengines.ir/user_api/v1/permissions/list"
|
||||||
}) {
|
}) {
|
||||||
const b = _(
|
const b = _(
|
||||||
() => ({
|
() => ({
|
||||||
@ -685,7 +685,7 @@ function je({
|
|||||||
clientId: n
|
clientId: n
|
||||||
},
|
},
|
||||||
permission: {
|
permission: {
|
||||||
url: c,
|
url: u,
|
||||||
clientId: l
|
clientId: l
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@ -695,14 +695,14 @@ function je({
|
|||||||
l,
|
l,
|
||||||
o,
|
o,
|
||||||
d,
|
d,
|
||||||
c
|
u
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
return C(() => {
|
return C(() => {
|
||||||
we(b);
|
ye(b);
|
||||||
}, [b]), /* @__PURE__ */ I(Z, { children: [
|
}, [b]), /* @__PURE__ */ I(Z, { children: [
|
||||||
s && /* @__PURE__ */ a(xe, { ...i }),
|
s && /* @__PURE__ */ a(ve, { ...i }),
|
||||||
/* @__PURE__ */ a(ce, { config: b.keycloak, loading: u, children: e })
|
/* @__PURE__ */ a(ce, { config: b.keycloak, loading: c, children: /* @__PURE__ */ a(ae, { config: b.permission, loading: c, children: e }) })
|
||||||
] });
|
] });
|
||||||
}
|
}
|
||||||
export {
|
export {
|
||||||
@ -710,32 +710,32 @@ export {
|
|||||||
je as BiProvider,
|
je as BiProvider,
|
||||||
Me as Can,
|
Me as Can,
|
||||||
ce as KeycloakProvider,
|
ce as KeycloakProvider,
|
||||||
De as LightPagination,
|
Ke as LightPagination,
|
||||||
Ke as Pagination,
|
Ne as Pagination,
|
||||||
Fe as PanelAccessGuard,
|
Fe as PanelAccessGuard,
|
||||||
_e as PermissionProvider,
|
ae as PermissionProvider,
|
||||||
Ne as SimplePagination,
|
Te as SimplePagination,
|
||||||
Ve as api,
|
Ve as api,
|
||||||
pe as checkPermission,
|
he as checkPermission,
|
||||||
ze as clearCachedPermissions,
|
ze as clearCachedPermissions,
|
||||||
we as configureApi,
|
ye as configureApi,
|
||||||
be as createApi,
|
we as createApi,
|
||||||
fe as createPermissionSet,
|
pe as createPermissionSet,
|
||||||
ye as getApi,
|
xe as getApi,
|
||||||
ae as getCachedPermissions,
|
de as getCachedPermissions,
|
||||||
T as getKeycloakToken,
|
T as getKeycloakToken,
|
||||||
he as getPermissions,
|
me as getPermissions,
|
||||||
J as initKeycloak,
|
J as initKeycloak,
|
||||||
G as isKeycloakAuthenticated,
|
G as isKeycloakAuthenticated,
|
||||||
le as isKeycloakInitialized,
|
le as isKeycloakInitialized,
|
||||||
Te as loginKeycloak,
|
_e as loginKeycloak,
|
||||||
H as logoutKeycloak,
|
H as logoutKeycloak,
|
||||||
Y as permissionKeys,
|
Y as permissionKeys,
|
||||||
de as setCachedPermissions,
|
fe as setCachedPermissions,
|
||||||
D as toEnDigits,
|
D as toEnDigits,
|
||||||
p as toFaDigits,
|
p as toFaDigits,
|
||||||
Ee as toFaNumber,
|
De as toFaNumber,
|
||||||
q as updateKeycloakToken,
|
q as updateKeycloakToken,
|
||||||
U as usePermission,
|
U as usePermission,
|
||||||
me as usePermissionsQuery
|
be as usePermissionsQuery
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { Spinner } from "@chakra-ui/react";
|
import { Spinner } from "@chakra-ui/react";
|
||||||
import { KeycloakProvider } from "../core/keycloak.jsx";
|
import { KeycloakProvider } from "../core/keycloak.jsx";
|
||||||
|
import { PermissionProvider } from "../core/permission.jsx";
|
||||||
import { UpdateChecker } from "../components/UpdateChecker.jsx";
|
import { UpdateChecker } from "../components/UpdateChecker.jsx";
|
||||||
import { configureApi } from "../core/api.js";
|
import { configureApi } from "../core/api.js";
|
||||||
|
|
||||||
@ -50,7 +51,9 @@ export function BiProvider({
|
|||||||
{updateChecker && <UpdateChecker {...updateCheckerProps} />}
|
{updateChecker && <UpdateChecker {...updateCheckerProps} />}
|
||||||
|
|
||||||
<KeycloakProvider config={config.keycloak} loading={loading}>
|
<KeycloakProvider config={config.keycloak} loading={loading}>
|
||||||
{children}
|
<PermissionProvider config={config.permission} loading={loading}>
|
||||||
|
{children}
|
||||||
|
</PermissionProvider>
|
||||||
</KeycloakProvider>
|
</KeycloakProvider>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user