@ukpc-lib/react 0.3.4 → 0.3.5

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../index.module-28c2f9be.cjs"),g=require("axios"),i=require("react/jsx-runtime"),d=require("react");require("moment");require("@r2wc/react-to-web-component");require("@mui/material");const R=require("react-router-dom"),T=require("../index-5840ed79.cjs");function v({config:n,pushError:o=r.pushError}){const t=g.create(n);t.interceptors.request.use(async e=>(e.headers={Accept:"application/json","Content-Type":"application/json"},e),e=>Promise.reject(e)),t.interceptors.response.use(e=>e,async e=>s(e));async function s(e){var l,h,P,p;console.error("Error 🚨:",e);const a=e.config,u=(h=(l=e.response)==null?void 0:l.data)==null?void 0:h.errorMessage,m=u===r.ERROR_MESSAGE.TOKEN_EXPIRED;return((P=e.response)==null?void 0:P.status)===401?m&&!a._retry?(a._retry=!0,t.post("/authentication/api/v1/auth/refresh-token").then(()=>t(a)).catch(()=>r.login(n.baseURL))):((!u||!m)&&r.login(n.baseURL),Promise.reject("Unauthorized! Please login again.")):(((p=e.response)==null?void 0:p.status)===403?o(r.t("errorMessage.403")):o(r.t(`${u}`)||"Something went wrong!"),Promise.reject(e.response.data))}return t}const f=n=>{const[o,t]=d.useState([]);return d.useEffect(()=>{g.get(`${n}/user-management/api/v1/users/my-account/permissions`,{withCredentials:!0}).then(s=>t(s.data)).catch(s=>{console.error("Getting user permission error:",s)})},[n]),o},c=n=>(o,t)=>{const s=f(n);return t?o.every(e=>s==null?void 0:s.includes(e)):o.some(e=>s==null?void 0:s.includes(e))},q=({baseUrl:n,accessWith:o,requireAll:t,children:s})=>c(n)(o,t)?i.jsx(i.Fragment,{children:s}):null,x=({accessWith:n,requireAll:o,baseUrl:t,unAuthorizedPath:s,children:e})=>c(t)(n,o)?i.jsx(i.Fragment,{children:e}):i.jsx(R.Navigate,{to:s,replace:!0});exports.AuthProvider=r.AuthProvider;exports.TranslationProvider=r.TranslationProvider;exports.search=r.search;exports.translate=r.translate;exports.translationConfig=r.translationConfig;exports.useAuth=r.useAuth;exports.useCustomTranslation=r.useCustomTranslation;exports.useTranslation=r.useTranslation$1;exports.SaasThemeProvider=T.SaasThemeProvider;exports.useTheme=T.useTheme;exports.HasPermission=q;exports.PermissionRoute=x;exports.getAxiosInstance=v;exports.getUseHasPermission=c;exports.useGetPermission=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../index.module-ad52e7aa.cjs"),d=require("axios"),i=require("react/jsx-runtime"),g=require("react");require("moment");require("@r2wc/react-to-web-component");require("@mui/material");const f=require("react-router-dom");function R({config:n,pushError:o=s.pushError}){const t=d.create(n);t.interceptors.request.use(async e=>(e.headers={Accept:"application/json","Content-Type":"application/json"},e),e=>Promise.reject(e)),t.interceptors.response.use(e=>e,async e=>r(e));async function r(e){var l,h,P,p;console.error("Error 🚨:",e);const a=e.config,u=(h=(l=e.response)==null?void 0:l.data)==null?void 0:h.errorMessage,m=u===s.ERROR_MESSAGE.TOKEN_EXPIRED;return((P=e.response)==null?void 0:P.status)===401?m&&!a._retry?(a._retry=!0,t.post("/authentication/api/v1/auth/refresh-token").then(()=>t(a)).catch(()=>s.login(n.baseURL))):((!u||!m)&&s.login(n.baseURL),Promise.reject("Unauthorized! Please login again.")):(((p=e.response)==null?void 0:p.status)===403?o(s.t("errorMessage.403")):o(s.t(`${u}`)||"Something went wrong!"),Promise.reject(e.response.data))}return t}const T=n=>{const[o,t]=g.useState([]);return g.useEffect(()=>{d.get(`${n}/user-management/api/v1/users/my-account/permissions`,{withCredentials:!0}).then(r=>t(r.data)).catch(r=>{console.error("Getting user permission error:",r)})},[n]),o},c=n=>(o,t)=>{const r=T(n);return t?o.every(e=>r==null?void 0:r.includes(e)):o.some(e=>r==null?void 0:r.includes(e))},v=({baseUrl:n,accessWith:o,requireAll:t,children:r})=>c(n)(o,t)?i.jsx(i.Fragment,{children:r}):null,j=({accessWith:n,requireAll:o,baseUrl:t,unAuthorizedPath:r,children:e})=>c(t)(n,o)?i.jsx(i.Fragment,{children:e}):i.jsx(f.Navigate,{to:r,replace:!0});exports.AuthProvider=s.AuthProvider;exports.SaasThemeProvider=s.SaasThemeProvider;exports.TranslationProvider=s.TranslationProvider;exports.color=s.color;exports.createCustomTheme=s.createCustomTheme;exports.search=s.search;exports.translate=s.translate;exports.translationConfig=s.translationConfig;exports.useAuth=s.useAuth;exports.useCustomTranslation=s.useCustomTranslation;exports.useTheme=s.useTheme;exports.useTranslation=s.useTranslation$1;exports.HasPermission=v;exports.PermissionRoute=j;exports.getAxiosInstance=R;exports.getUseHasPermission=c;exports.useGetPermission=T;
@@ -1,14 +1,13 @@
1
- import { B as l, E as f, p as E, F as R } from "../index.module-d03675ea.js";
2
- import { H as q, T as F, m as K, M as L, K as O, J as b, u as z, N as B } from "../index.module-d03675ea.js";
1
+ import { E as l, F as f, p as E, H as R } from "../index.module-9e206368.js";
2
+ import { J as k, V as q, T as F, c as K, R as L, n as b, N as z, M as D, K as J, u as V, U as X, O as $ } from "../index.module-9e206368.js";
3
3
  import P from "axios";
4
4
  import { jsx as i, Fragment as g } from "react/jsx-runtime";
5
5
  import { useState as T, useEffect as v } from "react";
6
6
  import "moment";
7
7
  import "@r2wc/react-to-web-component";
8
8
  import "@mui/material";
9
- import { Navigate as x } from "react-router-dom";
10
- import { S as J, u as X } from "../index-2ca7cc99.js";
11
- function H({
9
+ import { Navigate as y } from "react-router-dom";
10
+ function G({
12
11
  config: t,
13
12
  pushError: n = E
14
13
  }) {
@@ -31,7 +30,7 @@ function H({
31
30
  }
32
31
  return r;
33
32
  }
34
- const y = (t) => {
33
+ const x = (t) => {
35
34
  const [n, r] = T([]);
36
35
  return v(() => {
37
36
  P.get(`${t}/user-management/api/v1/users/my-account/permissions`, {
@@ -41,38 +40,40 @@ const y = (t) => {
41
40
  });
42
41
  }, [t]), n;
43
42
  }, d = (t) => (n, r) => {
44
- const s = y(t);
43
+ const s = x(t);
45
44
  return r ? n.every(
46
45
  (e) => s == null ? void 0 : s.includes(e)
47
46
  ) : n.some(
48
47
  (e) => s == null ? void 0 : s.includes(e)
49
48
  );
50
- }, I = ({
49
+ }, H = ({
51
50
  baseUrl: t,
52
51
  accessWith: n,
53
52
  requireAll: r,
54
53
  children: s
55
- }) => d(t)(n, r) ? /* @__PURE__ */ i(g, { children: s }) : null, N = ({
54
+ }) => d(t)(n, r) ? /* @__PURE__ */ i(g, { children: s }) : null, I = ({
56
55
  accessWith: t,
57
56
  requireAll: n,
58
57
  baseUrl: r,
59
58
  unAuthorizedPath: s,
60
59
  children: e
61
- }) => d(r)(t, n) ? /* @__PURE__ */ i(g, { children: e }) : /* @__PURE__ */ i(x, { to: s, replace: !0 });
60
+ }) => d(r)(t, n) ? /* @__PURE__ */ i(g, { children: e }) : /* @__PURE__ */ i(y, { to: s, replace: !0 });
62
61
  export {
63
- q as AuthProvider,
64
- I as HasPermission,
65
- N as PermissionRoute,
66
- J as SaasThemeProvider,
62
+ k as AuthProvider,
63
+ H as HasPermission,
64
+ I as PermissionRoute,
65
+ q as SaasThemeProvider,
67
66
  F as TranslationProvider,
68
- H as getAxiosInstance,
67
+ K as color,
68
+ L as createCustomTheme,
69
+ G as getAxiosInstance,
69
70
  d as getUseHasPermission,
70
- K as search,
71
- L as translate,
72
- O as translationConfig,
73
- b as useAuth,
74
- z as useCustomTranslation,
75
- y as useGetPermission,
71
+ b as search,
72
+ z as translate,
73
+ D as translationConfig,
74
+ J as useAuth,
75
+ V as useCustomTranslation,
76
+ x as useGetPermission,
76
77
  X as useTheme,
77
- B as useTranslation
78
+ $ as useTranslation
78
79
  };
@@ -0,0 +1,26 @@
1
+ import { Theme } from '@mui/material';
2
+ import { PropsWithChildren } from 'react';
3
+ import { ColorsType } from './Colors';
4
+ type B = {
5
+ url: string;
6
+ enabled: boolean;
7
+ };
8
+ export declare const useTheme: () => {
9
+ colors: ColorsType;
10
+ theme: Theme;
11
+ logo: any;
12
+ isFetching: boolean;
13
+ };
14
+ type P = {
15
+ brandTheme: B;
16
+ customTheme?: never;
17
+ } | {
18
+ brandTheme?: never;
19
+ customTheme: Partial<Theme>;
20
+ } | {
21
+ brandTheme?: never;
22
+ customTheme?: never;
23
+ };
24
+ export type BrandThemeProps = PropsWithChildren<P>;
25
+ export declare const SaasThemeProvider: (props: BrandThemeProps) => import("react/jsx-runtime").JSX.Element;
26
+ export {};
@@ -1,26 +1,3 @@
1
- import { Theme } from '@mui/material';
2
- import { PropsWithChildren } from 'react';
3
- import { ColorsType } from './Colors';
4
- type B = {
5
- url: string;
6
- enabled: boolean;
7
- };
8
- export declare const useTheme: () => {
9
- colors: ColorsType;
10
- theme: Theme;
11
- logo: any;
12
- isFetching: boolean;
13
- };
14
- type P = {
15
- brandTheme: B;
16
- customTheme?: never;
17
- } | {
18
- brandTheme?: never;
19
- customTheme: Partial<Theme>;
20
- } | {
21
- brandTheme?: never;
22
- customTheme?: never;
23
- };
24
- type BrandThemeProps = PropsWithChildren<P>;
25
- export declare const SaasThemeProvider: (props: BrandThemeProps) => import("react/jsx-runtime").JSX.Element;
26
- export {};
1
+ export * from './Colors';
2
+ export * from './Theme';
3
+ export * from './SaasThemeProvider';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ukpc-lib/react",
3
3
  "private": false,
4
- "version": "0.3.4",
4
+ "version": "0.3.5",
5
5
  "type": "module",
6
6
  "main": "./dist/",
7
7
  "module": "./dist/",