@ukpc-lib/react 0.2.14 → 0.2.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,6 +1,6 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
2
  import { Language } from '../../translations/config';
3
- export declare const useTranslation: () => {
3
+ export declare const useCustomTranslation: () => {
4
4
  language: Language | undefined;
5
5
  setLanguage: import("react").Dispatch<import("react").SetStateAction<Language | undefined>>;
6
6
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../index.module-4dfb8940.cjs"),d=require("axios"),i=require("react/jsx-runtime"),g=require("react");require("moment");require("@r2wc/react-to-web-component");const f=require("react-router-dom");require("react-dom");require("@mui/material");function q({config:t,pushError:n=o.pushError}){const r=d.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 l,P,p,h;console.error("Error 🚨:",e);const a=e.config,u=(P=(l=e.response)==null?void 0:l.data)==null?void 0:P.errorMessage,m=u===o.ERROR_MESSAGE.TOKEN_EXPIRED;return((p=e.response)==null?void 0:p.status)===401?m&&!a._retry?(a._retry=!0,r.post("/authentication/api/v1/auth/refresh-token").then(()=>r(a)).catch(()=>o.login(t.baseURL))):((!u||!m)&&o.login(t.baseURL),Promise.reject("Unauthorized! Please login again.")):(((h=e.response)==null?void 0:h.status)===403?n(o.t("errorMessage.403")):n(o.t(`${u}`)||"Something went wrong!"),Promise.reject(e.response.data))}return r}const R=t=>{const[n,r]=g.useState([]);return g.useEffect(()=>{d.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=R(t);return r?n.every(e=>s==null?void 0:s.includes(e)):n.some(e=>s==null?void 0:s.includes(e))},j=({baseUrl:t,accessWith:n,requireAll:r,children:s})=>c(t)(n,r)?i.jsx(i.Fragment,{children:s}):null,v=({accessWith:t,requireAll:n,baseUrl:r,unAuthorizedPath:s,children:e})=>c(r)(t,n)?i.jsx(i.Fragment,{children:e}):i.jsx(f.Navigate,{to:s,replace:!0});exports.AuthProvider=o.AuthProvider;exports.TranslationProvider=o.TranslationProvider;exports.search=o.search;exports.useAuth=o.useAuth;exports.useTranslation=o.useTranslation;exports.HasPermission=j;exports.PermissionRoute=v;exports.getAxiosInstance=q;exports.getUseHasPermission=c;exports.useGetPermission=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../index.module-87bfa088.cjs"),d=require("axios"),i=require("react/jsx-runtime"),g=require("react");require("moment");require("@r2wc/react-to-web-component");const f=require("react-router-dom");require("react-dom");require("@mui/material");function q({config:t,pushError:n=o.pushError}){const r=d.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 l,P,p,h;console.error("Error 🚨:",e);const a=e.config,u=(P=(l=e.response)==null?void 0:l.data)==null?void 0:P.errorMessage,m=u===o.ERROR_MESSAGE.TOKEN_EXPIRED;return((p=e.response)==null?void 0:p.status)===401?m&&!a._retry?(a._retry=!0,r.post("/authentication/api/v1/auth/refresh-token").then(()=>r(a)).catch(()=>o.login(t.baseURL))):((!u||!m)&&o.login(t.baseURL),Promise.reject("Unauthorized! Please login again.")):(((h=e.response)==null?void 0:h.status)===403?n(o.t("errorMessage.403")):n(o.t(`${u}`)||"Something went wrong!"),Promise.reject(e.response.data))}return r}const R=t=>{const[n,r]=g.useState([]);return g.useEffect(()=>{d.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=R(t);return r?n.every(e=>s==null?void 0:s.includes(e)):n.some(e=>s==null?void 0:s.includes(e))},j=({baseUrl:t,accessWith:n,requireAll:r,children:s})=>c(t)(n,r)?i.jsx(i.Fragment,{children:s}):null,v=({accessWith:t,requireAll:n,baseUrl:r,unAuthorizedPath:s,children:e})=>c(r)(t,n)?i.jsx(i.Fragment,{children:e}):i.jsx(f.Navigate,{to:s,replace:!0});exports.AuthProvider=o.AuthProvider;exports.TranslationProvider=o.TranslationProvider;exports.search=o.search;exports.useAuth=o.useAuth;exports.useCustomTranslation=o.useCustomTranslation;exports.HasPermission=j;exports.PermissionRoute=v;exports.getAxiosInstance=q;exports.getUseHasPermission=c;exports.useGetPermission=R;
@@ -1,5 +1,5 @@
1
- import { E as f, t as l, p as E, F as R } from "../index.module-ddaeb82a.js";
2
- import { G as L, T as N, m as O, H as b, u as z } from "../index.module-ddaeb82a.js";
1
+ import { E as f, t as l, p as E, F as R } from "../index.module-6a5e8d95.js";
2
+ import { G as L, T as N, m as O, H as b, u as z } from "../index.module-6a5e8d95.js";
3
3
  import P from "axios";
4
4
  import { jsx as a, Fragment as g } from "react/jsx-runtime";
5
5
  import { useState as y, useEffect as v } from "react";
@@ -8,7 +8,7 @@ import "@r2wc/react-to-web-component";
8
8
  import { Navigate as x } from "react-router-dom";
9
9
  import "react-dom";
10
10
  import "@mui/material";
11
- function U({
11
+ function I({
12
12
  config: t,
13
13
  pushError: n = E
14
14
  }) {
@@ -47,12 +47,12 @@ const j = (t) => {
47
47
  ) : n.some(
48
48
  (e) => s == null ? void 0 : s.includes(e)
49
49
  );
50
- }, k = ({
50
+ }, U = ({
51
51
  baseUrl: t,
52
52
  accessWith: n,
53
53
  requireAll: r,
54
54
  children: s
55
- }) => d(t)(n, r) ? /* @__PURE__ */ a(g, { children: s }) : null, q = ({
55
+ }) => d(t)(n, r) ? /* @__PURE__ */ a(g, { children: s }) : null, k = ({
56
56
  accessWith: t,
57
57
  requireAll: n,
58
58
  baseUrl: r,
@@ -61,13 +61,13 @@ const j = (t) => {
61
61
  }) => d(r)(t, n) ? /* @__PURE__ */ a(g, { children: e }) : /* @__PURE__ */ a(x, { to: s, replace: !0 });
62
62
  export {
63
63
  L as AuthProvider,
64
- k as HasPermission,
65
- q as PermissionRoute,
64
+ U as HasPermission,
65
+ k as PermissionRoute,
66
66
  N as TranslationProvider,
67
- U as getAxiosInstance,
67
+ I as getAxiosInstance,
68
68
  d as getUseHasPermission,
69
69
  O as search,
70
70
  b as useAuth,
71
- j as useGetPermission,
72
- z as useTranslation
71
+ z as useCustomTranslation,
72
+ j as useGetPermission
73
73
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ukpc-lib/react",
3
3
  "private": false,
4
- "version": "0.2.14",
4
+ "version": "0.2.16",
5
5
  "type": "module",
6
6
  "main": "./dist/",
7
7
  "module": "./dist/",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../index-661a7bdb.cjs");const e=require("../index-e24b2e17.cjs");exports.TopBar=e.TopBar;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../index-661a7bdb.cjs");const e=require("../index-48ba04c0.cjs");exports.TopBar=e.TopBar;
@@ -1,5 +1,5 @@
1
1
  import "../index-200424a6.js";
2
- import { T as a } from "../index-08fd914d.js";
2
+ import { T as a } from "../index-60a2bee1.js";
3
3
  export {
4
4
  a as TopBar
5
5
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../index-661a7bdb.cjs");const e=require("../index-e24b2e17.cjs");exports.HasPermission=e.HasPermission;exports.getUseHasPermission=e.getUseHasPermission;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../index-661a7bdb.cjs");const e=require("../index-48ba04c0.cjs");exports.HasPermission=e.HasPermission;exports.getUseHasPermission=e.getUseHasPermission;
@@ -1,5 +1,5 @@
1
1
  import "../index-200424a6.js";
2
- import { H as o, g as r } from "../index-08fd914d.js";
2
+ import { H as o, g as r } from "../index-60a2bee1.js";
3
3
  export {
4
4
  o as HasPermission,
5
5
  r as getUseHasPermission