@docbrasil/api-systemmanager 1.1.52 → 1.1.54
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/api/dispatch.js +12 -21
- package/dist/bundle.cjs +12 -21
- package/dist/bundle.mjs +1 -1
- package/package.json +1 -1
package/api/dispatch.js
CHANGED
|
@@ -14,7 +14,10 @@ class Dispatch {
|
|
|
14
14
|
self._cache = options.parent.options.cache;
|
|
15
15
|
self._forceCache = options.parent.options.forceCache;
|
|
16
16
|
self.parent = options.parent;
|
|
17
|
-
self._client = Axios.create({
|
|
17
|
+
self._client = Axios.create({
|
|
18
|
+
baseURL: self.parent.options.uri,
|
|
19
|
+
withCredentials: true
|
|
20
|
+
});
|
|
18
21
|
|
|
19
22
|
// Add request interceptor for offline handling
|
|
20
23
|
self._client.interceptors.request.use(
|
|
@@ -31,20 +34,14 @@ class Dispatch {
|
|
|
31
34
|
});
|
|
32
35
|
|
|
33
36
|
if (cachedData) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
return {
|
|
38
|
+
url: config.url,
|
|
39
|
+
method: config.method,
|
|
37
40
|
data: cachedData,
|
|
38
|
-
|
|
39
|
-
config,
|
|
41
|
+
params: config.params,
|
|
42
|
+
headers: config.headers,
|
|
40
43
|
cached: true
|
|
41
44
|
};
|
|
42
|
-
|
|
43
|
-
// Throwing a special error that includes our cached response
|
|
44
|
-
throw {
|
|
45
|
-
__CACHE_HIT__: true,
|
|
46
|
-
response: dummyResponse
|
|
47
|
-
};
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
self.errorOffline();
|
|
@@ -53,11 +50,10 @@ class Dispatch {
|
|
|
53
50
|
error => Promise.reject(error)
|
|
54
51
|
);
|
|
55
52
|
|
|
56
|
-
// Add response interceptor to handle
|
|
53
|
+
// Add response interceptor to handle caching
|
|
57
54
|
self._client.interceptors.response.use(
|
|
58
55
|
async response => {
|
|
59
|
-
|
|
60
|
-
if (response.status === 200 && self._isOnline() && self._cache) {
|
|
56
|
+
if (response.status === 200 && self._isOnline() && self._cache && !response.cached) {
|
|
61
57
|
await self._setCache(response.config.url, {
|
|
62
58
|
method: response.config.method,
|
|
63
59
|
data: response.config.data,
|
|
@@ -67,12 +63,7 @@ class Dispatch {
|
|
|
67
63
|
}
|
|
68
64
|
return response;
|
|
69
65
|
},
|
|
70
|
-
error =>
|
|
71
|
-
if (error.__CACHE_HIT__) {
|
|
72
|
-
return error.response;
|
|
73
|
-
}
|
|
74
|
-
return Promise.reject(error);
|
|
75
|
-
}
|
|
66
|
+
error => Promise.reject(error)
|
|
76
67
|
);
|
|
77
68
|
}
|
|
78
69
|
|
package/dist/bundle.cjs
CHANGED
|
@@ -26,7 +26,10 @@ class Dispatch {
|
|
|
26
26
|
self._cache = options.parent.options.cache;
|
|
27
27
|
self._forceCache = options.parent.options.forceCache;
|
|
28
28
|
self.parent = options.parent;
|
|
29
|
-
self._client = Axios__default["default"].create({
|
|
29
|
+
self._client = Axios__default["default"].create({
|
|
30
|
+
baseURL: self.parent.options.uri,
|
|
31
|
+
withCredentials: true
|
|
32
|
+
});
|
|
30
33
|
|
|
31
34
|
// Add request interceptor for offline handling
|
|
32
35
|
self._client.interceptors.request.use(
|
|
@@ -43,20 +46,14 @@ class Dispatch {
|
|
|
43
46
|
});
|
|
44
47
|
|
|
45
48
|
if (cachedData) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
return {
|
|
50
|
+
url: config.url,
|
|
51
|
+
method: config.method,
|
|
49
52
|
data: cachedData,
|
|
50
|
-
|
|
51
|
-
config,
|
|
53
|
+
params: config.params,
|
|
54
|
+
headers: config.headers,
|
|
52
55
|
cached: true
|
|
53
56
|
};
|
|
54
|
-
|
|
55
|
-
// Throwing a special error that includes our cached response
|
|
56
|
-
throw {
|
|
57
|
-
__CACHE_HIT__: true,
|
|
58
|
-
response: dummyResponse
|
|
59
|
-
};
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
self.errorOffline();
|
|
@@ -65,11 +62,10 @@ class Dispatch {
|
|
|
65
62
|
error => Promise.reject(error)
|
|
66
63
|
);
|
|
67
64
|
|
|
68
|
-
// Add response interceptor to handle
|
|
65
|
+
// Add response interceptor to handle caching
|
|
69
66
|
self._client.interceptors.response.use(
|
|
70
67
|
async response => {
|
|
71
|
-
|
|
72
|
-
if (response.status === 200 && self._isOnline() && self._cache) {
|
|
68
|
+
if (response.status === 200 && self._isOnline() && self._cache && !response.cached) {
|
|
73
69
|
await self._setCache(response.config.url, {
|
|
74
70
|
method: response.config.method,
|
|
75
71
|
data: response.config.data,
|
|
@@ -79,12 +75,7 @@ class Dispatch {
|
|
|
79
75
|
}
|
|
80
76
|
return response;
|
|
81
77
|
},
|
|
82
|
-
error =>
|
|
83
|
-
if (error.__CACHE_HIT__) {
|
|
84
|
-
return error.response;
|
|
85
|
-
}
|
|
86
|
-
return Promise.reject(error);
|
|
87
|
-
}
|
|
78
|
+
error => Promise.reject(error)
|
|
88
79
|
);
|
|
89
80
|
}
|
|
90
81
|
|