@capsitech/react-utilities 0.1.10 → 0.1.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/lib/Components/SuspenseRoute.js +29 -0
- package/lib/Components/index.js +1 -0
- package/lib/Hooks/index.d.ts +2 -2
- package/lib/Hooks/index.js +98 -0
- package/lib/Hooks/useInfiniteScroll.d.ts +1 -1
- package/lib/Hooks/useInfiniteScroll.js +22 -0
- package/lib/Hooks/useNetworkState.js +41 -0
- package/lib/Hooks/useShortcuts.js +91 -0
- package/lib/Utilities/ApiUtility.axios.js +326 -0
- package/lib/Utilities/BrowserInfo.js +153 -0
- package/lib/Utilities/Countries.js +290 -0
- package/lib/Utilities/CustomEventEmitter.js +30 -0
- package/lib/Utilities/FastCompare.js +128 -0
- package/lib/Utilities/HideablePromise.js +10 -0
- package/lib/Utilities/LoadScripts.js +51 -0
- package/lib/Utilities/MTDFraudPrevention.js +157 -0
- package/lib/Utilities/Nationalities.js +245 -0
- package/lib/Utilities/RouteUtils.d.ts +1 -1
- package/lib/Utilities/RouteUtils.js +223 -0
- package/lib/Utilities/TimeZones.js +1069 -0
- package/lib/Utilities/Types.js +1 -0
- package/lib/Utilities/Utils.d.ts +1 -1
- package/lib/Utilities/Utils.js +331 -0
- package/lib/Utilities/dayjs.d.ts +11 -10
- package/lib/Utilities/dayjs.js +57 -0
- package/lib/Utilities/index.js +14 -0
- package/lib/index.js +3 -72
- package/package.json +10 -57
- package/lib/Components.d.ts +0 -2
- package/lib/Components.js +0 -5
- package/lib/Components.js.map +0 -1
- package/lib/Hooks.d.ts +0 -2
- package/lib/Hooks.js +0 -72
- package/lib/Hooks.js.map +0 -1
- package/lib/Utilities.d.ts +0 -2
- package/lib/Utilities.js +0 -54
- package/lib/Utilities.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/logo.png +0 -0
- package/lib/src/Components/SuspenseRoute.d.ts +0 -2
- package/lib/src/Components/SuspenseRoute.js +0 -22
- package/lib/src/Components/SuspenseRoute.js.map +0 -1
- package/lib/src/Components/index.d.ts +0 -2
- package/lib/src/Components/index.js +0 -5
- package/lib/src/Components/index.js.map +0 -1
- package/lib/src/Hooks/index.d.ts +0 -2
- package/lib/src/Hooks/index.js +0 -20
- package/lib/src/Hooks/index.js.map +0 -1
- package/lib/src/Hooks/useInfiniteScroll.d.ts +0 -2
- package/lib/src/Hooks/useInfiniteScroll.js +0 -20
- package/lib/src/Hooks/useInfiniteScroll.js.map +0 -1
- package/lib/src/Hooks/useNetworkState.d.ts +0 -2
- package/lib/src/Hooks/useNetworkState.js +0 -33
- package/lib/src/Hooks/useNetworkState.js.map +0 -1
- package/lib/src/Hooks/useShortcuts.d.ts +0 -2
- package/lib/src/Hooks/useShortcuts.js +0 -43
- package/lib/src/Hooks/useShortcuts.js.map +0 -1
- package/lib/src/Utilities/ApiUtility.axios.d.ts +0 -2
- package/lib/src/Utilities/ApiUtility.axios.js +0 -228
- package/lib/src/Utilities/ApiUtility.axios.js.map +0 -1
- package/lib/src/Utilities/BrowserInfo.d.ts +0 -2
- package/lib/src/Utilities/BrowserInfo.js +0 -51
- package/lib/src/Utilities/BrowserInfo.js.map +0 -1
- package/lib/src/Utilities/Countries.d.ts +0 -2
- package/lib/src/Utilities/Countries.js +0 -518
- package/lib/src/Utilities/Countries.js.map +0 -1
- package/lib/src/Utilities/CustomEventEmitter.d.ts +0 -2
- package/lib/src/Utilities/CustomEventEmitter.js +0 -27
- package/lib/src/Utilities/CustomEventEmitter.js.map +0 -1
- package/lib/src/Utilities/FastCompare.d.ts +0 -2
- package/lib/src/Utilities/FastCompare.js +0 -56
- package/lib/src/Utilities/FastCompare.js.map +0 -1
- package/lib/src/Utilities/HideablePromise.d.ts +0 -2
- package/lib/src/Utilities/HideablePromise.js +0 -18
- package/lib/src/Utilities/HideablePromise.js.map +0 -1
- package/lib/src/Utilities/LoadScripts.d.ts +0 -2
- package/lib/src/Utilities/LoadScripts.js +0 -26
- package/lib/src/Utilities/LoadScripts.js.map +0 -1
- package/lib/src/Utilities/MTDFraudPrevention.d.ts +0 -2
- package/lib/src/Utilities/MTDFraudPrevention.js +0 -60
- package/lib/src/Utilities/MTDFraudPrevention.js.map +0 -1
- package/lib/src/Utilities/Nationalities.d.ts +0 -2
- package/lib/src/Utilities/Nationalities.js +0 -250
- package/lib/src/Utilities/Nationalities.js.map +0 -1
- package/lib/src/Utilities/RouteUtils.d.ts +0 -2
- package/lib/src/Utilities/RouteUtils.js +0 -200
- package/lib/src/Utilities/RouteUtils.js.map +0 -1
- package/lib/src/Utilities/TimeZones.d.ts +0 -2
- package/lib/src/Utilities/TimeZones.js +0 -1074
- package/lib/src/Utilities/TimeZones.js.map +0 -1
- package/lib/src/Utilities/Types.d.ts +0 -1
- package/lib/src/Utilities/Types.js +0 -2
- package/lib/src/Utilities/Types.js.map +0 -1
- package/lib/src/Utilities/Utils.d.ts +0 -2
- package/lib/src/Utilities/Utils.js +0 -274
- package/lib/src/Utilities/Utils.js.map +0 -1
- package/lib/src/Utilities/dayjs.d.ts +0 -2
- package/lib/src/Utilities/dayjs.js +0 -42
- package/lib/src/Utilities/dayjs.js.map +0 -1
- package/lib/src/Utilities/index.d.ts +0 -2
- package/lib/src/Utilities/index.js +0 -54
- package/lib/src/Utilities/index.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const LoadScript = (src, opts, callback) => {
|
|
2
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
3
|
+
var script = document.createElement('script');
|
|
4
|
+
if (typeof opts === 'function') {
|
|
5
|
+
callback = opts;
|
|
6
|
+
opts = {};
|
|
7
|
+
}
|
|
8
|
+
opts = opts || {};
|
|
9
|
+
callback = callback || function () { };
|
|
10
|
+
script.type = opts.type || 'text/javascript';
|
|
11
|
+
script.charset = opts.charset || 'utf8';
|
|
12
|
+
script.async = 'async' in opts ? !!opts.async : true;
|
|
13
|
+
script.src = src;
|
|
14
|
+
if (opts.attrs) {
|
|
15
|
+
for (var attr in opts.attrs) {
|
|
16
|
+
script.setAttribute(attr, opts.attrs[attr]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (opts.text) {
|
|
20
|
+
script.text = '' + opts.text;
|
|
21
|
+
}
|
|
22
|
+
var onend = 'onload' in script ? stdOnEnd : ieOnEnd;
|
|
23
|
+
onend(script, callback);
|
|
24
|
+
// some good legacy browsers (firefox) fail the 'in' detection above
|
|
25
|
+
// so as a fallback we always set onload
|
|
26
|
+
// old IE will ignore this and new IE will set onload
|
|
27
|
+
if (!script.onload) {
|
|
28
|
+
stdOnEnd(script, callback);
|
|
29
|
+
}
|
|
30
|
+
head.appendChild(script);
|
|
31
|
+
};
|
|
32
|
+
function stdOnEnd(script, callback) {
|
|
33
|
+
script.onload = function () {
|
|
34
|
+
this.onerror = this.onload = null;
|
|
35
|
+
callback(null, script);
|
|
36
|
+
};
|
|
37
|
+
script.onerror = function () {
|
|
38
|
+
// this.onload = null here is necessary
|
|
39
|
+
// because even IE9 works not like others
|
|
40
|
+
this.onerror = this.onload = null;
|
|
41
|
+
callback(new Error('Failed to load ' + this.src), script);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function ieOnEnd(script, callback) {
|
|
45
|
+
script.onreadystatechange = function () {
|
|
46
|
+
if (this.readyState !== 'complete' && this.readyState !== 'loaded')
|
|
47
|
+
return;
|
|
48
|
+
this.onreadystatechange = null;
|
|
49
|
+
callback(null, script); // there is no way to catch loading errors in IE8
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { getScreenColourDepth, getScreenHeight, getScreenScalingFactor, getScreenWidth, getTimezone, getWindowHeight, getWindowWidth } from './BrowserInfo';
|
|
2
|
+
/**
|
|
3
|
+
* Enum object of keys for each header in the Map returned by getFraudPreventionHeaders().headers
|
|
4
|
+
*/
|
|
5
|
+
export const fraudPreventionHeadersEnum = {
|
|
6
|
+
TIMEZONE: 'Gov-Client-Timezone',
|
|
7
|
+
SCREENS_DETAILS: 'Gov-Client-Screens',
|
|
8
|
+
WINDOW_SIZE: 'Gov-Client-Window-Size',
|
|
9
|
+
//BROWSER_PLUGINS: 'Gov-Client-Browser-Plugins',
|
|
10
|
+
//BROWSER_DONOTTRACK: 'Gov-Client-Browser-Do-Not-Track',
|
|
11
|
+
//DEVICE_LOCAL_IPS: 'Gov-Client-Local-IPs',
|
|
12
|
+
//DEVICE_LOCAL_IPS_TIMESTAMP: 'Gov-Client-Local-IPs-Timestamp',
|
|
13
|
+
//DEVICE_ID: 'Gov-Client-Device-ID',
|
|
14
|
+
//BROWSER_USER_AGENT: 'Gov-Client-Browser-JS-User-Agent',
|
|
15
|
+
};
|
|
16
|
+
const getScreenData = () => {
|
|
17
|
+
const screenDetails = `width=${getScreenWidth()}&height=${getScreenHeight()}&scaling-factor=${getScreenScalingFactor()}&colour-depth=${getScreenColourDepth()}`;
|
|
18
|
+
return encodeURI(screenDetails);
|
|
19
|
+
};
|
|
20
|
+
export const getScreenDetails = () => {
|
|
21
|
+
return {
|
|
22
|
+
width: getScreenWidth(),
|
|
23
|
+
height: getScreenHeight(),
|
|
24
|
+
colorDepth: getScreenColourDepth(),
|
|
25
|
+
scalingFactor: getScreenScalingFactor(),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const getWindowSize = () => {
|
|
29
|
+
const windowSize = `width=${getWindowWidth()}&height=${getWindowHeight()}`;
|
|
30
|
+
return encodeURI(windowSize);
|
|
31
|
+
};
|
|
32
|
+
export const windowDetails = () => {
|
|
33
|
+
return {
|
|
34
|
+
width: getWindowWidth(),
|
|
35
|
+
height: getWindowHeight(),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Returns Map of HMRC Fraud prevention headers.
|
|
40
|
+
* @returns {Promise<IHeaderValues>} with two fields headers and errors - The headers are a Map object and the errors are an array. If there are no errors, the array is empty
|
|
41
|
+
*/
|
|
42
|
+
export const getFraudPreventionHeaders = async () => {
|
|
43
|
+
const headers = {};
|
|
44
|
+
const errors = [];
|
|
45
|
+
const headerFunctions = [
|
|
46
|
+
{ header: fraudPreventionHeadersEnum.TIMEZONE, callback: getTimezone },
|
|
47
|
+
{
|
|
48
|
+
header: fraudPreventionHeadersEnum.SCREENS_DETAILS,
|
|
49
|
+
callback: getScreenData,
|
|
50
|
+
},
|
|
51
|
+
{ header: fraudPreventionHeadersEnum.WINDOW_SIZE, callback: getWindowSize },
|
|
52
|
+
// {
|
|
53
|
+
// header: fraudPreventionHeadersEnum.BROWSER_PLUGINS,
|
|
54
|
+
// callback: () => encodeURI(getBrowserPluginsAsString()),
|
|
55
|
+
// },
|
|
56
|
+
// {
|
|
57
|
+
// header: fraudPreventionHeadersEnum.BROWSER_DONOTTRACK,
|
|
58
|
+
// callback: getBrowserDoNotTrackStatus,
|
|
59
|
+
// },
|
|
60
|
+
//{ header: fraudPreventionHeadersEnum.DEVICE_ID, callback: generateClientDeviceID},
|
|
61
|
+
//{ header: fraudPreventionHeadersEnum.BROWSER_USER_AGENT, callback: getUserAgent },
|
|
62
|
+
];
|
|
63
|
+
for (let i = 0; i < headerFunctions.length; i++) {
|
|
64
|
+
try {
|
|
65
|
+
const { header, callback } = headerFunctions[i];
|
|
66
|
+
headers[header] = callback();
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
errors.push({ header: headerFunctions[i], error });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// try {
|
|
73
|
+
// const ipAddress = await getDeviceLocalIPAsString();
|
|
74
|
+
// headers[fraudPreventionHeadersEnum.DEVICE_LOCAL_IPS] = encodeURI(ipAddress.deviceIpString);
|
|
75
|
+
// headers[fraudPreventionHeadersEnum.DEVICE_LOCAL_IPS_TIMESTAMP] = ipAddress.deviceIpTimeStamp;
|
|
76
|
+
// } catch (error) {
|
|
77
|
+
// errors.push({ header: 'IPs', error });
|
|
78
|
+
// }
|
|
79
|
+
return { headers, errors };
|
|
80
|
+
};
|
|
81
|
+
// /**
|
|
82
|
+
// * Returns "Gov-Client-Browser-JS-User-Agent" header.
|
|
83
|
+
// * @returns {IHeaderValue} which has headerValue key having the value of the header or error key if there is an error
|
|
84
|
+
// */
|
|
85
|
+
// export const getGovClientBrowserJSUserAgentHeader = (): IHeaderValue => {
|
|
86
|
+
// try {
|
|
87
|
+
// return { headerValue: getUserAgent() };
|
|
88
|
+
// } catch (error) {
|
|
89
|
+
// return { error };
|
|
90
|
+
// }
|
|
91
|
+
// };
|
|
92
|
+
// /**
|
|
93
|
+
// * Returns the value for Gov-Client-Browser-Plugins HMRC Fraud prevention header.
|
|
94
|
+
// */
|
|
95
|
+
// export const getGovClientBrowserPluginsHeader = (): IHeaderValue => {
|
|
96
|
+
// try {
|
|
97
|
+
// return { headerValue: encodeURI(getBrowserPluginsAsString()) };
|
|
98
|
+
// } catch (error) {
|
|
99
|
+
// return { error };
|
|
100
|
+
// }
|
|
101
|
+
// };
|
|
102
|
+
// /**
|
|
103
|
+
// * Returns the value for Gov-Client-Browser-Do-Not-Track HMRC Fraud prevention header.
|
|
104
|
+
// */
|
|
105
|
+
// export const getGovClientBrowserDoNotTrackHeader = (): IHeaderValue => {
|
|
106
|
+
// try {
|
|
107
|
+
// return { headerValue: getBrowserDoNotTrackStatus() };
|
|
108
|
+
// } catch (error) {
|
|
109
|
+
// return { error };
|
|
110
|
+
// }
|
|
111
|
+
// };
|
|
112
|
+
// /**
|
|
113
|
+
// * Returns the value for Gov-Client-Timezone HMRC Fraud prevention header.
|
|
114
|
+
// * @returns {IHeaderValue} with headerValue field or error field in case of an exception
|
|
115
|
+
// */
|
|
116
|
+
// export const getGovClientTimezoneHeader = (): IHeaderValue => {
|
|
117
|
+
// try {
|
|
118
|
+
// return { headerValue: getTimezone() };
|
|
119
|
+
// } catch (error) {
|
|
120
|
+
// return { error };
|
|
121
|
+
// }
|
|
122
|
+
// };
|
|
123
|
+
// /**
|
|
124
|
+
// * Returns Gov-Client-Local-IPs header value
|
|
125
|
+
// * @returns {Promise<IHeaderValue>} which has header key having the value of the header or error key if there is an error
|
|
126
|
+
// */
|
|
127
|
+
// export const getGovClientLocalIPsHeader = async (): Promise<IHeaderValue> => {
|
|
128
|
+
// try {
|
|
129
|
+
// const ipAddress = await getDeviceLocalIPAsString();
|
|
130
|
+
// return {
|
|
131
|
+
// headerValue: encodeURI(ipAddress.deviceIpString),
|
|
132
|
+
// };
|
|
133
|
+
// } catch (error) {
|
|
134
|
+
// return { error };
|
|
135
|
+
// }
|
|
136
|
+
// };
|
|
137
|
+
// /**
|
|
138
|
+
// * Returns the value for Gov-Client-Window-Size HMRC Fraud prevention header.
|
|
139
|
+
// */
|
|
140
|
+
// export const getGovClientWindowSizeHeader = () => {
|
|
141
|
+
// try {
|
|
142
|
+
// return { headerValue: getWindowSize() };
|
|
143
|
+
// } catch (error) {
|
|
144
|
+
// return { error };
|
|
145
|
+
// }
|
|
146
|
+
// };
|
|
147
|
+
// /**
|
|
148
|
+
// * Returns the value for Gov-Client-Screens HMRC Fraud prevention header.
|
|
149
|
+
// * @returns {object} with headerValue key having the value of the header or error key if there is an error
|
|
150
|
+
// */
|
|
151
|
+
// export const getGovClientScreensHeader = () => {
|
|
152
|
+
// try {
|
|
153
|
+
// return { headerValue: getScreenData() };
|
|
154
|
+
// } catch (error) {
|
|
155
|
+
// return { error };
|
|
156
|
+
// }
|
|
157
|
+
// };
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
export const AllNationalities = [
|
|
2
|
+
'Afghan',
|
|
3
|
+
'Albanian',
|
|
4
|
+
'Algerian',
|
|
5
|
+
'American Samoan',
|
|
6
|
+
'Andorran',
|
|
7
|
+
'Angolan',
|
|
8
|
+
'Anguillan',
|
|
9
|
+
'Antarctic',
|
|
10
|
+
'Antiguan or Barbudan',
|
|
11
|
+
'Argentine',
|
|
12
|
+
'Armenian',
|
|
13
|
+
'Aruban',
|
|
14
|
+
'Australian',
|
|
15
|
+
'Austrian',
|
|
16
|
+
'Azerbaijani',
|
|
17
|
+
'Bahamian',
|
|
18
|
+
'Bahraini',
|
|
19
|
+
'Bangladeshi',
|
|
20
|
+
'Barbadian',
|
|
21
|
+
'Belarusian',
|
|
22
|
+
'Belgian',
|
|
23
|
+
'Belizean',
|
|
24
|
+
'Bermudian',
|
|
25
|
+
'Bhutanese',
|
|
26
|
+
'Bolivian',
|
|
27
|
+
'Bosnian or Herzegovinian',
|
|
28
|
+
'Botswanan',
|
|
29
|
+
'Brazilian',
|
|
30
|
+
'British Indian Ocean Territory',
|
|
31
|
+
'British Virgin Islander',
|
|
32
|
+
'Bruneian',
|
|
33
|
+
'Bulgarian',
|
|
34
|
+
'Burkinabe',
|
|
35
|
+
'Burundian',
|
|
36
|
+
'Cambodian',
|
|
37
|
+
'Cameroonian',
|
|
38
|
+
'Canadian',
|
|
39
|
+
'Cape Verdean',
|
|
40
|
+
'Caymanian',
|
|
41
|
+
'Central African',
|
|
42
|
+
'Beninese',
|
|
43
|
+
'Chadian',
|
|
44
|
+
'Chilean',
|
|
45
|
+
'Chinese',
|
|
46
|
+
'Cocos Islander',
|
|
47
|
+
'Colombian',
|
|
48
|
+
'Comoran',
|
|
49
|
+
'Cook Islander',
|
|
50
|
+
'Costa Rican',
|
|
51
|
+
'Croatian',
|
|
52
|
+
'Cuban',
|
|
53
|
+
'Curacaoan',
|
|
54
|
+
'Cypriot',
|
|
55
|
+
'Czech',
|
|
56
|
+
'Congolese',
|
|
57
|
+
'Danish',
|
|
58
|
+
'Djiboutian',
|
|
59
|
+
'Dominican (Note: Different from Dominican Republic)',
|
|
60
|
+
'Dominican',
|
|
61
|
+
'Timorese or East Timorese',
|
|
62
|
+
'Ecuadorian',
|
|
63
|
+
'Egyptian',
|
|
64
|
+
'Christmas Islander',
|
|
65
|
+
'Salvadoran',
|
|
66
|
+
'Equatorial Guinean',
|
|
67
|
+
'Eritrean',
|
|
68
|
+
'Ethiopian',
|
|
69
|
+
'Falkland Islander',
|
|
70
|
+
'Faroese',
|
|
71
|
+
'Fijian',
|
|
72
|
+
'Finnish',
|
|
73
|
+
'French',
|
|
74
|
+
'French Polynesian',
|
|
75
|
+
'Gabonese',
|
|
76
|
+
'Gambian',
|
|
77
|
+
'Georgian',
|
|
78
|
+
'German',
|
|
79
|
+
'Ghanaian',
|
|
80
|
+
'Gibraltarian',
|
|
81
|
+
'Greek',
|
|
82
|
+
'Greenlandic',
|
|
83
|
+
'Grenadian',
|
|
84
|
+
'Guamanian',
|
|
85
|
+
'Guatemalan',
|
|
86
|
+
'Estonian',
|
|
87
|
+
'Guernsey (or Channel Islander)',
|
|
88
|
+
'Guinean',
|
|
89
|
+
'Bissau-Guinean',
|
|
90
|
+
'Haitian',
|
|
91
|
+
'Honduran',
|
|
92
|
+
'Hong Konger',
|
|
93
|
+
'Hungarian',
|
|
94
|
+
'Icelander',
|
|
95
|
+
'Indian',
|
|
96
|
+
'Indonesian',
|
|
97
|
+
'Iranian',
|
|
98
|
+
'Iraqi',
|
|
99
|
+
'Irish',
|
|
100
|
+
'Manx',
|
|
101
|
+
'Israeli',
|
|
102
|
+
'Italian',
|
|
103
|
+
'Ivorian',
|
|
104
|
+
'Jamaican',
|
|
105
|
+
'Japanese',
|
|
106
|
+
'Jersey (or Channel Islander)',
|
|
107
|
+
'Jordanian',
|
|
108
|
+
'Guyanese',
|
|
109
|
+
'Kazakhstani',
|
|
110
|
+
'Kenyan',
|
|
111
|
+
'I-Kiribati',
|
|
112
|
+
'Kuwaiti',
|
|
113
|
+
'Kyrgyzstani',
|
|
114
|
+
'Lao or Laotian',
|
|
115
|
+
'Latvian',
|
|
116
|
+
'Lebanese',
|
|
117
|
+
'Basotho or Lesothan',
|
|
118
|
+
'Liberian',
|
|
119
|
+
'Libyan',
|
|
120
|
+
'Liechtensteiner',
|
|
121
|
+
'Lithuanian',
|
|
122
|
+
'Luxembourger',
|
|
123
|
+
'Macanese',
|
|
124
|
+
'Macedonian',
|
|
125
|
+
'Malagasy',
|
|
126
|
+
'Malawian',
|
|
127
|
+
'Malaysian',
|
|
128
|
+
'Maldivian',
|
|
129
|
+
'Malian',
|
|
130
|
+
'Kosovar',
|
|
131
|
+
'Maltese',
|
|
132
|
+
'Marshallese',
|
|
133
|
+
'Mauritanian',
|
|
134
|
+
'Mahoran or Mayotte',
|
|
135
|
+
'Mexican',
|
|
136
|
+
'Micronesian',
|
|
137
|
+
'Moldovan',
|
|
138
|
+
'Monégasque',
|
|
139
|
+
'Mongolian',
|
|
140
|
+
'Montenegrin',
|
|
141
|
+
'Montserratian',
|
|
142
|
+
'Moroccan',
|
|
143
|
+
'Mozambican',
|
|
144
|
+
'Burmese or Myanmarese',
|
|
145
|
+
'Namibian',
|
|
146
|
+
'Nauruan',
|
|
147
|
+
'Nepali or Nepalese',
|
|
148
|
+
'Dutch',
|
|
149
|
+
'Netherlands Antillean',
|
|
150
|
+
'New Caledonian',
|
|
151
|
+
'New Zealander',
|
|
152
|
+
'Mauritian',
|
|
153
|
+
'Nicaraguan',
|
|
154
|
+
'Nigerien',
|
|
155
|
+
'Nigerian',
|
|
156
|
+
'North Korean',
|
|
157
|
+
'Northern Marianan',
|
|
158
|
+
'Norwegian',
|
|
159
|
+
'Omani',
|
|
160
|
+
'Pakistani',
|
|
161
|
+
'Palauan',
|
|
162
|
+
'Palestinian',
|
|
163
|
+
'Panamanian',
|
|
164
|
+
'Papua New Guinean',
|
|
165
|
+
'Paraguayan',
|
|
166
|
+
'Peruvian',
|
|
167
|
+
'Filipino',
|
|
168
|
+
'Pitcairn Islander',
|
|
169
|
+
'Polish',
|
|
170
|
+
'Portuguese',
|
|
171
|
+
'Puerto Rican',
|
|
172
|
+
'Qatari',
|
|
173
|
+
'Congolese',
|
|
174
|
+
'Niuean',
|
|
175
|
+
'Réunionese or Réunionnais',
|
|
176
|
+
'Romanian',
|
|
177
|
+
'Russian',
|
|
178
|
+
'Barthélemois or Saint Barthélemy Islander',
|
|
179
|
+
'Saint Helenian',
|
|
180
|
+
'Kittitian or Nevisian',
|
|
181
|
+
'Saint Lucian',
|
|
182
|
+
'Saint-Martinoise',
|
|
183
|
+
'Saint-Pierrais or Miquelonnais',
|
|
184
|
+
'Vincentian or Vincy',
|
|
185
|
+
'Samoan',
|
|
186
|
+
'Sammarinese',
|
|
187
|
+
'São Toméan',
|
|
188
|
+
'Saudi or Saudi Arabian',
|
|
189
|
+
'Senegalese',
|
|
190
|
+
'Serbian',
|
|
191
|
+
'Seychellois',
|
|
192
|
+
'Sierra Leonean',
|
|
193
|
+
'Singaporean',
|
|
194
|
+
'Sint Maartener or Sint Maartian',
|
|
195
|
+
'Slovak',
|
|
196
|
+
'Rwandan',
|
|
197
|
+
'Slovenian',
|
|
198
|
+
'Solomon Islander',
|
|
199
|
+
'Somali',
|
|
200
|
+
'South Korean',
|
|
201
|
+
'South Sudanese',
|
|
202
|
+
'Spanish',
|
|
203
|
+
'Sri Lankan',
|
|
204
|
+
'Sudanese',
|
|
205
|
+
'Surinamese',
|
|
206
|
+
'Svalbardian or Jan Mayenian',
|
|
207
|
+
'Swazi',
|
|
208
|
+
'Swedish',
|
|
209
|
+
'Swiss',
|
|
210
|
+
'Syrian',
|
|
211
|
+
'Taiwanese',
|
|
212
|
+
'Tajikistani',
|
|
213
|
+
'Tanzanian',
|
|
214
|
+
'Thai',
|
|
215
|
+
'Togolese',
|
|
216
|
+
'Tokelauan',
|
|
217
|
+
'Tongan',
|
|
218
|
+
'South African',
|
|
219
|
+
'Trinidadian or Tobagonian',
|
|
220
|
+
'Tunisian',
|
|
221
|
+
'Turkish',
|
|
222
|
+
'Turks and Caicos Islander',
|
|
223
|
+
'Tuvaluan',
|
|
224
|
+
'Virgin Islander',
|
|
225
|
+
'Ugandan',
|
|
226
|
+
'Ukrainian',
|
|
227
|
+
'Emirati or Emirian',
|
|
228
|
+
'British',
|
|
229
|
+
'American',
|
|
230
|
+
'Uruguayan',
|
|
231
|
+
'Uzbekistani',
|
|
232
|
+
'Vanuatuan',
|
|
233
|
+
'Vatican (or Vatican City)',
|
|
234
|
+
'Venezuelan',
|
|
235
|
+
'Vietnamese',
|
|
236
|
+
'Wallisian or Futunan',
|
|
237
|
+
'Sahrawi',
|
|
238
|
+
'Turkmen',
|
|
239
|
+
'Zambian',
|
|
240
|
+
'Zimbabwean',
|
|
241
|
+
'Yemeni',
|
|
242
|
+
];
|
|
243
|
+
export function getNationalityOptions() {
|
|
244
|
+
return AllNationalities.map((v) => ({ key: v, text: v }));
|
|
245
|
+
}
|
|
@@ -0,0 +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
|
+
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();
|