@feardread/feature-factory 3.0.1 → 3.0.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.
- package/dist/bundle.min.js +2 -2
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/factory/api.js +3 -3
- package/src/factory/cache.js +4 -18
- package/src/factory/thunk.js +2 -2
- package/src/index.js +3 -1
package/package.json
CHANGED
package/src/factory/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import qs from "qs";
|
|
3
|
-
import
|
|
3
|
+
import CacheFactory from "./cache";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const API_BASE_URL = (process.env.NODE_ENV === "production")
|
|
@@ -26,7 +26,7 @@ const instance = axios.create({
|
|
|
26
26
|
|
|
27
27
|
instance.interceptors.request.use(
|
|
28
28
|
(config) => {
|
|
29
|
-
const isAuth =
|
|
29
|
+
const isAuth = CacheFactory.local.get("auth") ? CacheFactory.local.get("auth") : null;
|
|
30
30
|
let token = isAuth !== null ? isAuth.token : "";
|
|
31
31
|
|
|
32
32
|
config.headers = {
|
|
@@ -55,7 +55,7 @@ instance.interceptors.response.use(
|
|
|
55
55
|
console.log("API ERROR :: ", error);
|
|
56
56
|
if (error.response) {
|
|
57
57
|
if (error.response.status === 401) {
|
|
58
|
-
|
|
58
|
+
CacheFactory.local.remove("auth");
|
|
59
59
|
return Promise.reject(error.response);
|
|
60
60
|
}
|
|
61
61
|
if (error.response.status === 500) {
|
package/src/factory/cache.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
3
|
// cache
|
|
4
|
-
export const
|
|
4
|
+
export const CacheFactory = (options = {}) => {
|
|
5
5
|
var engine = options.type == 'local' ? 'localStorage' : 'sessionStorage';
|
|
6
6
|
|
|
7
7
|
return {
|
|
@@ -48,24 +48,10 @@ export const cache = (options = {}) => {
|
|
|
48
48
|
has: (key) => {
|
|
49
49
|
return window[engine].getItem(key) !== null;
|
|
50
50
|
},
|
|
51
|
-
/*
|
|
52
|
-
_extend: () => {
|
|
53
|
-
const destination = typeof arguments[0] === 'object' ? arguments[0] : {};
|
|
54
|
-
|
|
55
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
56
|
-
if (arguments[i] && typeof arguments[i] === 'object') {
|
|
57
|
-
for (var property in arguments[i])
|
|
58
|
-
destination[property] = arguments[i][property];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return destination;
|
|
63
|
-
}
|
|
64
|
-
*/
|
|
65
51
|
};
|
|
66
52
|
}
|
|
67
53
|
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
CacheFactory.local = CacheFactory({ type: 'local' });
|
|
55
|
+
CacheFactory.session = CacheFactory({ type: 'session' });
|
|
70
56
|
|
|
71
|
-
export default
|
|
57
|
+
export default CacheFactory;
|
package/src/factory/thunk.js
CHANGED
|
@@ -14,7 +14,7 @@ export const ThunkFactory = {
|
|
|
14
14
|
|
|
15
15
|
async ( params, thunkApi ) => {
|
|
16
16
|
let url = `${entity}/${prefix}`;
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
if ( prefix == 'one' ) url = `${entity}/${params.id}`
|
|
19
19
|
|
|
20
20
|
return API.get(url, (prefix == 'search') ? {params} : {})
|
|
@@ -34,7 +34,7 @@ export const ThunkFactory = {
|
|
|
34
34
|
`${entity}/${prefix}`,
|
|
35
35
|
|
|
36
36
|
async ( data, thunkApi ) => {
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
return API.post(`${entity}/${prefix}`, data)
|
|
39
39
|
|
|
40
40
|
.then((response) => {
|
package/src/index.js
CHANGED
|
@@ -4,4 +4,6 @@ export { default as ThunkFactory } from "./factory/thunk.js";
|
|
|
4
4
|
|
|
5
5
|
export { default as ApiFactory } from "./factory/service.js";
|
|
6
6
|
|
|
7
|
-
export { default as StateFactory } from "./factory/state.js";
|
|
7
|
+
export { default as StateFactory } from "./factory/state.js";
|
|
8
|
+
|
|
9
|
+
export { default as CacheFactory } from "./factory/cache.js";
|