@ukpc-lib/react 0.1.27 → 0.1.29

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 o=require("../index.module-35d2f1ab.cjs"),l=require("axios"),i=require("react/jsx-runtime"),g=require("react"),R=require("react-router-dom");require("react-dom");require("@mui/material");require("moment");function E({config:t,pushError:n=o.pushError}){const r=l.create(t);r.interceptors.request.use(async e=>(e.headers={Accept:"application/json","Content-Type":"application/json"},e),e=>Promise.reject(e)),r.interceptors.response.use(e=>e,async e=>s(e));async function s(e){var h,p,P;console.error("Error 🚨:",e);const u=e.config,a=(p=(h=e.response)==null?void 0:h.data)==null?void 0:p.errorMessage,m=a===o.ERROR_MESSAGE.TOKEN_EXPIRED;return((P=e.response)==null?void 0:P.status)===401?m&&!u._retry?(u._retry=!0,r.post("/authentication/api/v1/auth/refresh-token").then(()=>r(u)).catch(()=>o.login(t.baseURL))):((!a||!m)&&o.login(t.baseURL),Promise.reject("Unauthorized! Please login again.")):(n(a||"Something went wrong!"),Promise.reject(e.response.data))}return r}const d=t=>{const[n,r]=g.useState([]);return g.useEffect(()=>{l.get(`${t}/user-management/api/v1/users/my-account/permissions`,{withCredentials:!0}).then(s=>r(s.data)).catch(s=>{console.error("Getting user permission error:",s)})},[t]),n},c=t=>(n,r)=>{const s=d(t);return r?n.every(e=>s==null?void 0:s.includes(e)):n.some(e=>s==null?void 0:s.includes(e))},f=({baseUrl:t,accessWith:n,requireAll:r,children:s})=>c(t)(n,r)?i.jsx(i.Fragment,{children:s}):null,j=({accessWith:t,requireAll:n,baseUrl:r,unAuthorizedPath:s,children:e})=>c(r)(t,n)?i.jsx(i.Fragment,{children:e}):i.jsx(R.Navigate,{to:s,replace:!0});exports.AuthProvider=o.AuthProvider;exports.search=o.search;exports.useAuth=o.useAuth;exports.HasPermission=f;exports.PermissionRoute=j;exports.getAxiosInstance=E;exports.getUseHasPermission=c;exports.useGetPermission=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../index.module-9c4fe97a.cjs"),l=require("axios"),i=require("react/jsx-runtime"),g=require("react");require("@r2wc/react-to-web-component");const R=require("react-router-dom");require("react-dom");require("@mui/material");require("moment");function q({config:t,pushError:n=o.pushError}){const r=l.create(t);r.interceptors.request.use(async e=>(e.headers={Accept:"application/json","Content-Type":"application/json"},e),e=>Promise.reject(e)),r.interceptors.response.use(e=>e,async e=>s(e));async function s(e){var h,p,P;console.error("Error 🚨:",e);const u=e.config,a=(p=(h=e.response)==null?void 0:h.data)==null?void 0:p.errorMessage,m=a===o.ERROR_MESSAGE.TOKEN_EXPIRED;return((P=e.response)==null?void 0:P.status)===401?m&&!u._retry?(u._retry=!0,r.post("/authentication/api/v1/auth/refresh-token").then(()=>r(u)).catch(()=>o.login(t.baseURL))):((!a||!m)&&o.login(t.baseURL),Promise.reject("Unauthorized! Please login again.")):(n(a||"Something went wrong!"),Promise.reject(e.response.data))}return r}const d=t=>{const[n,r]=g.useState([]);return g.useEffect(()=>{l.get(`${t}/user-management/api/v1/users/my-account/permissions`,{withCredentials:!0}).then(s=>r(s.data)).catch(s=>{console.error("Getting user permission error:",s)})},[t]),n},c=t=>(n,r)=>{const s=d(t);return r?n.every(e=>s==null?void 0:s.includes(e)):n.some(e=>s==null?void 0:s.includes(e))},E=({baseUrl:t,accessWith:n,requireAll:r,children:s})=>c(t)(n,r)?i.jsx(i.Fragment,{children:s}):null,f=({accessWith:t,requireAll:n,baseUrl:r,unAuthorizedPath:s,children:e})=>c(r)(t,n)?i.jsx(i.Fragment,{children:e}):i.jsx(R.Navigate,{to:s,replace:!0});exports.AuthProvider=o.AuthProvider;exports.search=o.search;exports.useAuth=o.useAuth;exports.HasPermission=E;exports.PermissionRoute=f;exports.getAxiosInstance=q;exports.getUseHasPermission=c;exports.useGetPermission=d;
@@ -1,13 +1,14 @@
1
- import { t as h, p as E, E as g } from "../index.module-ebc563e0.js";
2
- import { A as C, i as H, u as L } from "../index.module-ebc563e0.js";
1
+ import { t as h, p as E, E as g } from "../index.module-34bab88b.js";
2
+ import { A as H, i as L, u as N } from "../index.module-34bab88b.js";
3
3
  import f from "axios";
4
4
  import { jsx as a, Fragment as P } from "react/jsx-runtime";
5
5
  import { useState as d, useEffect as R } from "react";
6
+ import "@r2wc/react-to-web-component";
6
7
  import { Navigate as y } from "react-router-dom";
7
8
  import "react-dom";
8
9
  import "@mui/material";
9
10
  import "moment";
10
- function M({
11
+ function T({
11
12
  config: t,
12
13
  pushError: n = E
13
14
  }) {
@@ -46,12 +47,12 @@ const x = (t) => {
46
47
  ) : n.some(
47
48
  (e) => r == null ? void 0 : r.includes(e)
48
49
  );
49
- }, T = ({
50
+ }, U = ({
50
51
  baseUrl: t,
51
52
  accessWith: n,
52
53
  requireAll: s,
53
54
  children: r
54
- }) => l(t)(n, s) ? /* @__PURE__ */ a(P, { children: r }) : null, U = ({
55
+ }) => l(t)(n, s) ? /* @__PURE__ */ a(P, { children: r }) : null, k = ({
55
56
  accessWith: t,
56
57
  requireAll: n,
57
58
  baseUrl: s,
@@ -59,12 +60,12 @@ const x = (t) => {
59
60
  children: e
60
61
  }) => l(s)(t, n) ? /* @__PURE__ */ a(P, { children: e }) : /* @__PURE__ */ a(y, { to: r, replace: !0 });
61
62
  export {
62
- C as AuthProvider,
63
- T as HasPermission,
64
- U as PermissionRoute,
65
- M as getAxiosInstance,
63
+ H as AuthProvider,
64
+ U as HasPermission,
65
+ k as PermissionRoute,
66
+ T as getAxiosInstance,
66
67
  l as getUseHasPermission,
67
- H as search,
68
- L as useAuth,
68
+ L as search,
69
+ N as useAuth,
69
70
  x as useGetPermission
70
71
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ukpc-lib/react",
3
3
  "private": false,
4
- "version": "0.1.27",
4
+ "version": "0.1.29",
5
5
  "type": "module",
6
6
  "main": "./dist/",
7
7
  "module": "./dist/",