@capsitech/react-utilities 0.1.4 → 0.1.5
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/lib/Components/SuspenseRoute.d.ts +7 -7
- package/lib/Components/SuspenseRoute.js +29 -29
- package/lib/Components/index.d.ts +1 -1
- package/lib/Components/index.js +1 -1
- package/lib/Hooks/index.d.ts +45 -45
- package/lib/Hooks/index.js +98 -98
- package/lib/Hooks/useInfiniteScroll.d.ts +7 -7
- package/lib/Hooks/useInfiniteScroll.js +22 -22
- package/lib/Hooks/useNetworkState.d.ts +67 -67
- package/lib/Hooks/useNetworkState.js +41 -41
- package/lib/Hooks/useShortcuts.d.ts +4 -4
- package/lib/Hooks/useShortcuts.js +91 -91
- package/lib/Utilities/ApiUtility.axios.d.ts +60 -60
- package/lib/Utilities/ApiUtility.axios.js +305 -305
- package/lib/Utilities/BrowserInfo.d.ts +74 -74
- package/lib/Utilities/BrowserInfo.js +153 -153
- package/lib/Utilities/Countries.d.ts +14 -14
- package/lib/Utilities/Countries.js +290 -290
- package/lib/Utilities/CustomEventEmitter.d.ts +12 -12
- package/lib/Utilities/CustomEventEmitter.js +30 -30
- package/lib/Utilities/FastCompare.d.ts +1 -1
- package/lib/Utilities/FastCompare.js +128 -128
- package/lib/Utilities/HideablePromise.d.ts +5 -5
- package/lib/Utilities/HideablePromise.js +10 -10
- package/lib/Utilities/LoadScripts.d.ts +9 -9
- package/lib/Utilities/LoadScripts.js +51 -51
- package/lib/Utilities/MTDFraudPrevention.d.ts +28 -28
- package/lib/Utilities/MTDFraudPrevention.js +157 -157
- package/lib/Utilities/Nationalities.d.ts +5 -5
- package/lib/Utilities/Nationalities.js +245 -245
- package/lib/Utilities/RouteUtils.d.ts +129 -120
- package/lib/Utilities/RouteUtils.js +223 -206
- package/lib/Utilities/TimeZones.d.ts +10 -10
- package/lib/Utilities/TimeZones.js +1069 -1069
- package/lib/Utilities/Types.d.ts +19 -19
- package/lib/Utilities/Types.js +1 -1
- package/lib/Utilities/Utils.d.ts +174 -174
- package/lib/Utilities/Utils.js +331 -331
- package/lib/Utilities/dayjs.d.ts +18 -18
- package/lib/Utilities/dayjs.js +56 -56
- package/lib/Utilities/index.d.ts +14 -14
- package/lib/Utilities/index.js +14 -14
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -3
- package/package.json +12 -25
|
@@ -1,206 +1,223 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { matchPath, Route } from "react-router
|
|
3
|
-
import { SuspenseRoute } from "../Components/SuspenseRoute";
|
|
4
|
-
export var FeatureStatus;
|
|
5
|
-
(function (FeatureStatus) {
|
|
6
|
-
FeatureStatus[FeatureStatus["placeholder"] = 0] = "placeholder";
|
|
7
|
-
FeatureStatus[FeatureStatus["alpha"] = 1] = "alpha";
|
|
8
|
-
FeatureStatus[FeatureStatus["beta"] = 2] = "beta";
|
|
9
|
-
FeatureStatus[FeatureStatus["release"] = 3] = "release";
|
|
10
|
-
})(FeatureStatus || (FeatureStatus = {}));
|
|
11
|
-
class RouteUtilsBase {
|
|
12
|
-
hasValidRole = (rolesRequired, rolesExists) => {
|
|
13
|
-
if (!rolesRequired || !rolesExists)
|
|
14
|
-
return true;
|
|
15
|
-
return rolesRequired.some((r) => rolesExists.includes(r));
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
return true;
|
|
20
|
-
return
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
return routes;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
for (const link of links) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return routes;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const routes = [];
|
|
162
|
-
for (const link of links) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { matchPath, Route } from "react-router";
|
|
3
|
+
import { SuspenseRoute } from "../Components/SuspenseRoute";
|
|
4
|
+
export var FeatureStatus;
|
|
5
|
+
(function (FeatureStatus) {
|
|
6
|
+
FeatureStatus[FeatureStatus["placeholder"] = 0] = "placeholder";
|
|
7
|
+
FeatureStatus[FeatureStatus["alpha"] = 1] = "alpha";
|
|
8
|
+
FeatureStatus[FeatureStatus["beta"] = 2] = "beta";
|
|
9
|
+
FeatureStatus[FeatureStatus["release"] = 3] = "release";
|
|
10
|
+
})(FeatureStatus || (FeatureStatus = {}));
|
|
11
|
+
class RouteUtilsBase {
|
|
12
|
+
hasValidRole = (rolesRequired, rolesExists) => {
|
|
13
|
+
if (!rolesRequired || !rolesExists)
|
|
14
|
+
return true;
|
|
15
|
+
return rolesRequired.some((r) => rolesExists.includes(r));
|
|
16
|
+
};
|
|
17
|
+
hasValidPermission = (permissionsRequired, permissionsExists) => {
|
|
18
|
+
if (!permissionsRequired || !permissionsExists)
|
|
19
|
+
return true;
|
|
20
|
+
return permissionsRequired.some((p) => permissionsExists.includes(p));
|
|
21
|
+
};
|
|
22
|
+
hasValidRoleOrPermission = (rolesRequired, rolesExists, permissionsRequired, permissionsExists) => {
|
|
23
|
+
// If roles are specified and user has valid roles, grant access
|
|
24
|
+
if (rolesRequired && rolesExists && this.hasValidRole(rolesRequired, rolesExists)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
// If roles are specified but user doesn't have valid roles, deny access
|
|
28
|
+
if (rolesRequired && rolesExists && rolesRequired.length > 0) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// If no roles specified, check permissions
|
|
32
|
+
return this.hasValidPermission(permissionsRequired, permissionsExists);
|
|
33
|
+
};
|
|
34
|
+
hasValidFeatures = (featuresRequired, featuresExists) => {
|
|
35
|
+
if (featuresRequired === undefined || featuresRequired === null)
|
|
36
|
+
return true;
|
|
37
|
+
return featuresExists && featuresRequired.some((r) => featuresExists.includes(r));
|
|
38
|
+
};
|
|
39
|
+
hasValidBusinessType = (typesRequired, businessType) => {
|
|
40
|
+
if (typesRequired === undefined ||
|
|
41
|
+
typesRequired === null ||
|
|
42
|
+
businessType === undefined ||
|
|
43
|
+
businessType === null)
|
|
44
|
+
return true;
|
|
45
|
+
return typesRequired?.some((v) => v === businessType);
|
|
46
|
+
};
|
|
47
|
+
hasValidUserConfig = (configRequired, configExists) => {
|
|
48
|
+
if (configRequired == undefined || configRequired === null || !configExists)
|
|
49
|
+
return true;
|
|
50
|
+
return Object.keys(configExists).some((key) => {
|
|
51
|
+
return configExists[key] && configRequired?.some((v) => v === key);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
hasValidUserParam = (paramsRequired, paramsExists) => {
|
|
55
|
+
if (paramsRequired == undefined || paramsRequired === null || !paramsExists)
|
|
56
|
+
return true;
|
|
57
|
+
return Object.keys(paramsExists).some((key) => {
|
|
58
|
+
return paramsExists[key] && paramsExists[key]?.enabled && paramsRequired?.some((v) => v === key);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
hasValidTags = (tagsRequired, tagsExists) => {
|
|
62
|
+
if (!tagsRequired || !tagsExists)
|
|
63
|
+
return true;
|
|
64
|
+
return Object.keys(tagsExists).some((key) => {
|
|
65
|
+
return tagsExists[key] && tagsRequired?.some((v) => v === key);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
isValidLink = (link, rolesExists, permissionsExists, featuresExists, businessType, configExists, paramsExists, tagsExists) => {
|
|
69
|
+
//check for user role or permission (roles take precedence)
|
|
70
|
+
if (!this.hasValidRoleOrPermission(link.roles, rolesExists, link.permissions, permissionsExists))
|
|
71
|
+
return false;
|
|
72
|
+
//check for app feature
|
|
73
|
+
if (!this.hasValidFeatures(link.features, featuresExists))
|
|
74
|
+
return false;
|
|
75
|
+
//check for user config
|
|
76
|
+
if (!this.hasValidUserConfig(link.userConfig, configExists))
|
|
77
|
+
return false;
|
|
78
|
+
//check for user params
|
|
79
|
+
if (!this.hasValidUserParam(link.userParams, paramsExists))
|
|
80
|
+
return false;
|
|
81
|
+
//check for business type
|
|
82
|
+
if (!this.hasValidBusinessType(link.businessTypes, businessType))
|
|
83
|
+
return false;
|
|
84
|
+
//check for tag
|
|
85
|
+
if (!this.hasValidTags(link.tags, tagsExists))
|
|
86
|
+
return false;
|
|
87
|
+
return true;
|
|
88
|
+
};
|
|
89
|
+
getPath = (link, trimUrl) => {
|
|
90
|
+
if (trimUrl && link?.url) {
|
|
91
|
+
return link.url.replace(trimUrl, '');
|
|
92
|
+
}
|
|
93
|
+
return link.url;
|
|
94
|
+
};
|
|
95
|
+
getRoutesFromGroups = (groups, SecureRoute, userRoles, userPermissions, features, businessType, userConfig, userParams, tags, trimUrl) => {
|
|
96
|
+
const routes = [];
|
|
97
|
+
for (const group of groups) {
|
|
98
|
+
routes.push(this.getRoutesFromGroup(group.links, SecureRoute, userRoles, userPermissions, features, businessType, userConfig, userParams, tags, trimUrl));
|
|
99
|
+
}
|
|
100
|
+
return routes;
|
|
101
|
+
};
|
|
102
|
+
getRoutesFromGroup = (links, SecureRoute, userRoles, userPermissions, features, businessType, userConfig, userParams, tags, trimUrl) => {
|
|
103
|
+
const routes = [];
|
|
104
|
+
for (const link of links) {
|
|
105
|
+
if (link.component) {
|
|
106
|
+
//check for valid link
|
|
107
|
+
if (!this.isValidLink(link, userRoles, userPermissions, features, businessType, userConfig, userParams, tags))
|
|
108
|
+
continue;
|
|
109
|
+
//const exact = typeof link.exact === 'undefined' ? true : link.exact;
|
|
110
|
+
routes.push(link.roles || link.features ? (_jsx(Route, { path: this.getPath(link, trimUrl), element: _jsx(SecureRoute, { component: link.component, roles: link.roles }) }, link.key)) : (_jsx(Route, { path: this.getPath(link, trimUrl), element: _jsx(SuspenseRoute, { children: link.component }) }, link.key)));
|
|
111
|
+
}
|
|
112
|
+
//add nested links
|
|
113
|
+
if (link.links) {
|
|
114
|
+
routes.push(...this.getRoutesFromGroup(link.links, SecureRoute, userRoles, userPermissions, features, businessType, userConfig, userParams, tags, trimUrl));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return routes;
|
|
118
|
+
};
|
|
119
|
+
getLinksFromGroups = (links, userRoles, userPermissions, features, businessType, userConfig, userParams, currentPath, params, tags) => {
|
|
120
|
+
const groups = [];
|
|
121
|
+
for (const link of links) {
|
|
122
|
+
//check for valid link
|
|
123
|
+
if (!this.isValidLink(link, userRoles, userPermissions, features, businessType, userConfig, userParams, tags))
|
|
124
|
+
continue;
|
|
125
|
+
groups.push(link);
|
|
126
|
+
//add nested links
|
|
127
|
+
if (link.links) {
|
|
128
|
+
link.links = this.getLinksFromGroup(link.links, userRoles, userPermissions, features, businessType, userConfig, userParams, currentPath, params, tags);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return groups;
|
|
132
|
+
};
|
|
133
|
+
getLinksFromGroup = (links, userRoles, userPermissions, features, businessType, userConfig, userParams, currentPath, params, tags) => {
|
|
134
|
+
const routes = [];
|
|
135
|
+
for (const link of links) {
|
|
136
|
+
//check for valid link
|
|
137
|
+
if (!this.isValidLink(link, userRoles, userPermissions, features, businessType, userConfig, userParams, tags))
|
|
138
|
+
continue;
|
|
139
|
+
let url = link.url, activeUrl = link.activeUrl;
|
|
140
|
+
if (url && params) {
|
|
141
|
+
for (const key in params) {
|
|
142
|
+
url = url?.replace(`:${key}`, params[key]);
|
|
143
|
+
if (activeUrl)
|
|
144
|
+
activeUrl = activeUrl.replace(`:${key}`, params[key]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
link.url = url;
|
|
148
|
+
link.activeUrl = activeUrl;
|
|
149
|
+
routes.push(link);
|
|
150
|
+
//add nested links
|
|
151
|
+
if (link.links) {
|
|
152
|
+
if (currentPath && link.activeUrl) {
|
|
153
|
+
link.isExpanded = link.url === currentPath || currentPath.indexOf(link.activeUrl) === 0;
|
|
154
|
+
}
|
|
155
|
+
link.links = this.getLinksFromGroup(link.links, userRoles, userPermissions, features, businessType, userConfig, userParams, currentPath, params, tags);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return routes;
|
|
159
|
+
};
|
|
160
|
+
getRoutesFromLinks = (links, SecureRoute, userRoles, userPermissions, features, businessType, userConfig, userParams, tags, trimUrl) => {
|
|
161
|
+
const routes = [];
|
|
162
|
+
for (const link of links) {
|
|
163
|
+
if (link.component) {
|
|
164
|
+
//check for valid link
|
|
165
|
+
if (!this.isValidLink(link, userRoles, userPermissions, features, businessType, userConfig, userParams, tags))
|
|
166
|
+
continue;
|
|
167
|
+
//const exact = typeof link.exact === 'undefined' ? true : link.exact;
|
|
168
|
+
routes.push(link.roles ? (_jsx(Route, { path: this.getPath(link, trimUrl), element: _jsx(SecureRoute, { component: link.component, roles: link.roles }) }, link.key)) : (_jsx(Route, { path: this.getPath(link, trimUrl) || '#', element: _jsx(SuspenseRoute, { children: link.component }) }, link.key)));
|
|
169
|
+
}
|
|
170
|
+
//add nested links
|
|
171
|
+
if (link.links) {
|
|
172
|
+
routes.push(...this.getRoutesFromLinks(link.links, SecureRoute, userRoles, userPermissions, features, businessType, userConfig, userParams, tags, trimUrl));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return routes;
|
|
176
|
+
};
|
|
177
|
+
getLinksFromLinks = (links, userRoles, userPermissions, features, businessType, userConfig, userParams, currentPath, params, tags) => {
|
|
178
|
+
const routes = [];
|
|
179
|
+
for (const link of links) {
|
|
180
|
+
//check for valid link
|
|
181
|
+
if (!this.isValidLink(link, userRoles, userPermissions, features, businessType, userConfig, userParams, tags))
|
|
182
|
+
continue;
|
|
183
|
+
let url = link.url, activeUrl = link.activeUrl;
|
|
184
|
+
if (url && params) {
|
|
185
|
+
for (const key in params) {
|
|
186
|
+
url = url?.replace(`:${key}`, params[key]);
|
|
187
|
+
if (activeUrl)
|
|
188
|
+
activeUrl = activeUrl.replace(`:${key}`, params[key]);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
link.url = url;
|
|
192
|
+
link.activeUrl = activeUrl;
|
|
193
|
+
routes.push(link);
|
|
194
|
+
//add nested links
|
|
195
|
+
if (link.links) {
|
|
196
|
+
if (currentPath && link.activeUrl) {
|
|
197
|
+
link.isExpanded = link.url === currentPath || currentPath.indexOf(link.activeUrl) === 0;
|
|
198
|
+
}
|
|
199
|
+
link.links = this.getLinksFromLinks(link.links, userRoles, userPermissions, features, businessType, userConfig, userParams, currentPath, params, tags);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return routes;
|
|
203
|
+
};
|
|
204
|
+
getSelectedNavKey = (pagesGroup, currentPath) => {
|
|
205
|
+
let selectedLink = undefined;
|
|
206
|
+
for (const group of pagesGroup) {
|
|
207
|
+
selectedLink = group.links
|
|
208
|
+
.flatMap((l) => {
|
|
209
|
+
if (l.links)
|
|
210
|
+
return l.links;
|
|
211
|
+
else
|
|
212
|
+
return [l];
|
|
213
|
+
})
|
|
214
|
+
.find((l) => l.url === currentPath ||
|
|
215
|
+
(l.activeUrls && l.activeUrls.some((la) => matchPath(la, currentPath))) ||
|
|
216
|
+
matchPath(l.url, currentPath));
|
|
217
|
+
if (selectedLink)
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return selectedLink?.key;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export const RouteUtils = new RouteUtilsBase();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export interface ITimeZone {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
utc: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const AllTimeZones: ITimeZone[];
|
|
7
|
-
export declare function getTimeZoneOptions(): {
|
|
8
|
-
key: string;
|
|
9
|
-
text: string;
|
|
10
|
-
}[];
|
|
1
|
+
export interface ITimeZone {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
utc: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const AllTimeZones: ITimeZone[];
|
|
7
|
+
export declare function getTimeZoneOptions(): {
|
|
8
|
+
key: string;
|
|
9
|
+
text: string;
|
|
10
|
+
}[];
|