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