@ukpc-lib/react 0.1.15 → 0.1.16

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.es-088789c7.cjs"),R=require("axios"),i=require("react/jsx-runtime"),d=require("react");require("@mui/material");const f=require("react-router-dom");require("moment");function j({config:n,pushError:r=o.pushError}){const t=R.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));function s(e){var c,p,m,h,P,g;console.error("Error 🚨:",e);const a=e==null?void 0:e.config;if(((c=e.response)==null?void 0:c.status)===401&&e.response.data.errorMessage===o.ERROR_MESSAGE.TOKEN_EXPIRED&&!a._retry&&(a._retry=!0,t.post("/authentication/api/v1/auth/refresh-token").then(()=>t(a)).catch(()=>o.login(n.baseURL))),((p=e.response)==null?void 0:p.status)===401&&(((m=e.response)==null?void 0:m.data.errorMessage)!==o.ERROR_MESSAGE.TOKEN_EXPIRED||!((h=e.response)!=null&&h.data.errorMessage))&&o.login(n.baseURL),e.response.status!==401){const l=((P=e.response)==null?void 0:P.data)&&((g=e.response.data)==null?void 0:g.errorMessage)||"Something went wrong!";return r(l),Promise.reject(e.response.data)}return Promise.reject(e)}return t}const E=n=>{const[r,t]=d.useState([]);return d.useEffect(()=>{R.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]),r},u=n=>(r,t)=>{const s=E(n);return t?r.every(e=>s==null?void 0:s.includes(e)):r.some(e=>s==null?void 0:s.includes(e))},A=({baseUrl:n,accessWith:r,requireAll:t,children:s})=>u(n)(r,t)?i.jsx(i.Fragment,{children:s}):null,q=({accessWith:n,requireAll:r,baseUrl:t,unAuthorizedPath:s,children:e})=>u(t)(n,r)?i.jsx(i.Fragment,{children:e}):i.jsx(f.Navigate,{to:s,replace:!0});exports.AuthProvider=o.AuthProvider;exports.search=o.search;exports.useAuth=o.useAuth;exports.HasPermission=A;exports.PermissionRoute=q;exports.getAxiosInstance=j;exports.getUseHasPermission=u;exports.useGetPermission=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../index.es-6cb46e89.cjs"),R=require("axios"),i=require("react/jsx-runtime"),d=require("react"),f=require("react-router-dom");require("react-dom");require("@mui/material");require("moment");function j({config:n,pushError:r=o.pushError}){const t=R.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));function s(e){var c,p,m,h,P,g;console.error("Error 🚨:",e);const a=e==null?void 0:e.config;if(((c=e.response)==null?void 0:c.status)===401&&e.response.data.errorMessage===o.ERROR_MESSAGE.TOKEN_EXPIRED&&!a._retry&&(a._retry=!0,t.post("/authentication/api/v1/auth/refresh-token").then(()=>t(a)).catch(()=>o.login(n.baseURL))),((p=e.response)==null?void 0:p.status)===401&&(((m=e.response)==null?void 0:m.data.errorMessage)!==o.ERROR_MESSAGE.TOKEN_EXPIRED||!((h=e.response)!=null&&h.data.errorMessage))&&o.login(n.baseURL),e.response.status!==401){const l=((P=e.response)==null?void 0:P.data)&&((g=e.response.data)==null?void 0:g.errorMessage)||"Something went wrong!";return r(l),Promise.reject(e.response.data)}return Promise.reject(e)}return t}const E=n=>{const[r,t]=d.useState([]);return d.useEffect(()=>{R.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]),r},u=n=>(r,t)=>{const s=E(n);return t?r.every(e=>s==null?void 0:s.includes(e)):r.some(e=>s==null?void 0:s.includes(e))},q=({baseUrl:n,accessWith:r,requireAll:t,children:s})=>u(n)(r,t)?i.jsx(i.Fragment,{children:s}):null,A=({accessWith:n,requireAll:r,baseUrl:t,unAuthorizedPath:s,children:e})=>u(t)(n,r)?i.jsx(i.Fragment,{children:e}):i.jsx(f.Navigate,{to:s,replace:!0});exports.AuthProvider=o.AuthProvider;exports.search=o.search;exports.useAuth=o.useAuth;exports.HasPermission=q;exports.PermissionRoute=A;exports.getAxiosInstance=j;exports.getUseHasPermission=u;exports.useGetPermission=E;
@@ -1,12 +1,13 @@
1
- import { E as f, h as E, p as R } from "../index.es-bb5fb95c.js";
2
- import { A as D, s as H, u as K } from "../index.es-bb5fb95c.js";
1
+ import { E as f, j as E, p as R } from "../index.es-4032ffe1.js";
2
+ import { A as H, s as K, u as L } from "../index.es-4032ffe1.js";
3
3
  import P from "axios";
4
4
  import { jsx as a, Fragment as d } from "react/jsx-runtime";
5
- import { useState as y, useEffect as A } from "react";
5
+ import { useState as j, useEffect as y } from "react";
6
+ import { Navigate as A } from "react-router-dom";
7
+ import "react-dom";
6
8
  import "@mui/material";
7
- import { Navigate as j } from "react-router-dom";
8
9
  import "moment";
9
- function N({
10
+ function O({
10
11
  config: r,
11
12
  pushError: n = R
12
13
  }) {
@@ -22,10 +23,10 @@ function N({
22
23
  async (e) => s(e)
23
24
  );
24
25
  function s(e) {
25
- var i, u, c, p, m, h;
26
+ var i, u, p, c, m, h;
26
27
  console.error("Error 🚨:", e);
27
28
  const o = e == null ? void 0 : e.config;
28
- if (((i = e.response) == null ? void 0 : i.status) === 401 && e.response.data.errorMessage === f.TOKEN_EXPIRED && !o._retry && (o._retry = !0, t.post("/authentication/api/v1/auth/refresh-token").then(() => t(o)).catch(() => E(r.baseURL))), ((u = e.response) == null ? void 0 : u.status) === 401 && (((c = e.response) == null ? void 0 : c.data.errorMessage) !== f.TOKEN_EXPIRED || !((p = e.response) != null && p.data.errorMessage)) && E(r.baseURL), e.response.status !== 401) {
29
+ if (((i = e.response) == null ? void 0 : i.status) === 401 && e.response.data.errorMessage === f.TOKEN_EXPIRED && !o._retry && (o._retry = !0, t.post("/authentication/api/v1/auth/refresh-token").then(() => t(o)).catch(() => E(r.baseURL))), ((u = e.response) == null ? void 0 : u.status) === 401 && (((p = e.response) == null ? void 0 : p.data.errorMessage) !== f.TOKEN_EXPIRED || !((c = e.response) != null && c.data.errorMessage)) && E(r.baseURL), e.response.status !== 401) {
29
30
  const l = ((m = e.response) == null ? void 0 : m.data) && ((h = e.response.data) == null ? void 0 : h.errorMessage) || "Something went wrong!";
30
31
  return n(l), Promise.reject(e.response.data);
31
32
  }
@@ -34,8 +35,8 @@ function N({
34
35
  return t;
35
36
  }
36
37
  const v = (r) => {
37
- const [n, t] = y([]);
38
- return A(() => {
38
+ const [n, t] = j([]);
39
+ return y(() => {
39
40
  P.get(`${r}/user-management/api/v1/users/my-account/permissions`, {
40
41
  withCredentials: !0
41
42
  }).then((s) => t(s.data)).catch((s) => {
@@ -49,25 +50,25 @@ const v = (r) => {
49
50
  ) : n.some(
50
51
  (e) => s == null ? void 0 : s.includes(e)
51
52
  );
52
- }, O = ({
53
+ }, T = ({
53
54
  baseUrl: r,
54
55
  accessWith: n,
55
56
  requireAll: t,
56
57
  children: s
57
- }) => g(r)(n, t) ? /* @__PURE__ */ a(d, { children: s }) : null, T = ({
58
+ }) => g(r)(n, t) ? /* @__PURE__ */ a(d, { children: s }) : null, q = ({
58
59
  accessWith: r,
59
60
  requireAll: n,
60
61
  baseUrl: t,
61
62
  unAuthorizedPath: s,
62
63
  children: e
63
- }) => g(t)(r, n) ? /* @__PURE__ */ a(d, { children: e }) : /* @__PURE__ */ a(j, { to: s, replace: !0 });
64
+ }) => g(t)(r, n) ? /* @__PURE__ */ a(d, { children: e }) : /* @__PURE__ */ a(A, { to: s, replace: !0 });
64
65
  export {
65
- D as AuthProvider,
66
- O as HasPermission,
67
- T as PermissionRoute,
68
- N as getAxiosInstance,
66
+ H as AuthProvider,
67
+ T as HasPermission,
68
+ q as PermissionRoute,
69
+ O as getAxiosInstance,
69
70
  g as getUseHasPermission,
70
- H as search,
71
- K as useAuth,
71
+ K as search,
72
+ L as useAuth,
72
73
  v as useGetPermission
73
74
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ukpc-lib/react",
3
3
  "private": false,
4
- "version": "0.1.15",
4
+ "version": "0.1.16",
5
5
  "type": "module",
6
6
  "main": "./dist/",
7
7
  "module": "./dist/",