@iushev/react-rbac 1.0.15 → 1.0.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.
@@ -7,10 +7,10 @@ const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const useCheckAccess_1 = __importDefault(require("./useCheckAccess"));
8
8
  const NoAccess_1 = __importDefault(require("./NoAccess"));
9
9
  const CheckAccess = ({ roles, allow, params, match, busy: BusyComponent = () => null, noAccess: NoAccessComponent = NoAccess_1.default, children, }) => {
10
- const { checking, hasAccess } = useCheckAccess_1.default({ roles, allow, params, match });
10
+ const { checking, hasAccess } = (0, useCheckAccess_1.default)({ roles, allow, params, match });
11
11
  if (checking) {
12
- return jsx_runtime_1.jsx(BusyComponent, {}, void 0);
12
+ return (0, jsx_runtime_1.jsx)(BusyComponent, {});
13
13
  }
14
- return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: hasAccess ? jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: children }, void 0) : jsx_runtime_1.jsx(NoAccessComponent, {}, void 0) }, void 0);
14
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: hasAccess ? (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }) : (0, jsx_runtime_1.jsx)(NoAccessComponent, {}) });
15
15
  };
16
16
  exports.default = CheckAccess;
package/build/NoAccess.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const jsx_runtime_1 = require("react/jsx-runtime");
4
4
  const NoAccess = () => {
5
- return (jsx_runtime_1.jsxs("div", { children: [jsx_runtime_1.jsx("h4", { children: "Access Denied" }, void 0),
6
- jsx_runtime_1.jsx("h5", { children: "You don't have permission to access." }, void 0)] }, void 0));
5
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h4", { children: "Access Denied" }), (0, jsx_runtime_1.jsx)("h5", { children: "You don't have permission to access." })] }));
7
6
  };
8
7
  exports.default = NoAccess;
@@ -22,12 +22,15 @@ class RbacCheckAccess extends rbac_1.BaseCheckAccess {
22
22
  baseURL: options.path,
23
23
  });
24
24
  this.axiosInstance.interceptors.request.use((config) => {
25
+ if (!config.headers) {
26
+ config.headers = {};
27
+ }
25
28
  if (options.authorization) {
26
29
  const token = options.authorization();
27
30
  config.headers.common["Authorization"] = "Bearer " + token;
28
31
  }
29
32
  else {
30
- config.headers.common["Authorization"] = null;
33
+ config.headers.common["Authorization"] = "";
31
34
  }
32
35
  return config;
33
36
  });
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -39,8 +43,8 @@ const RbacContext = react_1.default.createContext({
39
43
  checkAccess: (_options) => __awaiter(void 0, void 0, void 0, function* () { return true; }),
40
44
  });
41
45
  const RbacProvider = ({ username, rbacUrl, token, isSuperuser, isGuest, ruleClasses, children, }) => {
42
- const [rbac, setRbac] = react_1.useState(null);
43
- react_1.useEffect(() => {
46
+ const [rbac, setRbac] = (0, react_1.useState)(null);
47
+ (0, react_1.useEffect)(() => {
44
48
  if (!token) {
45
49
  setRbac(null);
46
50
  }
@@ -54,7 +58,7 @@ const RbacProvider = ({ username, rbacUrl, token, isSuperuser, isGuest, ruleClas
54
58
  _rbac.load().then(() => setRbac(_rbac));
55
59
  }
56
60
  }, [rbacUrl, token]);
57
- const value = react_1.useMemo(() => {
61
+ const value = (0, react_1.useMemo)(() => {
58
62
  const checkAccess = ({ roles, allow = true, match, params = {} }) => __awaiter(void 0, void 0, void 0, function* () {
59
63
  const matchRole = () => __awaiter(void 0, void 0, void 0, function* () {
60
64
  if (!roles || roles.length === 0) {
@@ -98,7 +102,7 @@ const RbacProvider = ({ username, rbacUrl, token, isSuperuser, isGuest, ruleClas
98
102
  checkAccess,
99
103
  };
100
104
  }, [rbac, username, isGuest, isSuperuser]);
101
- return jsx_runtime_1.jsx(RbacContext.Provider, Object.assign({ value: value }, { children: children }), void 0);
105
+ return (0, jsx_runtime_1.jsx)(RbacContext.Provider, Object.assign({ value: value }, { children: children }));
102
106
  };
103
107
  exports.RbacProvider = RbacProvider;
104
108
  exports.RbacConsumer = RbacContext.Consumer;
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = require("react");
7
7
  const RbacContext_1 = __importDefault(require("./RbacContext"));
8
8
  function useCheckAccess({ roles, allow, params, match }) {
9
- const rbac = react_1.useContext(RbacContext_1.default);
10
- const [state, setState] = react_1.useState({
9
+ const rbac = (0, react_1.useContext)(RbacContext_1.default);
10
+ const [state, setState] = (0, react_1.useState)({
11
11
  checking: true,
12
12
  hasAccess: false,
13
13
  });
14
- react_1.useEffect(() => {
14
+ (0, react_1.useEffect)(() => {
15
15
  let subscribed = true;
16
16
  setState({
17
17
  checking: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iushev/react-rbac",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "private": false,
5
5
  "author": "Ivaylo Ushev",
6
6
  "description": "",
@@ -12,13 +12,13 @@
12
12
  "test": "jest"
13
13
  },
14
14
  "devDependencies": {
15
- "typescript": "^4.4.4"
15
+ "typescript": "^4.6.2"
16
16
  },
17
17
  "peerDependencies": {
18
- "@iushev/rbac": "^1.0.19",
19
- "@types/react": "^16.14.5 || ^17.0.33",
20
- "@types/react-dom": "^17.0.10",
21
- "axios": "^0.24.0",
18
+ "@iushev/rbac": "^1.0.22",
19
+ "@types/react": "^16.14.5 || ^17.0.40",
20
+ "@types/react-dom": "^17.0.13",
21
+ "axios": ">= 0.26.1",
22
22
  "react": "^16.14.0 || ^17.0.2",
23
23
  "react-dom": "^16.14.0 || ^17.0.2"
24
24
  },
@@ -31,11 +31,15 @@ export default class RbacCheckAccess extends BaseCheckAccess {
31
31
  });
32
32
 
33
33
  this.axiosInstance.interceptors.request.use((config) => {
34
+ if (!config.headers) {
35
+ config.headers = {};
36
+ }
37
+
34
38
  if (options.authorization) {
35
39
  const token = options.authorization();
36
- config.headers.common["Authorization"] = "Bearer " + token;
40
+ (config.headers.common as any as Record<string, string>)["Authorization"] = "Bearer " + token;
37
41
  } else {
38
- config.headers.common["Authorization"] = null;
42
+ (config.headers.common as any as Record<string, string>)["Authorization"] = "";
39
43
  }
40
44
  return config;
41
45
  });