@capillarytech/cap-ui-utils 1.2.1 → 1.2.3

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.
package/GA/index.js CHANGED
@@ -16,11 +16,8 @@ const _initialize = (GAConfigs) => {
16
16
  if(GAConfigs.accessKey) {
17
17
  ReactGA.initialize(GAConfigs.accessKey,{debug: true,});
18
18
  }
19
- if(GAConfigs.trackError){
20
- //Track Error
21
- window.addEventListener('error', (e) =>{
22
- tracker.trackException(`UI Error ${e.message}`);
23
- });
19
+ if(GAConfigs.trackUIError){
20
+ errorTracks();
24
21
  }
25
22
  eventsAfterInitialize();
26
23
  log("Cap GA initialized");
@@ -34,13 +31,12 @@ const initialize = (GAConfigs) =>{
34
31
  return;
35
32
  }
36
33
  for ( const config in GAConfigs) {
37
- if (isEmpty(GAConfigs[config])) {
34
+ if (!GAConfigs[config]) {
38
35
  warn("Config is empty");
39
36
  return;
40
37
  }
41
38
  }
42
39
  _initialize(GAConfigs);
43
-
44
40
  return true;
45
41
  }
46
42
  const eventsAfterInitialize = () => {
@@ -52,6 +48,25 @@ const eventsAfterInitialize = () => {
52
48
  });
53
49
  }
54
50
 
51
+ const errorTracks = () => {
52
+ window.onerror = function (msg, url, lineNo, columnNo, error) {
53
+ // to avoid 2 times same error log
54
+ if (error.hasBeenCaught !== undefined){
55
+ return false
56
+ }
57
+ error.hasBeenCaught = true
58
+ const message = [
59
+ 'Message: ' + msg,
60
+ 'URL: ' + url,
61
+ 'Column: ' + columnNo,
62
+ 'Error object: ' + JSON.stringify(error)
63
+ ].join(' - ');
64
+ tracker.trackException({
65
+ description: message,
66
+ fatal: true,
67
+ });
68
+ };
69
+ }
55
70
 
56
71
  // ttiPolyfill.getFirstConsistentlyInteractive().then(tti => {
57
72
  // console.log('performance tti', tti);
@@ -8,7 +8,7 @@ const trackTiming = () => {}
8
8
 
9
9
  const trackPageView = () => {}
10
10
 
11
- const trackException = (description, fatal = true) => {
11
+ const trackException = ({description, fatal = true}) => {
12
12
  ReactGA.exception({
13
13
  description,
14
14
  fatal,
@@ -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.3",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {