@abcagency/hc-ui-components 1.3.14 → 1.3.16
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/dist/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/dist/apis/hcApi.js +1 -1
- package/dist/apis/hcApi.js.map +1 -1
- package/dist/clientToken.js.map +1 -1
- package/dist/components/HireControlMap.js +15 -5
- package/dist/components/HireControlMap.js.map +1 -1
- package/dist/components/modules/accordions/MapAccordionItem.js +11 -1
- package/dist/components/modules/accordions/MapAccordionItem.js.map +1 -1
- package/dist/components/modules/accordions/default.js.map +1 -1
- package/dist/components/modules/accordions/filterItem.js +2 -1
- package/dist/components/modules/accordions/filterItem.js.map +1 -1
- package/dist/components/modules/accordions/filters.js +0 -3
- package/dist/components/modules/accordions/filters.js.map +1 -1
- package/dist/components/modules/buttons/button-group-apply.js +36 -15
- package/dist/components/modules/buttons/button-group-apply.js.map +1 -1
- package/dist/components/modules/buttons/commute-pill.js.map +1 -1
- package/dist/components/modules/buttons/default.js.map +1 -1
- package/dist/components/modules/buttons/items-pill.js.map +1 -1
- package/dist/components/modules/buttons/pill-wrapper.js.map +1 -1
- package/dist/components/modules/buttons/show-all-button.js.map +1 -1
- package/dist/components/modules/cards/default.js.map +1 -1
- package/dist/components/modules/cards/filter.js.map +1 -1
- package/dist/components/modules/dialogs/apply-dialog.js.map +1 -1
- package/dist/components/modules/filter/commute.js +22 -6
- package/dist/components/modules/filter/commute.js.map +1 -1
- package/dist/components/modules/filter/index.js +7 -0
- package/dist/components/modules/filter/index.js.map +1 -1
- package/dist/components/modules/filter/item.js +16 -1
- package/dist/components/modules/filter/item.js.map +1 -1
- package/dist/components/modules/filter/location.js +1 -1
- package/dist/components/modules/filter/location.js.map +1 -1
- package/dist/components/modules/filter/points-of-interest.js.map +1 -1
- package/dist/components/modules/filter/radio-item.js +7 -0
- package/dist/components/modules/filter/radio-item.js.map +1 -1
- package/dist/components/modules/filter/search.js.map +1 -1
- package/dist/components/modules/filter/sort.js.map +1 -1
- package/dist/components/modules/grid.js.map +1 -1
- package/dist/components/modules/icon.js.map +1 -1
- package/dist/components/modules/jobListing/listing-details.js +6 -0
- package/dist/components/modules/jobListing/listing-details.js.map +1 -1
- package/dist/components/modules/maps/info-window-card.js.map +1 -1
- package/dist/components/modules/maps/info-window-content.js +20 -0
- package/dist/components/modules/maps/info-window-content.js.map +1 -1
- package/dist/components/modules/maps/list/field-mapper.js.map +1 -1
- package/dist/components/modules/maps/list/header-item.js.map +1 -1
- package/dist/components/modules/maps/list/header.js.map +1 -1
- package/dist/components/modules/maps/list/index.js +21 -12
- package/dist/components/modules/maps/list/index.js.map +1 -1
- package/dist/components/modules/maps/list/item-expand-card/index.js.map +1 -1
- package/dist/components/modules/maps/list/item-expand-card/recruiter-contact-nav.js.map +1 -1
- package/dist/components/modules/maps/list/item-expand-card/recruiter-details.js.map +1 -1
- package/dist/components/modules/maps/list/item-expand-card/recruiter-headshot.js.map +1 -1
- package/dist/components/modules/maps/list/list-item/index.js +12 -2
- package/dist/components/modules/maps/list/list-item/index.js.map +1 -1
- package/dist/components/modules/maps/map-list.js.map +1 -1
- package/dist/components/modules/maps/map-marker.js +10 -0
- package/dist/components/modules/maps/map-marker.js.map +1 -1
- package/dist/components/modules/maps/map.js.map +1 -1
- package/dist/components/modules/maps/place-marker.js.map +1 -1
- package/dist/components/modules/maps/tabs.js.map +1 -1
- package/dist/constants/eventTypes.js +16 -0
- package/dist/constants/eventTypes.js.map +1 -0
- package/dist/constants/placeTypes.js.map +1 -1
- package/dist/contexts/mapContext.js +9 -27
- package/dist/contexts/mapContext.js.map +1 -1
- package/dist/contexts/mapListContext.js +57 -38
- package/dist/contexts/mapListContext.js.map +1 -1
- package/dist/contexts/placesContext.js.map +1 -1
- package/dist/contexts/trackEventContext.js +20 -0
- package/dist/contexts/trackEventContext.js.map +1 -0
- package/dist/hooks/useList.js +1 -13
- package/dist/hooks/useList.js.map +1 -1
- package/dist/services/apis/hcApi.js +1 -1
- package/dist/services/apis/hcApi.js.map +1 -1
- package/dist/services/clientToken.js.map +1 -1
- package/dist/services/configService.js.map +1 -1
- package/dist/services/googlePlacesNearbyService.js.map +1 -1
- package/dist/services/listingAggregatorService.js +43 -16
- package/dist/services/listingAggregatorService.js.map +1 -1
- package/dist/services/listingEntityService.js.map +1 -1
- package/dist/services/listingService.js.map +1 -1
- package/dist/services/recruiterService.js.map +1 -1
- package/dist/util/filterUtil.js.map +1 -1
- package/dist/util/loading.js.map +1 -1
- package/dist/util/localStorageUtil.js.map +1 -1
- package/dist/util/mapIconUtil.js.map +1 -1
- package/dist/util/mapUtil.js.map +1 -1
- package/dist/util/sortUtil.js.map +1 -1
- package/dist/util/stringUtils.js.map +1 -1
- package/jsconfig.json +7 -7
- package/package.json +60 -60
- package/postcss.config.js +13 -13
- package/preset.default.js +15 -15
- package/rollup.config.mjs +88 -87
- package/src/apis/hcApi.js +93 -93
- package/src/clientToken.js +9 -9
- package/src/components/HireControlMap.js +129 -124
- package/src/components/modules/accordions/MapAccordionItem.js +74 -72
- package/src/components/modules/accordions/default.js +171 -171
- package/src/components/modules/accordions/filterItem.js +55 -53
- package/src/components/modules/accordions/filters.js +47 -47
- package/src/components/modules/buttons/button-group-apply.js +123 -116
- package/src/components/modules/buttons/commute-pill.js +22 -22
- package/src/components/modules/buttons/default.js +194 -194
- package/src/components/modules/buttons/items-pill.js +35 -35
- package/src/components/modules/buttons/pill-wrapper.js +27 -27
- package/src/components/modules/buttons/show-all-button.js +20 -20
- package/src/components/modules/cards/default.js +167 -167
- package/src/components/modules/cards/filter.js +56 -56
- package/src/components/modules/dialogs/apply-dialog.js +48 -48
- package/src/components/modules/filter/commute.js +154 -149
- package/src/components/modules/filter/index.js +89 -87
- package/src/components/modules/filter/item.js +87 -76
- package/src/components/modules/filter/location.js +71 -71
- package/src/components/modules/filter/points-of-interest.js +44 -44
- package/src/components/modules/filter/radio-item.js +57 -53
- package/src/components/modules/filter/search.js +92 -92
- package/src/components/modules/filter/sort.js +83 -83
- package/src/components/modules/grid.js +54 -54
- package/src/components/modules/icon.js +33 -33
- package/src/components/modules/jobListing/listing-details.js +99 -95
- package/src/components/modules/maps/info-window-card.js +17 -17
- package/src/components/modules/maps/info-window-content.js +81 -74
- package/src/components/modules/maps/list/field-mapper.js +112 -112
- package/src/components/modules/maps/list/header-item.js +91 -91
- package/src/components/modules/maps/list/header.js +47 -47
- package/src/components/modules/maps/list/index.js +112 -107
- package/src/components/modules/maps/list/item-expand-card/index.js +22 -22
- package/src/components/modules/maps/list/item-expand-card/recruiter-contact-nav.js +50 -50
- package/src/components/modules/maps/list/item-expand-card/recruiter-details.js +68 -68
- package/src/components/modules/maps/list/item-expand-card/recruiter-headshot.js +22 -22
- package/src/components/modules/maps/list/list-item/index.js +135 -133
- package/src/components/modules/maps/map-list.js +74 -74
- package/src/components/modules/maps/map-marker.js +88 -86
- package/src/components/modules/maps/map.js +230 -230
- package/src/components/modules/maps/place-marker.js +41 -41
- package/src/components/modules/maps/tabs.js +81 -81
- package/src/constants/eventTypes.js +13 -0
- package/src/constants/placeTypes.js +8 -8
- package/src/contexts/mapContext.js +101 -115
- package/src/contexts/mapListContext.js +242 -222
- package/src/contexts/placesContext.js +102 -102
- package/src/contexts/trackEventContext.js +14 -0
- package/src/hooks/useList.js +89 -100
- package/src/index.js +3 -3
- package/src/services/configService.js +16 -16
- package/src/services/googlePlacesNearbyService.js +33 -33
- package/src/services/listingAggregatorService.js +50 -45
- package/src/services/listingEntityService.js +15 -15
- package/src/services/listingService.js +26 -26
- package/src/services/recruiterService.js +17 -17
- package/src/styles/index.css +23 -23
- package/src/util/arrayUtil.js +3 -3
- package/src/util/fieldMapper.js +22 -22
- package/src/util/filterUtil.js +195 -195
- package/src/util/loading.js +17 -17
- package/src/util/localStorageUtil.js +26 -26
- package/src/util/mapIconUtil.js +180 -180
- package/src/util/mapUtil.js +91 -91
- package/src/util/sortUtil.js +32 -32
- package/src/util/stringUtils.js +6 -6
- package/src/util/urlFilterUtil.js +90 -90
- package/tailwind.config.js +126 -126
- package/.editorconfig +0 -12
- package/.eslintrc +0 -105
- package/.prettierignore +0 -3
package/preset.default.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = {
|
|
3
|
-
theme: {
|
|
4
|
-
extend: {
|
|
5
|
-
colors: {
|
|
6
|
-
"uiText": "#141414",
|
|
7
|
-
"uiAccent": "#0f172a",
|
|
8
|
-
"primary": "#002575",
|
|
9
|
-
"primaryDark": "#001f5f",
|
|
10
|
-
"secondary": "#ff612b",
|
|
11
|
-
"secondaryDark": "#bf900d"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
theme: {
|
|
4
|
+
extend: {
|
|
5
|
+
colors: {
|
|
6
|
+
"uiText": "#141414",
|
|
7
|
+
"uiAccent": "#0f172a",
|
|
8
|
+
"primary": "#002575",
|
|
9
|
+
"primaryDark": "#001f5f",
|
|
10
|
+
"secondary": "#ff612b",
|
|
11
|
+
"secondaryDark": "#bf900d"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
package/rollup.config.mjs
CHANGED
|
@@ -1,87 +1,88 @@
|
|
|
1
|
-
import babel from '@rollup/plugin-babel';
|
|
2
|
-
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve';
|
|
3
|
-
import external from 'rollup-plugin-peer-deps-external';
|
|
4
|
-
import alias from '@rollup/plugin-alias';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
7
|
-
import replace from '@rollup/plugin-replace';
|
|
8
|
-
import dotenv from 'dotenv';
|
|
9
|
-
import postcss from 'rollup-plugin-postcss';
|
|
10
|
-
import { fileURLToPath } from 'url';
|
|
11
|
-
import tailwindcss from 'tailwindcss';
|
|
12
|
-
import autoprefixer from 'autoprefixer';
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'process.env.
|
|
40
|
-
'process.env.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
'react
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
import babel from '@rollup/plugin-babel';
|
|
2
|
+
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve';
|
|
3
|
+
import external from 'rollup-plugin-peer-deps-external';
|
|
4
|
+
import alias from '@rollup/plugin-alias';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
7
|
+
import replace from '@rollup/plugin-replace';
|
|
8
|
+
import dotenv from 'dotenv';
|
|
9
|
+
import postcss from 'rollup-plugin-postcss';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
import tailwindcss from 'tailwindcss';
|
|
12
|
+
import autoprefixer from 'autoprefixer';
|
|
13
|
+
|
|
14
|
+
// Convert file URL to file path
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = path.dirname(__filename);
|
|
17
|
+
|
|
18
|
+
// Load environment variables from .env file
|
|
19
|
+
dotenv.config({ path: path.resolve(__dirname, '.env') });
|
|
20
|
+
console.log('GOOGLE_MAPS_API_KEY:', process.env.GOOGLE_MAPS_API_KEY);
|
|
21
|
+
|
|
22
|
+
// Resolve the project root directory
|
|
23
|
+
const projectRootDir = path.resolve(__dirname);
|
|
24
|
+
|
|
25
|
+
const plugins = [
|
|
26
|
+
external(),
|
|
27
|
+
resolve(),
|
|
28
|
+
postcss({
|
|
29
|
+
extensions: ['.css'],
|
|
30
|
+
extract: 'styles/index.css',
|
|
31
|
+
minimize: true,
|
|
32
|
+
plugins: [
|
|
33
|
+
tailwindcss(path.resolve(__dirname, 'tailwind.config.js')),
|
|
34
|
+
autoprefixer
|
|
35
|
+
]
|
|
36
|
+
}),
|
|
37
|
+
replace({
|
|
38
|
+
preventAssignment: true,
|
|
39
|
+
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(process.env.GOOGLE_MAPS_API_KEY),
|
|
40
|
+
'process.env.GOOGLE_MAPS_API_URL': JSON.stringify(process.env.GOOGLE_MAPS_API_URL),
|
|
41
|
+
'process.env.HC_API_BASE_URL': JSON.stringify(process.env.HC_API_BASE_URL)
|
|
42
|
+
}),
|
|
43
|
+
alias({
|
|
44
|
+
entries: [{ find: '~', replacement: path.resolve(projectRootDir, 'src') }]
|
|
45
|
+
}),
|
|
46
|
+
babel({
|
|
47
|
+
babelHelpers: 'bundled',
|
|
48
|
+
exclude: 'node_modules/**',
|
|
49
|
+
presets: ['@babel/preset-env', '@babel/preset-react']
|
|
50
|
+
}),
|
|
51
|
+
commonjs()
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const externalDependencies = [
|
|
55
|
+
'react', 'react-dom', 'react-router-dom', 'form-data',
|
|
56
|
+
'react/jsx-runtime', 'tailwind-merge'
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
export default [
|
|
60
|
+
{
|
|
61
|
+
input: path.resolve(__dirname, 'src/index.js'),
|
|
62
|
+
output: {
|
|
63
|
+
dir: path.resolve(__dirname, 'dist'),
|
|
64
|
+
format: 'es',
|
|
65
|
+
exports: 'named',
|
|
66
|
+
sourcemap: true,
|
|
67
|
+
preserveModules: true,
|
|
68
|
+
preserveModulesRoot: 'src'
|
|
69
|
+
},
|
|
70
|
+
plugins,
|
|
71
|
+
external: externalDependencies,
|
|
72
|
+
treeshake: true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
input: path.resolve(__dirname, 'src/services/listingService.js'),
|
|
76
|
+
output: {
|
|
77
|
+
dir: path.resolve(__dirname, 'dist/services'),
|
|
78
|
+
format: 'es',
|
|
79
|
+
exports: 'named',
|
|
80
|
+
sourcemap: true,
|
|
81
|
+
preserveModules: true,
|
|
82
|
+
preserveModulesRoot: 'src/services'
|
|
83
|
+
},
|
|
84
|
+
plugins,
|
|
85
|
+
external: externalDependencies,
|
|
86
|
+
treeshake: true
|
|
87
|
+
}
|
|
88
|
+
];
|
package/src/apis/hcApi.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import { getClientAuthKey } from '~/clientToken.js';
|
|
2
|
-
const baseURL = process.env.HC_API_BASE_URL;
|
|
3
|
-
|
|
4
|
-
const memoryStorage = {
|
|
5
|
-
authToken: null,
|
|
6
|
-
tokenExpiration: null
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function setStorage(key, value) {
|
|
10
|
-
try {
|
|
11
|
-
sessionStorage.setItem(key, value);
|
|
12
|
-
} catch (error) {
|
|
13
|
-
memoryStorage[key] = value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getStorage(key) {
|
|
18
|
-
try {
|
|
19
|
-
return sessionStorage.getItem(key) || memoryStorage[key];
|
|
20
|
-
} catch (error) {
|
|
21
|
-
return memoryStorage[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const login = async () => {
|
|
26
|
-
const clientAuthKey = getClientAuthKey();
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const response = await fetch(`${baseURL}/auth/login`, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json'
|
|
33
|
-
},
|
|
34
|
-
body: JSON.stringify({
|
|
35
|
-
clientAuthKey: clientAuthKey
|
|
36
|
-
})
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const data = await response.json();
|
|
40
|
-
|
|
41
|
-
if (data.token && data.expiration) {
|
|
42
|
-
setStorage('authToken', data.token);
|
|
43
|
-
setStorage('tokenExpiration', data.expiration);
|
|
44
|
-
return { token: data.token, expiration: data.expiration };
|
|
45
|
-
}
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.error('Login failed:', error);
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const fetchWithAuth = async (url, options = {}) => {
|
|
53
|
-
let token = getStorage('authToken');
|
|
54
|
-
|
|
55
|
-
const expirationDateTime = getStorage('tokenExpiration');
|
|
56
|
-
const currentTime = new Date();
|
|
57
|
-
|
|
58
|
-
if (!token || !expirationDateTime || new Date(expirationDateTime) <= currentTime) {
|
|
59
|
-
const authResponse = await login();
|
|
60
|
-
token = authResponse.token;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const headers = new Headers(options.headers || {});
|
|
64
|
-
headers.append('Authorization', `Bearer ${token}`);
|
|
65
|
-
|
|
66
|
-
const finalOptions = {
|
|
67
|
-
...options,
|
|
68
|
-
headers
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const response = await fetch(`${baseURL}${url}`, finalOptions);
|
|
72
|
-
|
|
73
|
-
if (!response.ok) throw new Error('Network response was not ok.');
|
|
74
|
-
|
|
75
|
-
return response;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export default {
|
|
79
|
-
get: async url => {
|
|
80
|
-
const response = await fetchWithAuth(url);
|
|
81
|
-
return await response.json();
|
|
82
|
-
},
|
|
83
|
-
post: async (url, data) => {
|
|
84
|
-
const response = await fetchWithAuth(url, {
|
|
85
|
-
method: 'POST',
|
|
86
|
-
headers: {
|
|
87
|
-
'Content-Type': 'application/json'
|
|
88
|
-
},
|
|
89
|
-
body: JSON.stringify(data)
|
|
90
|
-
});
|
|
91
|
-
return await response.json();
|
|
92
|
-
}
|
|
93
|
-
};
|
|
1
|
+
import { getClientAuthKey } from '~/clientToken.js';
|
|
2
|
+
const baseURL = process.env.HC_API_BASE_URL;
|
|
3
|
+
|
|
4
|
+
const memoryStorage = {
|
|
5
|
+
authToken: null,
|
|
6
|
+
tokenExpiration: null
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function setStorage(key, value) {
|
|
10
|
+
try {
|
|
11
|
+
sessionStorage.setItem(key, value);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
memoryStorage[key] = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getStorage(key) {
|
|
18
|
+
try {
|
|
19
|
+
return sessionStorage.getItem(key) || memoryStorage[key];
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return memoryStorage[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const login = async () => {
|
|
26
|
+
const clientAuthKey = getClientAuthKey();
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(`${baseURL}/auth/login`, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json'
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
clientAuthKey: clientAuthKey
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const data = await response.json();
|
|
40
|
+
|
|
41
|
+
if (data.token && data.expiration) {
|
|
42
|
+
setStorage('authToken', data.token);
|
|
43
|
+
setStorage('tokenExpiration', data.expiration);
|
|
44
|
+
return { token: data.token, expiration: data.expiration };
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('Login failed:', error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const fetchWithAuth = async (url, options = {}) => {
|
|
53
|
+
let token = getStorage('authToken');
|
|
54
|
+
|
|
55
|
+
const expirationDateTime = getStorage('tokenExpiration');
|
|
56
|
+
const currentTime = new Date();
|
|
57
|
+
|
|
58
|
+
if (!token || !expirationDateTime || new Date(expirationDateTime) <= currentTime) {
|
|
59
|
+
const authResponse = await login();
|
|
60
|
+
token = authResponse.token;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const headers = new Headers(options.headers || {});
|
|
64
|
+
headers.append('Authorization', `Bearer ${token}`);
|
|
65
|
+
|
|
66
|
+
const finalOptions = {
|
|
67
|
+
...options,
|
|
68
|
+
headers
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const response = await fetch(`${baseURL}${url}`, finalOptions);
|
|
72
|
+
|
|
73
|
+
if (!response.ok) throw new Error('Network response was not ok.');
|
|
74
|
+
|
|
75
|
+
return response;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default {
|
|
79
|
+
get: async url => {
|
|
80
|
+
const response = await fetchWithAuth(url);
|
|
81
|
+
return await response.json();
|
|
82
|
+
},
|
|
83
|
+
post: async (url, data) => {
|
|
84
|
+
const response = await fetchWithAuth(url, {
|
|
85
|
+
method: 'POST',
|
|
86
|
+
headers: {
|
|
87
|
+
'Content-Type': 'application/json'
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify(data)
|
|
90
|
+
});
|
|
91
|
+
return await response.json();
|
|
92
|
+
}
|
|
93
|
+
};
|
package/src/clientToken.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
let clientAuthKey = null;
|
|
2
|
-
|
|
3
|
-
export const setClientAuthKey = key => {
|
|
4
|
-
clientAuthKey = key;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const getClientAuthKey = () => {
|
|
8
|
-
return clientAuthKey;
|
|
9
|
-
};
|
|
1
|
+
let clientAuthKey = null;
|
|
2
|
+
|
|
3
|
+
export const setClientAuthKey = key => {
|
|
4
|
+
clientAuthKey = key;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const getClientAuthKey = () => {
|
|
8
|
+
return clientAuthKey;
|
|
9
|
+
};
|