@cocreate/pwa 1.9.2 → 1.10.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 +12 -0
- package/CoCreate.config.js +25 -25
- package/package.json +1 -1
- package/src/cache.js +42 -21
- package/src/service-worker.js +6 -89
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [1.10.0](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.9.2...v1.10.0) (2023-09-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* object.$filter ([1e73390](https://github.com/CoCreate-app/CoCreate-pwa/commit/1e73390bc97f840c54fb2043624bbeda622b63d9))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* cache updates dynaically using crud and sockert listener ([17e1646](https://github.com/CoCreate-app/CoCreate-pwa/commit/17e1646949ec49efc487e8e3cbcd565e5aa0c6b9))
|
|
12
|
+
|
|
1
13
|
## [1.9.2](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.9.1...v1.9.2) (2023-09-07)
|
|
2
14
|
|
|
3
15
|
|
package/CoCreate.config.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
"organization_id": "",
|
|
3
|
-
"key": "",
|
|
4
|
-
"host": "",
|
|
5
|
-
"sources": [
|
|
6
|
-
{
|
|
7
|
-
"array": "files",
|
|
8
|
-
"object": {
|
|
9
|
-
"_id": "637ca5ac50234ef1671ce327",
|
|
10
|
-
"name": "index.html",
|
|
11
|
-
"path": "/docs/pwa/index.html",
|
|
12
|
-
"src": "{{./docs/index.html}}",
|
|
13
|
-
"host": [
|
|
14
|
-
"cocreate.app",
|
|
15
|
-
"general.cocreate.app"
|
|
16
|
-
],
|
|
17
|
-
"directory": "/docs/pwa",
|
|
18
|
-
"parentDirectory": "{{parentDirectory}}",
|
|
19
|
-
"content-type": "{{content-type}}",
|
|
20
|
-
"public": "true",
|
|
21
|
-
"website_id": "614298c2829b690010a5c031"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
"organization_id": "",
|
|
3
|
+
"key": "",
|
|
4
|
+
"host": "",
|
|
5
|
+
"sources": [
|
|
6
|
+
{
|
|
7
|
+
"array": "files",
|
|
8
|
+
"object": {
|
|
9
|
+
"_id": "637ca5ac50234ef1671ce327",
|
|
10
|
+
"name": "index.html",
|
|
11
|
+
"path": "/docs/pwa/index.html",
|
|
12
|
+
"src": "{{./docs/index.html}}",
|
|
13
|
+
"host": [
|
|
14
|
+
"cocreate.app",
|
|
15
|
+
"general.cocreate.app"
|
|
16
|
+
],
|
|
17
|
+
"directory": "/docs/pwa",
|
|
18
|
+
"parentDirectory": "{{parentDirectory}}",
|
|
19
|
+
"content-type": "{{content-type}}",
|
|
20
|
+
"public": "true",
|
|
21
|
+
"website_id": "614298c2829b690010a5c031"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
};
|
package/package.json
CHANGED
package/src/cache.js
CHANGED
|
@@ -1,28 +1,37 @@
|
|
|
1
|
+
import socket from "@cocreate/socket-client"
|
|
2
|
+
|
|
3
|
+
// const cacheName = "dynamic-v2"
|
|
4
|
+
|
|
1
5
|
const cacheBtn = document.getElementById('cacheBtn');
|
|
2
6
|
|
|
3
|
-
function
|
|
7
|
+
function putFile(cacheName, data) {
|
|
8
|
+
if (!data.name || !data.path || !data.src || !data['content-type'])
|
|
9
|
+
return
|
|
10
|
+
// Open the cache and update it with the new file data
|
|
11
|
+
caches.open(cacheName).then((cache) => {
|
|
12
|
+
// Construct the URL for the file based on the fileObject's path and src
|
|
13
|
+
const fileUrl = new URL(data.name, window.location.origin + data.path).toString();
|
|
14
|
+
|
|
15
|
+
// Create a Response object with the file data
|
|
16
|
+
const fileResponse = new Response(data.src, {
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': data['content-type'],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Update the cache with the new version (or add it if not in the cache)
|
|
23
|
+
cache.put(fileUrl, fileResponse).then(() => {
|
|
24
|
+
console.log(`Updated cache for ${fileUrl}`);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function deleteCache(cacheName) {
|
|
4
30
|
if ('serviceWorker' in navigator) {
|
|
5
|
-
return caches.delete(
|
|
6
|
-
|
|
7
|
-
// caches.keys().then(function(cacheNames) {
|
|
8
|
-
// cacheNames.forEach(function(cacheName) {
|
|
9
|
-
// if (cacheName == cache)
|
|
10
|
-
// caches.delete(cacheName);
|
|
11
|
-
// });
|
|
12
|
-
// });
|
|
31
|
+
return caches.delete(cacheName);
|
|
13
32
|
}
|
|
14
33
|
}
|
|
15
34
|
|
|
16
|
-
// function cleanCache(cacheName, numeroItems) {
|
|
17
|
-
// caches.open(cacheName).then((cache) => {
|
|
18
|
-
// return cache.keys().then((keys) => {
|
|
19
|
-
// if (keys.length > numeroItems) {
|
|
20
|
-
// cache.delete(keys[0]).then(cleanCache(cacheName, numeroItems));
|
|
21
|
-
// }
|
|
22
|
-
// });
|
|
23
|
-
// });
|
|
24
|
-
// }
|
|
25
|
-
|
|
26
35
|
function deleteFile(cacheName, fileName) {
|
|
27
36
|
if ('serviceWorker' in navigator) {
|
|
28
37
|
caches.open(cacheName).then(function (cache) {
|
|
@@ -34,11 +43,23 @@ function deleteFile(cacheName, fileName) {
|
|
|
34
43
|
}
|
|
35
44
|
}
|
|
36
45
|
|
|
37
|
-
|
|
38
46
|
if (cacheBtn) {
|
|
39
47
|
cacheBtn.addEventListener('click', function () {
|
|
40
48
|
deleteFile('dynamic-v2', '/CoCreate-components/CoCreate-pwa/src/index.js');
|
|
41
49
|
});
|
|
42
50
|
}
|
|
43
51
|
|
|
44
|
-
|
|
52
|
+
function fileChange(data) {
|
|
53
|
+
if (!data.array === 'files' || !data.object)
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
for (let i = 0; i < data.object.length; i++)
|
|
57
|
+
putFile('test', data.object[i])
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
socket.listen('create.object', (data) => fileChange(data));
|
|
61
|
+
socket.listen('read.object', (data) => fileChange(data));
|
|
62
|
+
socket.listen('update.object', (data) => fileChange(data));
|
|
63
|
+
socket.listen('delete.object', (data) => fileChange(data));
|
|
64
|
+
|
|
65
|
+
export { putFile, deleteFile, deleteCache }
|
package/src/service-worker.js
CHANGED
|
@@ -15,10 +15,12 @@
|
|
|
15
15
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
********************************************************************************/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Commercial Licensing Information:
|
|
20
|
+
* For commercial use of this software without the copyleft provisions of the AGPLv3,
|
|
21
|
+
* you must obtain a commercial license from CoCreate LLC.
|
|
22
|
+
* For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
|
|
23
|
+
*/
|
|
22
24
|
|
|
23
25
|
const cacheName = "dynamic-v2";
|
|
24
26
|
let organization_id = ""
|
|
@@ -40,41 +42,6 @@ self.addEventListener("activate", async (e) => {
|
|
|
40
42
|
self.addEventListener("fetch", async (e) => {
|
|
41
43
|
if (!(e.request.url.indexOf('http') === 0) || e.request.method === 'POST') return;
|
|
42
44
|
|
|
43
|
-
if (!storage) {
|
|
44
|
-
console.log('storage:', storage);
|
|
45
|
-
|
|
46
|
-
const url = new URL(e.request.url);
|
|
47
|
-
const hostname = url.host;
|
|
48
|
-
const pathname = url.pathname;
|
|
49
|
-
|
|
50
|
-
let file = await readFile({
|
|
51
|
-
database: '5ff747727005da1c272740ab',
|
|
52
|
-
array: 'files',
|
|
53
|
-
filter: {
|
|
54
|
-
path: hostname,
|
|
55
|
-
host: '*'
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
if (file) {
|
|
60
|
-
console.log('file:', file);
|
|
61
|
-
console.log('Pathname:', pathname);
|
|
62
|
-
console.log('file', file)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (file && file.object && file.object[0]) {
|
|
66
|
-
file = file.object[0]
|
|
67
|
-
|
|
68
|
-
const modifiedRequest = new Request(e.request, {
|
|
69
|
-
headers: new Headers({
|
|
70
|
-
'File-Content': file.src,
|
|
71
|
-
'Content-Type': file['content-type']
|
|
72
|
-
})
|
|
73
|
-
});
|
|
74
|
-
e.request = modifiedRequest
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
45
|
e.respondWith(
|
|
79
46
|
caches
|
|
80
47
|
.match(e.request)
|
|
@@ -132,56 +99,6 @@ self.addEventListener("fetch", async (e) => {
|
|
|
132
99
|
);
|
|
133
100
|
});
|
|
134
101
|
|
|
135
|
-
|
|
136
|
-
function readFile(data) {
|
|
137
|
-
return new Promise((resolve) => {
|
|
138
|
-
const request = indexedDB.open(data.database);
|
|
139
|
-
|
|
140
|
-
request.onsuccess = function () {
|
|
141
|
-
const db = request.result
|
|
142
|
-
console.log('readFile', data)
|
|
143
|
-
try {
|
|
144
|
-
const transaction = db.transaction(data.array, "readonly");
|
|
145
|
-
const objectStore = transaction.objectStore(data.array);
|
|
146
|
-
const cursorRequest = objectStore.openCursor();
|
|
147
|
-
|
|
148
|
-
cursorRequest.onsuccess = function () {
|
|
149
|
-
const cursor = cursorRequest.result;
|
|
150
|
-
if (cursor) {
|
|
151
|
-
const file = cursor.value;
|
|
152
|
-
if (!file || !file.src || !file.path || !file.host)
|
|
153
|
-
cursor.continue();
|
|
154
|
-
else if (file.path !== data.filter.path || !file.host.includes(data.filter.host))
|
|
155
|
-
cursor.continue();
|
|
156
|
-
else {
|
|
157
|
-
db.close()
|
|
158
|
-
return resolve(file);
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
// Resolve the Promise when cursor is finished
|
|
162
|
-
db.close()
|
|
163
|
-
resolve();
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
cursorRequest.onerror = function () {
|
|
168
|
-
console.error("Cursor error:", cursorRequest.error);
|
|
169
|
-
db.close()
|
|
170
|
-
resolve();
|
|
171
|
-
};
|
|
172
|
-
} catch (error) {
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
request.onerror = function (event) {
|
|
179
|
-
reject(event.target.error);
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
102
|
self.addEventListener('message', function (event) {
|
|
186
103
|
if (event.data === 'getOrganization')
|
|
187
104
|
event.source.postMessage(organization_id);
|