fix BiProvider
All checks were successful
Build and Deploy Next.js + Nginx Docker Image / build-and-deploy (push) Successful in 52s
Build and Deploy Next.js + Nginx Docker Image / deploy (push) Successful in 9s

This commit is contained in:
Mohamadzadeh 2026-08-19 14:18:41 +03:30
parent 3f5fd87742
commit 37f0b178bd
2 changed files with 91 additions and 91 deletions

172
dist/core.js vendored
View File

@ -1,31 +1,31 @@
import _ from "axios"; 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 $ 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 { 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 { 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 { 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 D from "next-query-params/pages";
import * as M from "use-query-params"; import le from "use-query-params";
import { Global as he } from "@emotion/react"; import { Global as he } from "@emotion/react";
let v = null, o = null, Y = null, W = !1; let W = null, o = null, Y = null, O = !1;
const Se = N(null), me = ({ url: e, realm: r, clientId: t }) => (o || (o = new $({ const Se = N(null), pe = ({ url: e, realm: r, clientId: t }) => (o || (o = new $({
url: e, url: e,
realm: r, realm: r,
clientId: t 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 = {} } = {}) => { })), 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 ?? v; const t = e ?? W;
if (!(t != null && t.url) || !(t != null && t.realm) || !(t != null && t.clientId)) if (!(t != null && t.url) || !(t != null && t.realm) || !(t != null && t.clientId))
throw new Error("Keycloak config is required."); throw new Error("Keycloak config is required.");
Fe(t); Fe(t);
const n = me(t); const n = pe(t);
return Y || (Y = n.init({ return Y || (Y = n.init({
onLoad: "login-required", onLoad: "login-required",
checkLoginIframe: !1, checkLoginIframe: !1,
flow: "implicit", flow: "implicit",
...r ...r
}).then((d) => (W = !0, d)).catch((d) => { }).then((d) => (O = !0, d)).catch((d) => {
throw W = !0, d; throw O = !0, d;
})), Y; })), Y;
}, qe = ({ }, qe = ({
children: e, children: e,
@ -33,15 +33,15 @@ const Se = N(null), me = ({ url: e, realm: r, clientId: t }) => (o || (o = new $
initOptions: t, initOptions: t,
loading: n = null loading: n = null
}) => { }) => {
const [d, h] = X(!1), [u, s] = X(!1), [a, m] = X(null), p = R(!1), i = K(() => { const [d, h] = X(!1), [u, s] = X(!1), [a, p] = X(null), m = R(!1), i = K(() => {
o && (s(!!o.authenticated), m(o.token ?? null)); o && (s(!!o.authenticated), p(o.token ?? null));
}, []); }, []);
z(() => (p.current = !0, H({ config: r, initOptions: t }).then((l) => { g(() => (m.current = !0, H({ config: r, initOptions: t }).then((l) => {
p.current && (s(!!l), m((o == null ? void 0 : o.token) ?? null), h(!0)); m.current && (s(!!l), p((o == null ? void 0 : o.token) ?? null), h(!0));
}).catch(() => { }).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]); }), [r, t]);
const c = K(() => o == null ? void 0 : o.login(), []), q = K((l) => o == null ? void 0 : o.logout(l), []), S = K( const c = K(() => o == null ? void 0 : o.login(), []), q = K((l) => o == null ? void 0 : o.logout(l), []), S = K(
async (l = 30) => { async (l = 30) => {
@ -68,7 +68,7 @@ const Ee = (e) => {
const { api: r } = e, t = _.create({ const { api: r } = e, t = _.create({
baseURL: r.baseUrl baseURL: r.baseUrl
}), n = async () => { }), n = async () => {
(!pe() || !G()) && await H(); (!me() || !G()) && await H();
}, d = !!e.keycloak, h = async (s) => { }, d = !!e.keycloak, h = async (s) => {
if (!d) return s; if (!d) return s;
await n(); await n();
@ -85,16 +85,16 @@ const Ee = (e) => {
} }
return s; return s;
}, u = async (s) => { }, u = async (s) => {
var m; var p;
const a = s.config; 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; a._retry = !0;
try { try {
await C(30); await C(30);
const p = x(); const m = x();
return a.headers = { return a.headers = {
...a.headers, ...a.headers,
Authorization: `Bearer ${p}` Authorization: `Bearer ${m}`
}, t(a); }, t(a);
} catch { } catch {
J({ redirectUri: window.location.origin }); J({ redirectUri: window.location.origin });
@ -120,14 +120,14 @@ const Ee = (e) => {
} }
} }
), be = async (e) => (await k.get(e)).data; ), be = async (e) => (await k.get(e)).data;
function O(e) { function v(e) {
return Array.isArray(e) ? e : [e]; return Array.isArray(e) ? e : [e];
} }
function Te(e) { function Te(e) {
return [...O(e), "list"]; return [...v(e), "list"];
} }
function U(e, r) { function U(e, r) {
return [...O(e), r]; return [...v(e), r];
} }
function Ke(e, r) { function Ke(e, r) {
if (!r) return e; if (!r) return e;
@ -141,11 +141,11 @@ function Ke(e, r) {
function Xe(e, r) { function Xe(e, r) {
return typeof e == "function" ? e(r == null ? void 0 : r.id, r) : e; return typeof e == "function" ? e(r == null ? void 0 : r.id, r) : e;
} }
function ze(e = {}) { function ge(e = {}) {
const { id: r, ...t } = e; const { id: r, ...t } = e;
return t; return t;
} }
function ge(e, r) { function ze(e, r) {
return `${e.replace(/\/$/, "")}/${r}`; return `${e.replace(/\/$/, "")}/${r}`;
} }
function xe(e) { function xe(e) {
@ -154,14 +154,14 @@ function xe(e) {
function fe(e, r) { function fe(e, r) {
return typeof e == "function" ? e(r) : e; return typeof e == "function" ? e(r) : e;
} }
function et({ function rt({
key: e, key: e,
url: r, url: r,
actions: t = {}, actions: t = {},
axiosInstance: n = k, axiosInstance: n = k,
fetcher: d = be fetcher: d = be
}) { }) {
const h = O(e), u = Te(e); const h = v(e), u = Te(e);
function s(i, c = {}) { function s(i, c = {}) {
return P({ return P({
queryKey: i ? [...u, i] : u, queryKey: i ? [...u, i] : u,
@ -172,19 +172,19 @@ function et({
function a(i, c = {}) { function a(i, c = {}) {
return P({ return P({
queryKey: U(e, i), queryKey: U(e, i),
queryFn: () => d(ge(r, i)), queryFn: () => d(ze(r, i)),
enabled: !!i, enabled: !!i,
...c ...c
}); });
} }
function m(i, c = {}) { function p(i, c = {}) {
const q = re(), S = t[i]; const q = re(), S = t[i];
if (!S) if (!S)
throw new Error(`Action "${i}" is not defined.`); throw new Error(`Action "${i}" is not defined.`);
return ne({ return ne({
mutationKey: [...h, i], mutationKey: [...h, i],
mutationFn: async (F = {}) => { 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; let y;
if (l === "get") if (l === "get")
y = await n.get( y = await n.get(
@ -195,12 +195,12 @@ function et({
} : E } : E
); );
else if (l === "delete") { else if (l === "delete") {
const g = E && Object.keys(E).length > 0; const z = E && Object.keys(E).length > 0;
y = await n.delete( y = await n.delete(
Z, Z,
T || g ? { T || z ? {
...T || {}, ...T || {},
...g ? { data: E } : {} ...z ? { data: E } : {}
} : void 0 } : void 0
); );
} else } else
@ -222,21 +222,21 @@ function et({
queryKey: U(e, T) queryKey: U(e, T)
}); });
const E = typeof S.invalidateKeys == "function" ? S.invalidateKeys(l, Z) : S.invalidateKeys; const E = typeof S.invalidateKeys == "function" ? S.invalidateKeys(l, Z) : S.invalidateKeys;
E == null || E.forEach((g) => { E == null || E.forEach((z) => {
q.invalidateQueries({ queryKey: g }); q.invalidateQueries({ queryKey: z });
}), (y = c.onSuccess) == null || y.call(c, ...F); }), (y = c.onSuccess) == null || y.call(c, ...F);
}, },
...c ...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 { return {
key: h, key: h,
listKey: u, listKey: u,
useGet: s, useGet: s,
useItem: a, useItem: a,
useAction: m, useAction: p,
...p ...m
}; };
} }
const Q = N(null), w = "permissions", Be = (e) => (e == null ? void 0 : e.storageKey) || w, we = ({ 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( const h = Be(t), [u, s] = X(
() => Ye(h) () => Ye(h)
), { data: a, isLoading: m, error: p } = Ae(t), i = a ?? u; ), { data: a, isLoading: p, error: m } = Ae(t), i = a ?? u;
z(() => { g(() => {
a && (Pe(h, a), s(a)); a && (Pe(h, a), s(a));
}, [a, h]); }, [a, h]);
const c = f( const c = f(
() => ve(i), () => We(i),
[i] [i]
), q = K( ), q = K(
(l = "") => We(c, l), (l = "") => Oe(c, l),
[c] [c]
), S = K((l = "") => !q(l), [q]), F = f( ), 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, can: q,
cannot: S, cannot: S,
permissions: i, permissions: i,
isLoading: m, isLoading: p,
error: 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) => { }, Ye = (e = w) => {
if (!(typeof window > "u")) if (!(typeof window > "u"))
try { 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)); localStorage.setItem(e, JSON.stringify(r));
} catch { } catch {
} }
}, tt = (e = w) => { }, nt = (e = w) => {
if (!(typeof window > "u")) if (!(typeof window > "u"))
try { try {
localStorage.removeItem(e); localStorage.removeItem(e);
} catch { } 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 (!r) return !1;
if (e.has(r) || [...e].some((n) => n.startsWith(r))) return !0; if (e.has(r) || [...e].some((n) => n.startsWith(r))) return !0;
let t = r; let t = r;
@ -300,7 +300,7 @@ const Q = N(null), w = "permissions", Be = (e) => (e == null ? void 0 : e.storag
}, j = { }, j = {
all: ["permissions"], all: ["permissions"],
list: (e) => [...j.all, e] list: (e) => [...j.all, e]
}, Oe = async (e) => { }, ve = 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 r = x(), t = new URL(e.url); 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; return e;
}, Ae = (e) => P({ }, Ae = (e) => P({
queryKey: j.list(e == null ? void 0 : e.clientId), 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(), enabled: !!(e != null && e.url) && !!(e != null && e.clientId) && G(),
staleTime: 1 / 0, staleTime: 1 / 0,
refetchOnWindowFocus: !1, refetchOnWindowFocus: !1,
refetchOnReconnect: !1 refetchOnReconnect: !1
}), rt = ({ }), ot = ({
perm: e, perm: e,
children: r, children: r,
fallback: t = /* @__PURE__ */ b("div", { children: "You are not allowed to do this" }) fallback: t = /* @__PURE__ */ b("div", { children: "You are not allowed to do this" })
}) => { }) => {
const { can: n } = A(); const { can: n } = A();
return n(e) ? r : t; return n(e) ? r : t;
}, nt = ({ children: e }) => { }, it = ({ children: e }) => {
const { can: r, permissions: t } = A(); const { can: r, permissions: t } = A();
return t && r("admin") ? e : null; return t && r("admin") ? e : null;
}, ot = ({ children: e, forceNoAccess: r = !1 }) => { }, st = ({ children: e, forceNoAccess: r = !1 }) => {
const { can: t, isLoading: n } = A(); const { can: t, isLoading: n } = A();
return z(() => { return g(() => {
n || (r || !t("panel_access")) && J(); n || (r || !t("panel_access")) && J();
}, [n, t, r]), e; }, [n, t, r]), e;
}; };
function De() { function Me() {
const [e, r] = X(!1), t = R(null); const [e, r] = X(!1), t = R(null);
return z(() => { return g(() => {
if (process.env.NODE_ENV !== "production") return; if (process.env.NODE_ENV !== "production") return;
let n; let n;
const d = async () => { const d = async () => {
@ -391,7 +391,7 @@ function De() {
} }
) : null; ) : null;
} }
const Me = new oe({ const De = new oe({
defaultOptions: { defaultOptions: {
queries: { queries: {
retry: 1, retry: 1,
@ -435,10 +435,10 @@ const Me = new oe({
} }
` `
} }
); ), { QueryParamProvider: Ve } = le;
var V; var V;
const Ve = M.QueryParamProvider ?? ((V = M.default) == null ? void 0 : V.QueryParamProvider), L = "__UIKIT_REMOTE_DEPS__"; const Ne = ((V = D) == null ? void 0 : V.default) ?? D, L = "__UIKIT_REMOTE_DEPS__";
function Ne({ theme: e, chakraProviderProps: r } = {}) { function Re({ theme: e, chakraProviderProps: r } = {}) {
if (typeof window > "u") return; if (typeof window > "u") return;
const t = window[L] || {}; const t = window[L] || {};
window[L] = { window[L] = {
@ -454,7 +454,7 @@ function Ne({ theme: e, chakraProviderProps: r } = {}) {
} }
}; };
} }
function it({ function at({
children: e, children: e,
apiBaseUrl: r, apiBaseUrl: r,
keycloakClientId: t, keycloakClientId: t,
@ -464,14 +464,14 @@ function it({
updateCheckerProps: u, updateCheckerProps: u,
keycloakUrl: s = "https://auth.ibagher.ir", keycloakUrl: s = "https://auth.ibagher.ir",
keycloakRealm: a = "bi", keycloakRealm: a = "bi",
permissionUrl: m = "https://api.d.aiengines.ir/user_api/v1/permissions/list", permissionUrl: p = "https://api.d.aiengines.ir/user_api/v1/permissions/list",
keycloakEnabled: p, keycloakEnabled: m,
permissionEnabled: i, permissionEnabled: i,
theme: c = Ue, theme: c = Ue,
remoteUiEnabled: q = !0, remoteUiEnabled: q = !0,
remoteUiChakraProviderProps: S 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: { api: {
baseUrl: r || "" baseUrl: r || ""
@ -482,7 +482,7 @@ function it({
clientId: t clientId: t
} : null, } : null,
permission: T ? { permission: T ? {
url: m, url: p,
clientId: n clientId: n
} : null } : null
}), }),
@ -493,51 +493,51 @@ function it({
s, s,
a, a,
t, t,
m, p,
n n
] ]
); );
if (z(() => { if (g(() => {
l(!0); l(!0);
}, []), z(() => { }, []), g(() => {
F && Ze(E); F && Ze(E);
}, [F, E]), !F) }, [F, E]), !F)
return null; return null;
q && Ne({ q && Re({
theme: c, theme: c,
chakraProviderProps: S chakraProviderProps: S
}); });
let y = e; 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__ */ b(Le, {}),
/* @__PURE__ */ D(ie, { client: Me, children: [ /* @__PURE__ */ M(ie, { client: De, children: [
h && /* @__PURE__ */ b(De, { ...u }), h && /* @__PURE__ */ b(Me, { ...u }),
/* @__PURE__ */ b(Ve, { adapter: le, children: y }) /* @__PURE__ */ b(Ve, { adapter: Ne, children: y })
] }) ] })
] }); ] });
} }
export { export {
nt as AdminGuard, it as AdminGuard,
it as BiProvider, at as BiProvider,
rt as Can, ot as Can,
qe as KeycloakProvider, qe as KeycloakProvider,
ot as PanelAccessGuard, st as PanelAccessGuard,
we as PermissionProvider, we as PermissionProvider,
k as api, k as api,
We as checkPermission, Oe as checkPermission,
tt as clearCachedPermissions, nt as clearCachedPermissions,
Ze as configureApi, Ze as configureApi,
et as createApi, rt as createApi,
ve as createPermissionSet, We as createPermissionSet,
be as fetcher, be as fetcher,
ye as getApi, ye as getApi,
Ye as getCachedPermissions, Ye as getCachedPermissions,
x as getKeycloakToken, x as getKeycloakToken,
Oe as getPermissions, ve as getPermissions,
H as initKeycloak, H as initKeycloak,
G as isKeycloakAuthenticated, G as isKeycloakAuthenticated,
pe as isKeycloakInitialized, me as isKeycloakInitialized,
$e as loginKeycloak, tt as loginKeycloak,
J as logoutKeycloak, J as logoutKeycloak,
j as permissionKeys, j as permissionKeys,
Pe as setCachedPermissions, Pe as setCachedPermissions,

View File

@ -2,8 +2,8 @@ import React, { useEffect, useMemo, useState } from "react";
import { createRoot } from "react-dom/client"; import { createRoot } from "react-dom/client";
import { Badge, ChakraProvider, Spinner } from "@chakra-ui/react"; import { Badge, ChakraProvider, Spinner } from "@chakra-ui/react";
import { QueryClientProvider } from "@tanstack/react-query"; import { QueryClientProvider } from "@tanstack/react-query";
import NextAdapterPages from "next-query-params/pages"; import nextAdapterPagesModule from "next-query-params/pages";
import * as useQueryParamsModule from "use-query-params"; import useQueryParamsModule from "use-query-params";
import { KeycloakProvider } from "./keycloak.jsx"; import { KeycloakProvider } from "./keycloak.jsx";
import { PermissionProvider } from "./permission.jsx"; import { PermissionProvider } from "./permission.jsx";
import { UpdateChecker } from "./UpdateChecker.jsx"; import { UpdateChecker } from "./UpdateChecker.jsx";
@ -11,9 +11,9 @@ import { configureApi } from "./api.js";
import { queryClient } from "./query.js"; import { queryClient } from "./query.js";
import { Fonts, theme as defaultTheme } from "./style.jsx"; import { Fonts, theme as defaultTheme } from "./style.jsx";
const QueryParamProvider = const { QueryParamProvider } = useQueryParamsModule;
useQueryParamsModule.QueryParamProvider ?? const NextAdapterPages =
useQueryParamsModule.default?.QueryParamProvider; nextAdapterPagesModule?.default ?? nextAdapterPagesModule;
const REMOTE_DEPS_KEY = "__UIKIT_REMOTE_DEPS__"; const REMOTE_DEPS_KEY = "__UIKIT_REMOTE_DEPS__";
function setupBiRemoteUiDeps({ theme, chakraProviderProps } = {}) { function setupBiRemoteUiDeps({ theme, chakraProviderProps } = {}) {