orderiom-api-package 0.4.77 → 0.4.79

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": "orderiom-api-package",
3
- "version": "0.4.77",
3
+ "version": "0.4.79",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/common.js CHANGED
@@ -179,8 +179,7 @@ axios.interceptors.response.use(
179
179
  error.response &&
180
180
  error.response.data &&
181
181
  error.response.data.message &&
182
- error.response.data.message.body === "unauthenticated" &&
183
- localStorage.getItem("privateToken")
182
+ error.response.data.message.body === "unauthenticated"
184
183
  ) {
185
184
  localStorage.clear();
186
185
  window.location.reload();
@@ -101,6 +101,39 @@ const actions = {
101
101
  commonErrorCallback()
102
102
  );
103
103
  },
104
+ // Delete older caches of index.html file manually because workbox can't do it properly
105
+ async deleteOlderIndexCaches() {
106
+ // get all the cache storages for this website
107
+ return caches.keys().then(res => {
108
+ if(!res.length) return;
109
+ // get the first cache storages for this website
110
+ return caches.open(res[0]).then(cache => {
111
+ // get all the cached requests
112
+ return cache.keys().then(requests => {
113
+ // get all the cached requests that is related to index.html
114
+ const indexCaches = requests.filter(request => request.url.includes('index.html'))
115
+
116
+ // If there is only one cached request for index.html then no need to do anything
117
+ if(indexCaches.length <= 1) return;
118
+
119
+ return Promise.all(indexCaches.map(async indexCache => {
120
+ // Get the last modified time for all cache requests of index.html
121
+ return cache.match(indexCache).then(response => {
122
+ if(!response) return;
123
+ indexCache.lastModified = new Date(response.headers.get('Last-Modified')).getTime()
124
+ })
125
+ })).then(() => {
126
+ // Delete the older caches of index.html
127
+ indexCaches.sort((a, b) => b.lastModified - a.lastModified)
128
+ const olderIndexCaches = indexCaches.slice(1, indexCaches.length)
129
+ return Promise.all(olderIndexCaches.map(olderIndexCache => {
130
+ return cache.delete(olderIndexCache);
131
+ }))
132
+ })
133
+ })
134
+ })
135
+ })
136
+ },
104
137
  contact({ }, data) {
105
138
  return $http.post('api/contact', data).then((res) => {
106
139
  return {