@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feardread/feature-factory",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Library to interact with redux toolkit and reduce boilerplate / repeated code",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  import axios from "axios";
2
2
  import qs from "qs";
3
- import cache from "./cache";
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 = cache.local.get("auth") ? cache.local.get("auth") : null;
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
- cache.local.remove("auth");
58
+ CacheFactory.local.remove("auth");
59
59
  return Promise.reject(error.response);
60
60
  }
61
61
  if (error.response.status === 500) {
@@ -1,7 +1,7 @@
1
1
 
2
2
 
3
3
  // cache
4
- export const cache = (options = {}) => {
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
- cache.local = cache({ type: 'local' });
69
- cache.session = cache({ type: 'session' });
54
+ CacheFactory.local = CacheFactory({ type: 'local' });
55
+ CacheFactory.session = CacheFactory({ type: 'session' });
70
56
 
71
- export default cache;
57
+ export default CacheFactory;
@@ -14,7 +14,7 @@ export const ThunkFactory = {
14
14
 
15
15
  async ( params, thunkApi ) => {
16
16
  let url = `${entity}/${prefix}`;
17
- console.log('params = ', params);
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
- console.log('params = ', data);
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";