@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feardread/feature-factory",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "rollup -c",
@@ -4,27 +4,28 @@ import cache from "../cache/cache.js";
4
4
 
5
5
 
6
6
 
7
-
8
- function InstanceFactory ( options ) {
9
- console.log('Instance Opts = ', options)
10
- const API_BASE_URL = (options.API_BASE_URL)
11
- ? options.API_BASE_URL
12
- : "http://fear.master.com/fear/api/";
13
-
14
- const ACCESS_TOKEN_NAME = (options.JWT_TOKEN)
15
- ? options.JWT_TOKEN
16
- : "x-token";
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: `${API_BASE_URL}`,
19
+ baseURL: API_BASE_URL,
20
20
  headers: {
21
21
  Accept: "application/json",
22
- "Content-Type": "application/json",
22
+ 'Content-Type': 'application/json',
23
+ ...headers,
23
24
  },
24
25
  paramsSerializer: (params) => {
25
26
  return qs.stringify(params, { indices: false });
26
27
  },
27
- credentials: true
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
- [ACCESS_TOKEN_NAME]: token
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 instance;
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
 
@@ -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.API) ? options.API : InstanceFactory({
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,