From 37f0b178bdd6bf625f80429e6fa1661d945bbe65 Mon Sep 17 00:00:00 2001 From: Mohamadzadeh <7796733@gmail.com> Date: Wed, 19 Aug 2026 14:18:41 +0330 Subject: [PATCH] fix BiProvider --- dist/core.js | 172 ++++++++++++++++++++-------------------- src/core/BiProvider.jsx | 10 +-- 2 files changed, 91 insertions(+), 91 deletions(-) diff --git a/dist/core.js b/dist/core.js index 6607090..10bf5a7 100644 --- a/dist/core.js +++ b/dist/core.js @@ -1,31 +1,31 @@ import _ from "axios"; -import { jsx as b, jsxs as D } from "react/jsx-runtime"; +import { jsx as b, jsxs as M } from "react/jsx-runtime"; import $ from "keycloak-js"; -import ee, { createContext as N, useState as X, useRef as R, useCallback as K, useEffect as z, useMemo as f, useContext as te } from "react"; +import ee, { createContext as N, useState as X, useRef as R, useCallback as K, useEffect as g, useMemo as f, useContext as te } from "react"; import { useQueryClient as re, useMutation as ne, useQuery as P, QueryClient as oe, QueryClientProvider as ie } from "@tanstack/react-query"; import { createRoot as se } from "react-dom/client"; import { extendTheme as ae, withDefaultColorScheme as ue, ChakraProvider as I, Spinner as de, Badge as ce } from "@chakra-ui/react"; -import le from "next-query-params/pages"; -import * as M from "use-query-params"; +import D from "next-query-params/pages"; +import le from "use-query-params"; import { Global as he } from "@emotion/react"; -let v = null, o = null, Y = null, W = !1; -const Se = N(null), me = ({ url: e, realm: r, clientId: t }) => (o || (o = new $({ +let W = null, o = null, Y = null, O = !1; +const Se = N(null), pe = ({ url: e, realm: r, clientId: t }) => (o || (o = new $({ url: e, realm: r, clientId: t -})), o), Fe = (e) => (v = e, v), pe = () => W, G = () => !!(o != null && o.authenticated), x = () => (o == null ? void 0 : o.token) ?? null, C = async (e = 30) => o ? o.updateToken(e) : !1, J = (e) => o == null ? void 0 : o.logout(e), $e = (e) => o == null ? void 0 : o.login(e), H = ({ config: e, initOptions: r = {} } = {}) => { - const t = e ?? v; +})), o), Fe = (e) => (W = e, W), me = () => O, G = () => !!(o != null && o.authenticated), x = () => (o == null ? void 0 : o.token) ?? null, C = async (e = 30) => o ? o.updateToken(e) : !1, J = (e) => o == null ? void 0 : o.logout(e), tt = (e) => o == null ? void 0 : o.login(e), H = ({ config: e, initOptions: r = {} } = {}) => { + const t = e ?? W; if (!(t != null && t.url) || !(t != null && t.realm) || !(t != null && t.clientId)) throw new Error("Keycloak config is required."); Fe(t); - const n = me(t); + const n = pe(t); return Y || (Y = n.init({ onLoad: "login-required", checkLoginIframe: !1, flow: "implicit", ...r - }).then((d) => (W = !0, d)).catch((d) => { - throw W = !0, d; + }).then((d) => (O = !0, d)).catch((d) => { + throw O = !0, d; })), Y; }, qe = ({ children: e, @@ -33,15 +33,15 @@ const Se = N(null), me = ({ url: e, realm: r, clientId: t }) => (o || (o = new $ initOptions: t, loading: n = null }) => { - const [d, h] = X(!1), [u, s] = X(!1), [a, m] = X(null), p = R(!1), i = K(() => { - o && (s(!!o.authenticated), m(o.token ?? null)); + const [d, h] = X(!1), [u, s] = X(!1), [a, p] = X(null), m = R(!1), i = K(() => { + o && (s(!!o.authenticated), p(o.token ?? null)); }, []); - z(() => (p.current = !0, H({ config: r, initOptions: t }).then((l) => { - p.current && (s(!!l), m((o == null ? void 0 : o.token) ?? null), h(!0)); + g(() => (m.current = !0, H({ config: r, initOptions: t }).then((l) => { + m.current && (s(!!l), p((o == null ? void 0 : o.token) ?? null), h(!0)); }).catch(() => { - p.current && (s(!1), m(null), h(!0)); + m.current && (s(!1), p(null), h(!0)); }), () => { - p.current = !1; + m.current = !1; }), [r, t]); const c = K(() => o == null ? void 0 : o.login(), []), q = K((l) => o == null ? void 0 : o.logout(l), []), S = K( async (l = 30) => { @@ -68,7 +68,7 @@ const Ee = (e) => { const { api: r } = e, t = _.create({ baseURL: r.baseUrl }), n = async () => { - (!pe() || !G()) && await H(); + (!me() || !G()) && await H(); }, d = !!e.keycloak, h = async (s) => { if (!d) return s; await n(); @@ -85,16 +85,16 @@ const Ee = (e) => { } return s; }, u = async (s) => { - var m; + var p; const a = s.config; - if (((m = s == null ? void 0 : s.response) == null ? void 0 : m.status) === 401 && !(a != null && a._retry)) { + if (((p = s == null ? void 0 : s.response) == null ? void 0 : p.status) === 401 && !(a != null && a._retry)) { a._retry = !0; try { await C(30); - const p = x(); + const m = x(); return a.headers = { ...a.headers, - Authorization: `Bearer ${p}` + Authorization: `Bearer ${m}` }, t(a); } catch { J({ redirectUri: window.location.origin }); @@ -120,14 +120,14 @@ const Ee = (e) => { } } ), be = async (e) => (await k.get(e)).data; -function O(e) { +function v(e) { return Array.isArray(e) ? e : [e]; } function Te(e) { - return [...O(e), "list"]; + return [...v(e), "list"]; } function U(e, r) { - return [...O(e), r]; + return [...v(e), r]; } function Ke(e, r) { if (!r) return e; @@ -141,11 +141,11 @@ function Ke(e, r) { function Xe(e, r) { return typeof e == "function" ? e(r == null ? void 0 : r.id, r) : e; } -function ze(e = {}) { +function ge(e = {}) { const { id: r, ...t } = e; return t; } -function ge(e, r) { +function ze(e, r) { return `${e.replace(/\/$/, "")}/${r}`; } function xe(e) { @@ -154,14 +154,14 @@ function xe(e) { function fe(e, r) { return typeof e == "function" ? e(r) : e; } -function et({ +function rt({ key: e, url: r, actions: t = {}, axiosInstance: n = k, fetcher: d = be }) { - const h = O(e), u = Te(e); + const h = v(e), u = Te(e); function s(i, c = {}) { return P({ queryKey: i ? [...u, i] : u, @@ -172,19 +172,19 @@ function et({ function a(i, c = {}) { return P({ queryKey: U(e, i), - queryFn: () => d(ge(r, i)), + queryFn: () => d(ze(r, i)), enabled: !!i, ...c }); } - function m(i, c = {}) { + function p(i, c = {}) { const q = re(), S = t[i]; if (!S) throw new Error(`Action "${i}" is not defined.`); return ne({ mutationKey: [...h, i], mutationFn: async (F = {}) => { - const l = S.method || "post", Z = Xe(S.url || r, F), T = fe(S.requestConfig, F), E = S.body ? S.body(F) : S.sendRawPayload ? F : ze(F); + const l = S.method || "post", Z = Xe(S.url || r, F), T = fe(S.requestConfig, F), E = S.body ? S.body(F) : S.sendRawPayload ? F : ge(F); let y; if (l === "get") y = await n.get( @@ -195,12 +195,12 @@ function et({ } : E ); else if (l === "delete") { - const g = E && Object.keys(E).length > 0; + const z = E && Object.keys(E).length > 0; y = await n.delete( Z, - T || g ? { + T || z ? { ...T || {}, - ...g ? { data: E } : {} + ...z ? { data: E } : {} } : void 0 ); } else @@ -222,21 +222,21 @@ function et({ queryKey: U(e, T) }); const E = typeof S.invalidateKeys == "function" ? S.invalidateKeys(l, Z) : S.invalidateKeys; - E == null || E.forEach((g) => { - q.invalidateQueries({ queryKey: g }); + E == null || E.forEach((z) => { + q.invalidateQueries({ queryKey: z }); }), (y = c.onSuccess) == null || y.call(c, ...F); }, ...c }); } - const p = Object.keys(t).reduce((i, c) => (i[xe(c)] = (q = {}) => m(c, q), i), {}); + const m = Object.keys(t).reduce((i, c) => (i[xe(c)] = (q = {}) => p(c, q), i), {}); return { key: h, listKey: u, useGet: s, useItem: a, - useAction: m, - ...p + useAction: p, + ...m }; } const Q = N(null), w = "permissions", Be = (e) => (e == null ? void 0 : e.storageKey) || w, we = ({ @@ -248,15 +248,15 @@ const Q = N(null), w = "permissions", Be = (e) => (e == null ? void 0 : e.storag }) => { const h = Be(t), [u, s] = X( () => Ye(h) - ), { data: a, isLoading: m, error: p } = Ae(t), i = a ?? u; - z(() => { + ), { data: a, isLoading: p, error: m } = Ae(t), i = a ?? u; + g(() => { a && (Pe(h, a), s(a)); }, [a, h]); const c = f( - () => ve(i), + () => We(i), [i] ), q = K( - (l = "") => We(c, l), + (l = "") => Oe(c, l), [c] ), S = K((l = "") => !q(l), [q]), F = f( () => ({ @@ -264,12 +264,12 @@ const Q = N(null), w = "permissions", Be = (e) => (e == null ? void 0 : e.storag can: q, cannot: S, permissions: i, - isLoading: m, - error: p + isLoading: p, + error: m }), - [e, q, S, i, m, p] + [e, q, S, i, p, m] ); - return p && !i ? d : m && !i ? n : /* @__PURE__ */ b(Q.Provider, { value: F, children: r }); + return m && !i ? d : p && !i ? n : /* @__PURE__ */ b(Q.Provider, { value: F, children: r }); }, Ye = (e = w) => { if (!(typeof window > "u")) try { @@ -284,13 +284,13 @@ const Q = N(null), w = "permissions", Be = (e) => (e == null ? void 0 : e.storag localStorage.setItem(e, JSON.stringify(r)); } catch { } -}, tt = (e = w) => { +}, nt = (e = w) => { if (!(typeof window > "u")) try { localStorage.removeItem(e); } catch { } -}, ve = (e) => e ? new Set(e.map((r) => r.name)) : /* @__PURE__ */ new Set(), We = (e, r = "") => { +}, We = (e) => e ? new Set(e.map((r) => r.name)) : /* @__PURE__ */ new Set(), Oe = (e, r = "") => { if (!r) return !1; if (e.has(r) || [...e].some((n) => n.startsWith(r))) return !0; let t = r; @@ -300,7 +300,7 @@ const Q = N(null), w = "permissions", Be = (e) => (e == null ? void 0 : e.storag }, j = { all: ["permissions"], list: (e) => [...j.all, e] -}, Oe = async (e) => { +}, ve = async (e) => { if (!(e != null && e.url) || !(e != null && e.clientId)) throw new Error("Permission config requires url and clientId."); const r = x(), t = new URL(e.url); @@ -321,30 +321,30 @@ const Q = N(null), w = "permissions", Be = (e) => (e == null ? void 0 : e.storag return e; }, Ae = (e) => P({ queryKey: j.list(e == null ? void 0 : e.clientId), - queryFn: () => Oe(e), + queryFn: () => ve(e), enabled: !!(e != null && e.url) && !!(e != null && e.clientId) && G(), staleTime: 1 / 0, refetchOnWindowFocus: !1, refetchOnReconnect: !1 -}), rt = ({ +}), ot = ({ perm: e, children: r, fallback: t = /* @__PURE__ */ b("div", { children: "You are not allowed to do this" }) }) => { const { can: n } = A(); return n(e) ? r : t; -}, nt = ({ children: e }) => { +}, it = ({ children: e }) => { const { can: r, permissions: t } = A(); return t && r("admin") ? e : null; -}, ot = ({ children: e, forceNoAccess: r = !1 }) => { +}, st = ({ children: e, forceNoAccess: r = !1 }) => { const { can: t, isLoading: n } = A(); - return z(() => { + return g(() => { n || (r || !t("panel_access")) && J(); }, [n, t, r]), e; }; -function De() { +function Me() { const [e, r] = X(!1), t = R(null); - return z(() => { + return g(() => { if (process.env.NODE_ENV !== "production") return; let n; const d = async () => { @@ -391,7 +391,7 @@ function De() { } ) : null; } -const Me = new oe({ +const De = new oe({ defaultOptions: { queries: { retry: 1, @@ -435,10 +435,10 @@ const Me = new oe({ } ` } -); +), { QueryParamProvider: Ve } = le; var V; -const Ve = M.QueryParamProvider ?? ((V = M.default) == null ? void 0 : V.QueryParamProvider), L = "__UIKIT_REMOTE_DEPS__"; -function Ne({ theme: e, chakraProviderProps: r } = {}) { +const Ne = ((V = D) == null ? void 0 : V.default) ?? D, L = "__UIKIT_REMOTE_DEPS__"; +function Re({ theme: e, chakraProviderProps: r } = {}) { if (typeof window > "u") return; const t = window[L] || {}; window[L] = { @@ -454,7 +454,7 @@ function Ne({ theme: e, chakraProviderProps: r } = {}) { } }; } -function it({ +function at({ children: e, apiBaseUrl: r, keycloakClientId: t, @@ -464,14 +464,14 @@ function it({ updateCheckerProps: u, keycloakUrl: s = "https://auth.ibagher.ir", keycloakRealm: a = "bi", - permissionUrl: m = "https://api.d.aiengines.ir/user_api/v1/permissions/list", - keycloakEnabled: p, + permissionUrl: p = "https://api.d.aiengines.ir/user_api/v1/permissions/list", + keycloakEnabled: m, permissionEnabled: i, theme: c = Ue, remoteUiEnabled: q = !0, remoteUiChakraProviderProps: S }) { - const [F, l] = X(!1), Z = p ?? !!t, T = i ?? !!n, E = f( + const [F, l] = X(!1), Z = m ?? !!t, T = i ?? !!n, E = f( () => ({ api: { baseUrl: r || "" @@ -482,7 +482,7 @@ function it({ clientId: t } : null, permission: T ? { - url: m, + url: p, clientId: n } : null }), @@ -493,51 +493,51 @@ function it({ s, a, t, - m, + p, n ] ); - if (z(() => { + if (g(() => { l(!0); - }, []), z(() => { + }, []), g(() => { F && Ze(E); }, [F, E]), !F) return null; - q && Ne({ + q && Re({ theme: c, chakraProviderProps: S }); let y = e; - return T && (y = /* @__PURE__ */ b(we, { config: E.permission, loading: d, children: y })), Z && (y = /* @__PURE__ */ b(qe, { config: E.keycloak, loading: d, children: y })), /* @__PURE__ */ D(I, { theme: c, children: [ + return T && (y = /* @__PURE__ */ b(we, { config: E.permission, loading: d, children: y })), Z && (y = /* @__PURE__ */ b(qe, { config: E.keycloak, loading: d, children: y })), /* @__PURE__ */ M(I, { theme: c, children: [ /* @__PURE__ */ b(Le, {}), - /* @__PURE__ */ D(ie, { client: Me, children: [ - h && /* @__PURE__ */ b(De, { ...u }), - /* @__PURE__ */ b(Ve, { adapter: le, children: y }) + /* @__PURE__ */ M(ie, { client: De, children: [ + h && /* @__PURE__ */ b(Me, { ...u }), + /* @__PURE__ */ b(Ve, { adapter: Ne, children: y }) ] }) ] }); } export { - nt as AdminGuard, - it as BiProvider, - rt as Can, + it as AdminGuard, + at as BiProvider, + ot as Can, qe as KeycloakProvider, - ot as PanelAccessGuard, + st as PanelAccessGuard, we as PermissionProvider, k as api, - We as checkPermission, - tt as clearCachedPermissions, + Oe as checkPermission, + nt as clearCachedPermissions, Ze as configureApi, - et as createApi, - ve as createPermissionSet, + rt as createApi, + We as createPermissionSet, be as fetcher, ye as getApi, Ye as getCachedPermissions, x as getKeycloakToken, - Oe as getPermissions, + ve as getPermissions, H as initKeycloak, G as isKeycloakAuthenticated, - pe as isKeycloakInitialized, - $e as loginKeycloak, + me as isKeycloakInitialized, + tt as loginKeycloak, J as logoutKeycloak, j as permissionKeys, Pe as setCachedPermissions, diff --git a/src/core/BiProvider.jsx b/src/core/BiProvider.jsx index 6b3b80c..22073b6 100644 --- a/src/core/BiProvider.jsx +++ b/src/core/BiProvider.jsx @@ -2,8 +2,8 @@ import React, { useEffect, useMemo, useState } from "react"; import { createRoot } from "react-dom/client"; import { Badge, ChakraProvider, Spinner } from "@chakra-ui/react"; import { QueryClientProvider } from "@tanstack/react-query"; -import NextAdapterPages from "next-query-params/pages"; -import * as useQueryParamsModule from "use-query-params"; +import nextAdapterPagesModule from "next-query-params/pages"; +import useQueryParamsModule from "use-query-params"; import { KeycloakProvider } from "./keycloak.jsx"; import { PermissionProvider } from "./permission.jsx"; import { UpdateChecker } from "./UpdateChecker.jsx"; @@ -11,9 +11,9 @@ import { configureApi } from "./api.js"; import { queryClient } from "./query.js"; import { Fonts, theme as defaultTheme } from "./style.jsx"; -const QueryParamProvider = - useQueryParamsModule.QueryParamProvider ?? - useQueryParamsModule.default?.QueryParamProvider; +const { QueryParamProvider } = useQueryParamsModule; +const NextAdapterPages = + nextAdapterPagesModule?.default ?? nextAdapterPagesModule; const REMOTE_DEPS_KEY = "__UIKIT_REMOTE_DEPS__"; function setupBiRemoteUiDeps({ theme, chakraProviderProps } = {}) {