@capsitech/react-utilities 0.1.2

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 (44) hide show
  1. package/README.md +3 -0
  2. package/lib/Hooks/index.d.ts +45 -0
  3. package/lib/Hooks/index.js +98 -0
  4. package/lib/Hooks/useInfiniteScroll.d.ts +7 -0
  5. package/lib/Hooks/useInfiniteScroll.js +22 -0
  6. package/lib/Hooks/useNetworkState.d.ts +67 -0
  7. package/lib/Hooks/useNetworkState.js +41 -0
  8. package/lib/Hooks/useShortcuts.d.ts +4 -0
  9. package/lib/Hooks/useShortcuts.js +91 -0
  10. package/lib/Utilities/ApiUtility.axios.d.ts +60 -0
  11. package/lib/Utilities/ApiUtility.axios.js +305 -0
  12. package/lib/Utilities/BrowserInfo.d.ts +74 -0
  13. package/lib/Utilities/BrowserInfo.js +153 -0
  14. package/lib/Utilities/Countries.d.ts +14 -0
  15. package/lib/Utilities/Countries.js +290 -0
  16. package/lib/Utilities/CustomEventEmitter.d.ts +12 -0
  17. package/lib/Utilities/CustomEventEmitter.js +30 -0
  18. package/lib/Utilities/FastCompare.d.ts +1 -0
  19. package/lib/Utilities/FastCompare.js +128 -0
  20. package/lib/Utilities/HideablePromise.d.ts +5 -0
  21. package/lib/Utilities/HideablePromise.js +10 -0
  22. package/lib/Utilities/LoadScripts.d.ts +9 -0
  23. package/lib/Utilities/LoadScripts.js +51 -0
  24. package/lib/Utilities/MTDFraudPrevention.d.ts +28 -0
  25. package/lib/Utilities/MTDFraudPrevention.js +157 -0
  26. package/lib/Utilities/Nationalities.d.ts +5 -0
  27. package/lib/Utilities/Nationalities.js +245 -0
  28. package/lib/Utilities/RouteUtils.d.ts +120 -0
  29. package/lib/Utilities/RouteUtils.js +206 -0
  30. package/lib/Utilities/SuspenseRoute.d.ts +7 -0
  31. package/lib/Utilities/SuspenseRoute.js +10 -0
  32. package/lib/Utilities/TimeZones.d.ts +10 -0
  33. package/lib/Utilities/TimeZones.js +1069 -0
  34. package/lib/Utilities/Types.d.ts +19 -0
  35. package/lib/Utilities/Types.js +1 -0
  36. package/lib/Utilities/Utils.d.ts +174 -0
  37. package/lib/Utilities/Utils.js +331 -0
  38. package/lib/Utilities/dayjs.d.ts +18 -0
  39. package/lib/Utilities/dayjs.js +56 -0
  40. package/lib/Utilities/index.d.ts +15 -0
  41. package/lib/Utilities/index.js +15 -0
  42. package/lib/index.d.ts +2 -0
  43. package/lib/index.js +2 -0
  44. package/package.json +92 -0
@@ -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,5 @@
1
+ export declare const AllNationalities: string[];
2
+ export declare function getNationalityOptions(): {
3
+ key: string;
4
+ text: string;
5
+ }[];
@@ -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,120 @@
1
+ import React from "react";
2
+ import { RouteProps } from "react-router-dom";
3
+ export declare enum FeatureStatus {
4
+ placeholder = 0,
5
+ alpha = 1,
6
+ beta = 2,
7
+ release = 3
8
+ }
9
+ export interface IRouteProps extends RouteProps {
10
+ name?: string;
11
+ path?: string;
12
+ url?: string;
13
+ key?: string | number;
14
+ icon?: string;
15
+ isCategory?: boolean;
16
+ children?: React.ReactNode;
17
+ /**
18
+ * The component to render for this route's content (or a loading placeholder if `getComponent` is provided).
19
+ */
20
+ component?: any;
21
+ /**
22
+ * Function that loads the component asynchronously.
23
+ * Notify when loading has finished using `cb`.
24
+ * If `component` is provided, it will be rendered while waiting for the callback.
25
+ */
26
+ getComponent?: (cb: (component: any) => void) => void;
27
+ /**
28
+ * User roles to check for route rendering
29
+ */
30
+ roles?: string[];
31
+ /**
32
+ * Practice features to check for route rendering
33
+ */
34
+ features?: number[];
35
+ /**
36
+ * Business types to check for route rendering
37
+ */
38
+ businessTypes?: number[];
39
+ /**
40
+ * User config/tags to check for route rendering
41
+ */
42
+ userConfig?: string[];
43
+ /**
44
+ * User params to check for route rendering
45
+ */
46
+ userParams?: string[];
47
+ /**
48
+ * Other tags to check for route rendering
49
+ */
50
+ tags?: string[];
51
+ /**
52
+ * Sub/inner links
53
+ */
54
+ links?: IRouteProps[];
55
+ /**
56
+ * Other URL to show this link as active
57
+ */
58
+ activeUrl?: string;
59
+ /**
60
+ * Other URLs to show this link as active
61
+ */
62
+ activeUrls?: string[];
63
+ /**
64
+ * Default expanded or collapsed
65
+ */
66
+ isExpanded?: boolean;
67
+ /**
68
+ * Feature status (to show bedge on link)
69
+ */
70
+ status?: FeatureStatus;
71
+ }
72
+ export interface IRouteGroupProps {
73
+ /**
74
+ * Links to render within this group
75
+ */
76
+ links: IRouteProps[];
77
+ /**
78
+ * User roles to check for route rendering
79
+ */
80
+ roles?: string[];
81
+ /**
82
+ * Practice features to check for route rendering
83
+ */
84
+ features?: number[];
85
+ /**
86
+ * User config/tags to check for route rendering
87
+ */
88
+ userConfig?: string[];
89
+ /**
90
+ * Other tags to check for route rendering
91
+ */
92
+ tags?: string[];
93
+ /**
94
+ * Other URL to show this link as active
95
+ */
96
+ activeUrls?: string[];
97
+ /**
98
+ * Default expanded or collapsed
99
+ */
100
+ isExpanded?: boolean;
101
+ }
102
+ declare class RouteUtilsBase {
103
+ private hasValidRole;
104
+ private hasValidFeatures;
105
+ private hasValidBusinessType;
106
+ private hasValidUserConfig;
107
+ private hasValidUserParam;
108
+ private hasValidTags;
109
+ private isValidLink;
110
+ private getPath;
111
+ getRoutesFromGroups: (groups: IRouteGroupProps[], SecureRoute: any, roles?: string[], features?: number[], businessType?: number, userConfig?: any, userParams?: any, tags?: any, trimUrl?: string) => any[];
112
+ getRoutesFromGroup: (links: IRouteProps[], SecureRoute: any, roles?: string[], features?: number[], businessType?: number, userConfig?: any, userParams?: any, tags?: any, trimUrl?: string) => any[];
113
+ getLinksFromGroups: (links: IRouteGroupProps[], roles?: string[], features?: number[], businessType?: number, userConfig?: any, userParams?: any, currentPath?: string, params?: any, tags?: any) => IRouteGroupProps[];
114
+ getLinksFromGroup: (links: IRouteProps[], roles?: string[], features?: number[], businessType?: number, userConfig?: any, userParams?: any, currentPath?: string, params?: any, tags?: any) => IRouteProps[];
115
+ getRoutesFromLinks: (links: IRouteProps[], SecureRoute: any, roles?: string[], features?: number[], businessType?: number, userConfig?: any, userParams?: any, tags?: any, trimUrl?: string) => any[];
116
+ getLinksFromLinks: (links: IRouteProps[], roles?: string[], features?: number[], businessType?: number, userConfig?: any, userParams?: any, currentPath?: string, params?: any, tags?: any) => IRouteProps[];
117
+ getSelectedNavKey: (pagesGroup: IRouteGroupProps[], currentPath: string) => string | number | undefined;
118
+ }
119
+ export declare const RouteUtils: RouteUtilsBase;
120
+ export {};