@capillarytech/cap-ui-utils 1.0.7 → 1.0.11
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/utils/timeTracker.js +3 -3
- package/GA/utils/tracker.js +4 -4
- package/auth/hasRole.js +14 -0
- package/auth/index.js +10 -0
- package/auth/isCapUser.js +13 -0
- package/package.json +1 -1
package/GA/utils/timeTracker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
// import ReactGA from 'react-ga';
|
|
3
3
|
import tracker from './tracker'
|
|
4
|
-
import log from '
|
|
4
|
+
import log from '../../utils/console/log'
|
|
5
5
|
let trackableEvents = {};
|
|
6
6
|
let trackingStoppedAt = 0;
|
|
7
7
|
let windowWasInActive = false;
|
|
@@ -13,13 +13,13 @@ let addInactiveTimeToEvents = inActiveInterval => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
const startTimer = (event) => {
|
|
16
|
-
log(
|
|
16
|
+
log(`tracker Started timer for ${event}` );
|
|
17
17
|
trackableEvents[event] = Date.now();
|
|
18
18
|
}
|
|
19
19
|
const stopTimer = (event, options) =>{
|
|
20
20
|
const timeTaken = Date.now() - (trackableEvents[event] || 0);
|
|
21
21
|
delete trackableEvents[event];
|
|
22
|
-
log(
|
|
22
|
+
log(`tracker stopped timer for ${event} ${timeTaken} ${options}` );
|
|
23
23
|
//Track the event timing
|
|
24
24
|
const { category , action, label } =options;
|
|
25
25
|
if (options) {
|
package/GA/utils/tracker.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import ReactGA from 'react-ga';
|
|
2
2
|
|
|
3
|
-
trackEvent = (options)=> {
|
|
3
|
+
const trackEvent = (options)=> {
|
|
4
4
|
ReactGA.event(options);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
trackTiming = () => {}
|
|
7
|
+
const trackTiming = () => {}
|
|
8
8
|
|
|
9
|
-
trackPageView = () => {}
|
|
9
|
+
const trackPageView = () => {}
|
|
10
10
|
|
|
11
|
-
trackException = (description, fatal = true) => {
|
|
11
|
+
const trackException = (description, fatal = true) => {
|
|
12
12
|
ReactGA.exception({
|
|
13
13
|
description,
|
|
14
14
|
fatal,
|
package/auth/hasRole.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import warn from '../utils/console/warn';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function to check if the user has access to the role
|
|
5
|
+
* @param {*} role
|
|
6
|
+
*/
|
|
7
|
+
export default function hasRole(role) {
|
|
8
|
+
if(!window.capAuth) {
|
|
9
|
+
warn("Cap auth not initialized. Please initialize cap auth to use this method");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const { roles } = window.capAuth;
|
|
13
|
+
return roles.includes(role);
|
|
14
|
+
}
|
package/auth/index.js
CHANGED
|
@@ -10,6 +10,8 @@ import log from '../utils/console/log';
|
|
|
10
10
|
import isEmpty from '../utils/isEmpty';
|
|
11
11
|
import hasAccess from './hasAccess';
|
|
12
12
|
import authHoc from './authHoc';
|
|
13
|
+
import hasRole from './hasRole';
|
|
14
|
+
import isCapUser from './isCapUser';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Function to initialize the capAuth configurations to the document
|
|
@@ -27,6 +29,12 @@ function _initialize(authConfigs) {
|
|
|
27
29
|
if(authConfigs.orgFeatures) {
|
|
28
30
|
capAuth.orgFeatures = Object.freeze(authConfigs.orgFeatures);
|
|
29
31
|
}
|
|
32
|
+
if(authConfigs.roles) {
|
|
33
|
+
capAuth.roles = Object.freeze(authConfigs.roles);
|
|
34
|
+
}
|
|
35
|
+
if(authConfigs.isCapUser) {
|
|
36
|
+
capAuth.isCapUser = true;
|
|
37
|
+
}
|
|
30
38
|
log("Cap auth initialized");
|
|
31
39
|
window.capAuth = Object.freeze(capAuth);
|
|
32
40
|
}
|
|
@@ -62,5 +70,7 @@ export default {
|
|
|
62
70
|
initialize,
|
|
63
71
|
hasAccess,
|
|
64
72
|
authHoc,
|
|
73
|
+
hasRole,
|
|
74
|
+
isCapUser,
|
|
65
75
|
}
|
|
66
76
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import warn from '../utils/console/warn';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function to check if the user is a capUser
|
|
5
|
+
*/
|
|
6
|
+
export default function isCapUser() {
|
|
7
|
+
if(!window.capAuth) {
|
|
8
|
+
warn("Cap auth not initialized. Please initialize cap auth to use this method");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const { isCapUser = false } = window.capAuth;
|
|
12
|
+
return isCapUser;
|
|
13
|
+
}
|