@capillarytech/cap-ui-utils 1.2.1 → 1.2.2

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.
@@ -0,0 +1,14 @@
1
+ import warn from '../utils/console/warn';
2
+
3
+ /**
4
+ * Function to check if the user has access to the permission
5
+ * @param {*} feature
6
+ */
7
+ export default function hasFeatureAccess(feature) {
8
+ if(!window.capAuth) {
9
+ warn("Cap auth not initialized. Please initialize cap auth to use this method");
10
+ return;
11
+ }
12
+ const { accessibleFeatures } = window.capAuth;
13
+ return accessibleFeatures.includes(feature);
14
+ }
package/auth/index.js CHANGED
@@ -12,6 +12,7 @@ import hasAccess from './hasAccess';
12
12
  import authHoc from './authHoc';
13
13
  import hasRole from './hasRole';
14
14
  import isCapUser from './isCapUser';
15
+ import hasFeatureAccess from './hasFeatureAccess';
15
16
 
16
17
  const KEYS_EXEMPTED_FROM_VALIDATION = ['isCapUser']
17
18
  /**
@@ -20,23 +21,27 @@ const KEYS_EXEMPTED_FROM_VALIDATION = ['isCapUser']
20
21
  */
21
22
  function _initialize(authConfigs) {
22
23
  const capAuth = {};
24
+ const { permissions, orgFeatures, roles, isCapUser, accessibleFeatures } = authConfigs;
23
25
  try {
24
- if (!authConfigs.permissions) {
26
+ if (!permissions) {
25
27
  warn("Cannot initialize auth without permissions");
26
28
  return;
27
29
  }
28
- if(authConfigs.permissions) {
29
- capAuth.permissions = Object.freeze(authConfigs.permissions);
30
+ if(permissions) {
31
+ capAuth.permissions = Object.freeze(permissions);
30
32
  }
31
- if(authConfigs.orgFeatures) {
32
- capAuth.orgFeatures = Object.freeze(authConfigs.orgFeatures);
33
+ if(orgFeatures) {
34
+ capAuth.orgFeatures = Object.freeze(orgFeatures);
33
35
  }
34
- if(authConfigs.roles) {
35
- capAuth.roles = Object.freeze(authConfigs.roles);
36
+ if(roles) {
37
+ capAuth.roles = Object.freeze(roles);
36
38
  }
37
- if(authConfigs.isCapUser) {
39
+ if(isCapUser) {
38
40
  capAuth.isCapUser = true;
39
41
  }
42
+ if(accessibleFeatures) {
43
+ capAuth.accessibleFeatures = Object.freeze(accessibleFeatures);
44
+ }
40
45
  log("Cap auth initialized");
41
46
  window.capAuth = Object.freeze(capAuth);
42
47
  }
@@ -67,10 +72,6 @@ function initialize(authConfigs, authOptions) {
67
72
  warn("Config must be an object");
68
73
  return;
69
74
  }
70
- if (isEmpty(authConfigs[config])) {
71
- warn("Config is empty");
72
- return;
73
- }
74
75
  }
75
76
  _initialize(authConfigs);
76
77
  return true;
@@ -82,5 +83,6 @@ export default {
82
83
  authHoc,
83
84
  hasRole,
84
85
  isCapUser,
86
+ hasFeatureAccess,
85
87
  }
86
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {