@capillarytech/cap-ui-utils 1.2.0 → 1.2.1
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/auth/index.js +27 -17
- package/package.json +1 -1
package/auth/index.js
CHANGED
|
@@ -13,30 +13,36 @@ import authHoc from './authHoc';
|
|
|
13
13
|
import hasRole from './hasRole';
|
|
14
14
|
import isCapUser from './isCapUser';
|
|
15
15
|
|
|
16
|
+
const KEYS_EXEMPTED_FROM_VALIDATION = ['isCapUser']
|
|
16
17
|
/**
|
|
17
18
|
* Function to initialize the capAuth configurations to the document
|
|
18
19
|
* @param {*} authConfigs
|
|
19
20
|
*/
|
|
20
21
|
function _initialize(authConfigs) {
|
|
21
22
|
const capAuth = {};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
try {
|
|
24
|
+
if (!authConfigs.permissions) {
|
|
25
|
+
warn("Cannot initialize auth without permissions");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if(authConfigs.permissions) {
|
|
29
|
+
capAuth.permissions = Object.freeze(authConfigs.permissions);
|
|
30
|
+
}
|
|
31
|
+
if(authConfigs.orgFeatures) {
|
|
32
|
+
capAuth.orgFeatures = Object.freeze(authConfigs.orgFeatures);
|
|
33
|
+
}
|
|
34
|
+
if(authConfigs.roles) {
|
|
35
|
+
capAuth.roles = Object.freeze(authConfigs.roles);
|
|
36
|
+
}
|
|
37
|
+
if(authConfigs.isCapUser) {
|
|
38
|
+
capAuth.isCapUser = true;
|
|
39
|
+
}
|
|
40
|
+
log("Cap auth initialized");
|
|
41
|
+
window.capAuth = Object.freeze(capAuth);
|
|
34
42
|
}
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
catch(error) {
|
|
44
|
+
warn(error);
|
|
37
45
|
}
|
|
38
|
-
log("Cap auth initialized");
|
|
39
|
-
window.capAuth = Object.freeze(capAuth);
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
/**
|
|
@@ -53,7 +59,11 @@ function initialize(authConfigs, authOptions) {
|
|
|
53
59
|
return;
|
|
54
60
|
}
|
|
55
61
|
for ( const config in authConfigs) {
|
|
56
|
-
if(
|
|
62
|
+
if(KEYS_EXEMPTED_FROM_VALIDATION.includes(config)) {
|
|
63
|
+
//Skip validation
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if(!["object"].includes(typeof authConfigs[config])) {
|
|
57
67
|
warn("Config must be an object");
|
|
58
68
|
return;
|
|
59
69
|
}
|