@feardread/feature-factory 2.0.5 → 2.0.6
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/bundle.min.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/factory.js +22 -15
- package/src/factory/factory.js +1 -4
package/package.json
CHANGED
package/src/api/factory.js
CHANGED
|
@@ -4,27 +4,28 @@ import cache from "../cache/cache.js";
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Creates and configures an Axios instance.
|
|
9
|
+
* @param {string} baseURL - The base URL for API requests.
|
|
10
|
+
* @param {object} [headers={}] - Optional default headers for requests.
|
|
11
|
+
* @returns {object} An object containing configured Axios methods (get, post, put, delete).
|
|
12
|
+
*/
|
|
13
|
+
export const InstanceFactory = (baseURL, headers = {}) => {
|
|
14
|
+
const API_BASE_URL = (baseURL)
|
|
15
|
+
? baseURL
|
|
16
|
+
: "http://fear.master.com/fear/api/";
|
|
17
17
|
|
|
18
18
|
const instance = axios.create({
|
|
19
|
-
baseURL:
|
|
19
|
+
baseURL: API_BASE_URL,
|
|
20
20
|
headers: {
|
|
21
21
|
Accept: "application/json",
|
|
22
|
-
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
...headers,
|
|
23
24
|
},
|
|
24
25
|
paramsSerializer: (params) => {
|
|
25
26
|
return qs.stringify(params, { indices: false });
|
|
26
27
|
},
|
|
27
|
-
|
|
28
|
+
withCredentials: true
|
|
28
29
|
//httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
|
29
30
|
});
|
|
30
31
|
|
|
@@ -35,7 +36,7 @@ function InstanceFactory ( options ) {
|
|
|
35
36
|
|
|
36
37
|
config.headers = {
|
|
37
38
|
Authorization: `Bearer ${token}`,
|
|
38
|
-
[
|
|
39
|
+
['fear-x-token']: token
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
return config;
|
|
@@ -70,7 +71,13 @@ function InstanceFactory ( options ) {
|
|
|
70
71
|
}
|
|
71
72
|
);
|
|
72
73
|
|
|
73
|
-
return
|
|
74
|
+
return {
|
|
75
|
+
get: (url, config) => instance.get(url, config),
|
|
76
|
+
post: (url, data, config) => instance.post(url, data, config),
|
|
77
|
+
put: (url, data, config) => instance.put(url, data, config),
|
|
78
|
+
delete: (url, config) => instance.delete(url, config),
|
|
79
|
+
// Add other methods as needed (patch, head, etc.)
|
|
80
|
+
};
|
|
74
81
|
};
|
|
75
82
|
|
|
76
83
|
|
package/src/factory/factory.js
CHANGED
|
@@ -10,10 +10,7 @@ const StateFactory = (entity, data = null) => ({
|
|
|
10
10
|
|
|
11
11
|
const FeatureFactory = (sliceName, endpoint, options = {}) => {
|
|
12
12
|
const apiEndpoint = `${sliceName}/${endpoint}`;
|
|
13
|
-
const API = (options.
|
|
14
|
-
API_BASE_URL: 'http://localhost:4000/fear/api',
|
|
15
|
-
JWT_TOKEN: 'fear-x-token'
|
|
16
|
-
});
|
|
13
|
+
const API = (options.instance) ? options.instance : InstanceFactory('http://localhost:4000/fear/api');
|
|
17
14
|
|
|
18
15
|
const fetch = createAsyncThunk(
|
|
19
16
|
apiEndpoint,
|