@cocreate/pwa 1.13.7 → 1.14.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # [1.14.0](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.13.7...v1.14.0) (2023-11-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * meta name typo ([3c58a5e](https://github.com/CoCreate-app/CoCreate-pwa/commit/3c58a5ead6d509fb6cf63e57c0c3bc58e21a1e1d))
7
+ * update crud methods ([1b5236c](https://github.com/CoCreate-app/CoCreate-pwa/commit/1b5236c3c91610d9420f96584fbd195eb9c90078))
8
+
9
+
10
+ ### Features
11
+
12
+ * debounce an array of files served from cache and send to client ([4daa134](https://github.com/CoCreate-app/CoCreate-pwa/commit/4daa1344a06049667c22fa6dab8aa229678d726e))
13
+
1
14
  ## [1.13.7](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.13.6...v1.13.7) (2023-11-03)
2
15
 
3
16
 
package/demo/index.html CHANGED
@@ -5,7 +5,7 @@
5
5
  <meta charset="utf-8" />
6
6
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
7
7
  <meta
8
- key="viewport"
8
+ name="viewport"
9
9
  content="width=device-width; initial-scale=1; viewport-fit=cover" />
10
10
  <!-- import the webpage's stylesheet -->
11
11
  <link
@@ -23,7 +23,7 @@
23
23
  <meta name="apple-mobile-web-app-capable" content="yes" />
24
24
  <!--<hides status bar for a full screen experience omn ios only>-->
25
25
  <meta
26
- key="apple-mobile-web-app-status-bar-style"
26
+ name="apple-mobile-web-app-status-bar-style"
27
27
  content="black-translucent" />
28
28
 
29
29
  <link rel="apple-touch-startup-image" href="ios-startup.png" />
package/docs/index.html CHANGED
@@ -11,10 +11,10 @@
11
11
  sizes="32x32"
12
12
  href="https://cocreate.app/images/favicon.ico" />
13
13
  <meta
14
- key="description"
14
+ name="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
16
  <meta
17
- key="keywords"
17
+ name="keywords"
18
18
  content="helper classes, utility classes, css framework, css library, inline style classes" />
19
19
  <meta name="robots" content="index,follow" />
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/pwa",
3
- "version": "1.13.7",
3
+ "version": "1.14.0",
4
4
  "description": "A simple pwa component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "pwa",
@@ -25,7 +25,6 @@
25
25
  const cacheName = "dynamic-v2";
26
26
  let organization_id = ""
27
27
  let storage = true
28
- let returnedFromCache = {};
29
28
 
30
29
  const queryString = self.location.search;
31
30
  const queryParams = new URLSearchParams(queryString);
@@ -42,7 +41,7 @@ self.addEventListener("activate", async (e) => {
42
41
 
43
42
  self.addEventListener("fetch", async (e) => {
44
43
  if (!(e.request.url.indexOf('http') === 0) || e.request.method === 'POST') return;
45
- // TODO: check file header for cache policies and cache accorddingly
44
+
46
45
  e.respondWith(
47
46
  caches
48
47
  .match(e.request)
@@ -51,7 +50,8 @@ self.addEventListener("fetch", async (e) => {
51
50
  const organization = cacheResponse.headers.get('organization')
52
51
  const lastModified = cacheResponse.headers.get('last-modified')
53
52
 
54
- returnedFromCache[e.request.url] = { organization, lastModified }
53
+ // returnedFromCache[e.request.url] = { organization, lastModified }
54
+ sendCacheUpdate(e.request.url, organization, lastModified);
55
55
  return cacheResponse;
56
56
  } else {
57
57
  const networkResponse = await fetch(e.request);
@@ -129,7 +129,7 @@ self.addEventListener('push', (event) => {
129
129
  // Handle WebSocket events
130
130
  socket.addEventListener('open', () => {
131
131
  // The WebSocket connection is open, send the message to the server
132
- socket.send(JSON.stringify({ method: 'read.object', array: 'files', object: { _id }, uid: '' }));
132
+ socket.send(JSON.stringify({ method: 'object.read', array: 'files', object: { _id }, uid: '' }));
133
133
  });
134
134
 
135
135
  socket.addEventListener('message', (event) => {
@@ -160,6 +160,28 @@ self.addEventListener('push', (event) => {
160
160
  );
161
161
  });
162
162
 
163
+ let returnedFromCache = {};
164
+ let fetchTimeout = null;
165
+ const sendCacheUpdate = (url, organization, lastModified) => {
166
+
167
+ returnedFromCache[url] = { organization, lastModified };
168
+
169
+ if (fetchTimeout) {
170
+ clearTimeout(fetchTimeout);
171
+ }
172
+ const self = this
173
+ fetchTimeout = setTimeout(() => {
174
+ self.clients.matchAll().then(clients => {
175
+ if (clients.length > 0) {
176
+ clients[0].postMessage({ action: 'checkCache', returnedFromCache });
177
+ }
178
+ });
179
+
180
+ fetchTimeout = null;
181
+ returnedFromCache = {};
182
+ }, 500);
183
+ };
184
+
163
185
  // self.addEventListener('backgroundfetchsuccess', (event) => {
164
186
  // const bgFetch = event.registration;
165
187