@ukpc-lib/react 0.13.1-dev.20 → 0.13.1-dev.21

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.
@@ -2883,34 +2883,38 @@ const $Y = da.interceptors.response.use(
2883
2883
  };
2884
2884
  }, [e]), r;
2885
2885
  }, bT = ir({}), jY = (t) => {
2886
- const { children: e, baseUrl: n, axiosInstance: r } = t, i = new URL(n).origin, o = kM({ axiosInstance: r, baseUrl: n }), a = DM({
2886
+ const { children: e, baseUrl: n, axiosInstance: r, requiredPermissions: i = [] } = t, o = new URL(n).origin, a = kM({ axiosInstance: r, baseUrl: n }), c = DM({
2887
2887
  axiosInstance: r,
2888
2888
  baseUrl: n
2889
2889
  });
2890
- function c() {
2891
- window.location.href = `${i}/authentication/login`;
2892
- }
2893
2890
  function f() {
2894
- window.location.href = `${i}/authentication/logout`;
2891
+ window.location.href = `${o}/authentication/login`;
2895
2892
  }
2896
- return o != null && o.isFetching ? /* @__PURE__ */ Me(
2897
- EI,
2898
- {
2899
- container: !0,
2900
- justifyContent: "center",
2901
- alignItems: "center",
2902
- sx: { minHeight: "100vh" },
2903
- children: /* @__PURE__ */ Me(kI, {})
2904
- }
2905
- ) : /* @__PURE__ */ Me(
2893
+ function p() {
2894
+ window.location.href = `${o}/authentication/logout`;
2895
+ }
2896
+ if (a != null && a.isFetching)
2897
+ return /* @__PURE__ */ Me(
2898
+ EI,
2899
+ {
2900
+ container: !0,
2901
+ justifyContent: "center",
2902
+ alignItems: "center",
2903
+ sx: { minHeight: "100vh" },
2904
+ children: /* @__PURE__ */ Me(kI, {})
2905
+ }
2906
+ );
2907
+ const w = (c == null ? void 0 : c.data) || [], g = i.length === 0 || i.some((T) => w.includes(T));
2908
+ return /* @__PURE__ */ Me(
2906
2909
  bT.Provider,
2907
2910
  {
2908
2911
  value: {
2909
- user: o == null ? void 0 : o.data,
2910
- login: c,
2911
- logout: f,
2912
- isFetching: o.isFetching,
2913
- permissions: a == null ? void 0 : a.data
2912
+ user: a == null ? void 0 : a.data,
2913
+ login: f,
2914
+ logout: p,
2915
+ isFetching: a.isFetching,
2916
+ permissions: c == null ? void 0 : c.data,
2917
+ hasPermission: g
2914
2918
  },
2915
2919
  children: e
2916
2920
  }
@@ -32,9 +32,12 @@ type AuthContext = {
32
32
  login: () => void;
33
33
  logout: () => void;
34
34
  permissions: string[];
35
+ hasPermission: boolean;
35
36
  };
36
37
  export declare const AuthContext: import('react').Context<AuthContext>;
37
- type AuthProviderProps = PropsWithChildren<UseUserProps>;
38
+ type AuthProviderProps = PropsWithChildren<UseUserProps> & {
39
+ requiredPermissions?: string[];
40
+ };
38
41
  export declare const AuthProvider: (props: AuthProviderProps) => import("react/jsx-runtime").JSX.Element;
39
42
  export declare const useAuth: () => AuthContext;
40
43
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.esm2017-Bx66LwxI.cjs"),h=require("axios"),c=require("react"),l=require("react-router-dom"),u=require("react/jsx-runtime");require("@r2wc/react-to-web-component");require("@mui/material");const m=n=>{const[s,r]=c.useState([]);return c.useEffect(()=>{h.get(`${n}/user-management/api/v1/users/my-account/permissions`,{withCredentials:!0}).then(o=>r(o.data)).catch(o=>{console.error("Getting user permission error:",o)})},[n]),s},f=n=>{const s=l.useNavigate(),r=l.useLocation();console.log(" useSyncRouter.tsx ~ location1:",r,window.location.pathname);const o=(t=r)=>(n||"")+t.pathname+t.search+t.hash;if(c.useEffect(()=>{const t={changeRoute:i=>{const a=o();if(typeof i=="string"&&a!==i){console.log(" useSyncRouter.tsx ~ location2:",a,i);const g=n&&i.startsWith(n)?i.substring(n.length):i;s(g)}}};window.MicrofeBridge=t},[s,r]),c.useEffect(()=>{var i,a;const t=o();console.log("fullPath1",window.location.pathname,t),(a=(i=window.parent)==null?void 0:i.HostBridge)==null||a.childRouteChange(t)},[r]),window.self===window.top){console.log("useSyncRouter: Navigate to /app path"),window.location.href=window.location.href.replace(window.origin,`${window.origin}/app`);return}};function w({open:n,disabled:s}){c.useMemo(()=>{var r,o,t,i;s||(n?(o=(r=window.top)==null?void 0:r.HostBridge)==null||o.openBackdrop(!0):(i=(t=window.top)==null?void 0:t.HostBridge)==null||i.openBackdrop(!1))},[n,s])}const d=n=>(s,r)=>{const o=m(n);return r?s.every(t=>o==null?void 0:o.includes(t)):s.some(t=>o==null?void 0:o.includes(t))},P=({baseUrl:n,accessWith:s,requireAll:r,children:o})=>d(n)(s,r)?u.jsx(u.Fragment,{children:o}):null,p=({accessWith:n,requireAll:s,baseUrl:r,unAuthorizedPath:o,children:t})=>d(r)(n,s)?u.jsx(u.Fragment,{children:t}):u.jsx(l.Navigate,{to:o,replace:!0});exports.AuthContext=e.AuthContext;exports.AuthProvider=e.AuthProvider;exports.ERROR_MESSAGE=e.ERROR_MESSAGE;exports.SaasThemeProvider=e.SaasThemeProvider;exports.TranslationProvider=e.TranslationProvider;exports.axiosInstance=e.axiosInstance;exports.color=e.color;exports.createCustomTheme=e.createCustomTheme;exports.handleErrorAxios=e.handleErrorAxios;exports.login=e.login;exports.logout=e.logout;exports.responseInterceptor=e.responseInterceptor;exports.search=e.search;exports.setFavicon=e.setFavicon;exports.setShellBackdrop=e.setShellBackdrop;exports.translate=e.translate;exports.translationConfig=e.translationConfig;exports.useAuth=e.useAuth;exports.useCustomTranslation=e.useCustomTranslation;exports.useTheme=e.useTheme;exports.useTranslation=e.useTranslation$1;exports.HasPermission=P;exports.PermissionRoute=p;exports.getUseHasPermission=d;exports.useGetPermission=m;exports.useSyncBackdrop=w;exports.useSyncRouter=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.esm2017-C_B_8-Rt.cjs"),h=require("axios"),c=require("react"),l=require("react-router-dom"),u=require("react/jsx-runtime");require("@r2wc/react-to-web-component");require("@mui/material");const m=n=>{const[s,r]=c.useState([]);return c.useEffect(()=>{h.get(`${n}/user-management/api/v1/users/my-account/permissions`,{withCredentials:!0}).then(o=>r(o.data)).catch(o=>{console.error("Getting user permission error:",o)})},[n]),s},f=n=>{const s=l.useNavigate(),r=l.useLocation();console.log(" useSyncRouter.tsx ~ location1:",r,window.location.pathname);const o=(t=r)=>(n||"")+t.pathname+t.search+t.hash;if(c.useEffect(()=>{const t={changeRoute:i=>{const a=o();if(typeof i=="string"&&a!==i){console.log(" useSyncRouter.tsx ~ location2:",a,i);const g=n&&i.startsWith(n)?i.substring(n.length):i;s(g)}}};window.MicrofeBridge=t},[s,r]),c.useEffect(()=>{var i,a;const t=o();console.log("fullPath1",window.location.pathname,t),(a=(i=window.parent)==null?void 0:i.HostBridge)==null||a.childRouteChange(t)},[r]),window.self===window.top){console.log("useSyncRouter: Navigate to /app path"),window.location.href=window.location.href.replace(window.origin,`${window.origin}/app`);return}};function w({open:n,disabled:s}){c.useMemo(()=>{var r,o,t,i;s||(n?(o=(r=window.top)==null?void 0:r.HostBridge)==null||o.openBackdrop(!0):(i=(t=window.top)==null?void 0:t.HostBridge)==null||i.openBackdrop(!1))},[n,s])}const d=n=>(s,r)=>{const o=m(n);return r?s.every(t=>o==null?void 0:o.includes(t)):s.some(t=>o==null?void 0:o.includes(t))},P=({baseUrl:n,accessWith:s,requireAll:r,children:o})=>d(n)(s,r)?u.jsx(u.Fragment,{children:o}):null,p=({accessWith:n,requireAll:s,baseUrl:r,unAuthorizedPath:o,children:t})=>d(r)(n,s)?u.jsx(u.Fragment,{children:t}):u.jsx(l.Navigate,{to:o,replace:!0});exports.AuthContext=e.AuthContext;exports.AuthProvider=e.AuthProvider;exports.ERROR_MESSAGE=e.ERROR_MESSAGE;exports.SaasThemeProvider=e.SaasThemeProvider;exports.TranslationProvider=e.TranslationProvider;exports.axiosInstance=e.axiosInstance;exports.color=e.color;exports.createCustomTheme=e.createCustomTheme;exports.handleErrorAxios=e.handleErrorAxios;exports.login=e.login;exports.logout=e.logout;exports.responseInterceptor=e.responseInterceptor;exports.search=e.search;exports.setFavicon=e.setFavicon;exports.setShellBackdrop=e.setShellBackdrop;exports.translate=e.translate;exports.translationConfig=e.translationConfig;exports.useAuth=e.useAuth;exports.useCustomTranslation=e.useCustomTranslation;exports.useTheme=e.useTheme;exports.useTranslation=e.useTranslation$1;exports.HasPermission=P;exports.PermissionRoute=p;exports.getUseHasPermission=d;exports.useGetPermission=m;exports.useSyncBackdrop=w;exports.useSyncRouter=f;
@@ -1,4 +1,4 @@
1
- import { O as F, R as M, T as G, a2 as N, $, a as I, c as O, a0 as j, W as z, U as L, V as U, X as V, v as W, a1 as X, s as Y, E as Z, Y as _, e as q, u as D, i as J, Z as K } from "../index.esm2017-DVyzcks1.js";
1
+ import { O as F, R as M, T as G, a2 as N, $, a as I, c as O, a0 as j, W as z, U as L, V as U, X as V, v as W, a1 as X, s as Y, E as Z, Y as _, e as q, u as D, i as J, Z as K } from "../index.esm2017-DVluJw-p.js";
2
2
  import d from "axios";
3
3
  import { useState as g, useEffect as i, useMemo as h } from "react";
4
4
  import { useNavigate as f, useLocation as w, Navigate as p } from "react-router-dom";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ukpc-lib/react",
3
3
  "private": false,
4
- "version": "0.13.1-dev.20",
4
+ "version": "0.13.1-dev.21",
5
5
  "type": "module",
6
6
  "main": "./dist/",
7
7
  "module": "./dist/",
@@ -1,5 +1,5 @@
1
1
  import "../react-to-web-component-CXwKHjZr.js";
2
- import { F as p, u as a } from "../index-DUT8X9pC.js";
2
+ import { F as p, u as a } from "../index-CNRqfpBd.js";
3
3
  import "../index-BtUzqnTK.js";
4
4
  import "../index-CAmMT_XN.js";
5
5
  import "../SaasThemeProvider-8W2MaSUF.js";
@@ -1,5 +1,5 @@
1
1
  import "../react-to-web-component-CXwKHjZr.js";
2
- import { G as a } from "../index-DUT8X9pC.js";
2
+ import { G as a } from "../index-CNRqfpBd.js";
3
3
  import "../index-BtUzqnTK.js";
4
4
  import "../index-CAmMT_XN.js";
5
5
  import "../SaasThemeProvider-8W2MaSUF.js";
@@ -1,5 +1,5 @@
1
1
  import "../react-to-web-component-CXwKHjZr.js";
2
- import { L as s, T as L } from "../index-DUT8X9pC.js";
2
+ import { L as s, T as L } from "../index-CNRqfpBd.js";
3
3
  import "../index-BtUzqnTK.js";
4
4
  import "../index-DSTem_oO.js";
5
5
  import "../index-CAmMT_XN.js";
@@ -1,5 +1,5 @@
1
1
  import "../react-to-web-component-CXwKHjZr.js";
2
- import { H as e, g as m } from "../index-DUT8X9pC.js";
2
+ import { H as e, g as m } from "../index-CNRqfpBd.js";
3
3
  import "../SaasThemeProvider-8W2MaSUF.js";
4
4
  export {
5
5
  e as HasPermission,