@webqit/webflo 0.11.61 → 0.20.2-next.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/.github/FUNDING.yml +12 -0
- package/.github/workflows/publish.yml +48 -0
- package/.gitignore +2 -0
- package/LICENSE +2 -2
- package/README.md +71 -2050
- package/package.json +28 -13
- package/site/-/_.md +139 -0
- package/site/-/docs.old.md +2010 -0
- package/site/.vitepress/cache/deps/@braintree_sanitize-url 2.js +93 -0
- package/site/.vitepress/cache/deps/@braintree_sanitize-url.js +93 -0
- package/site/.vitepress/cache/deps/@braintree_sanitize-url.js 2.map +7 -0
- package/site/.vitepress/cache/deps/@braintree_sanitize-url.js.map +7 -0
- package/site/.vitepress/cache/deps/_metadata 2.json +85 -0
- package/site/.vitepress/cache/deps/_metadata.json +85 -0
- package/site/.vitepress/cache/deps/chunk-BUSYA2B4 2.js +9 -0
- package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js +9 -0
- package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js 2.map +7 -0
- package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js.map +7 -0
- package/site/.vitepress/cache/deps/chunk-Q2AYPHVK 2.js +9719 -0
- package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js +9719 -0
- package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js 2.map +7 -0
- package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js.map +7 -0
- package/site/.vitepress/cache/deps/chunk-QAXAIFA7 2.js +12705 -0
- package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js +12705 -0
- package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js 2.map +7 -0
- package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js.map +7 -0
- package/site/.vitepress/cache/deps/cytoscape 2.js +30278 -0
- package/site/.vitepress/cache/deps/cytoscape-cose-bilkent 2.js +4710 -0
- package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js +4710 -0
- package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js 2.map +7 -0
- package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js.map +7 -0
- package/site/.vitepress/cache/deps/cytoscape.js +30278 -0
- package/site/.vitepress/cache/deps/cytoscape.js 2.map +7 -0
- package/site/.vitepress/cache/deps/cytoscape.js.map +7 -0
- package/site/.vitepress/cache/deps/dayjs 2.js +285 -0
- package/site/.vitepress/cache/deps/dayjs.js +285 -0
- package/site/.vitepress/cache/deps/dayjs.js 2.map +7 -0
- package/site/.vitepress/cache/deps/dayjs.js.map +7 -0
- package/site/.vitepress/cache/deps/debug 2.js +453 -0
- package/site/.vitepress/cache/deps/debug.js +453 -0
- package/site/.vitepress/cache/deps/debug.js 2.map +7 -0
- package/site/.vitepress/cache/deps/debug.js.map +7 -0
- package/site/.vitepress/cache/deps/package 2.json +3 -0
- package/site/.vitepress/cache/deps/package.json +3 -0
- package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api 2.js +4507 -0
- package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4507 -0
- package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_core 2.js +584 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js +584 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap 2.js +1166 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +1166 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js 2.js +1667 -0
- package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +1667 -0
- package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___minisearch 2.js +1815 -0
- package/site/.vitepress/cache/deps/vitepress___minisearch.js +1815 -0
- package/site/.vitepress/cache/deps/vitepress___minisearch.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___minisearch.js.map +7 -0
- package/site/.vitepress/cache/deps/vue 2.js +344 -0
- package/site/.vitepress/cache/deps/vue.js +344 -0
- package/site/.vitepress/cache/deps/vue.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vue.js.map +7 -0
- package/site/.vitepress/config.ts +147 -0
- package/site/.vitepress/theme/custom.css +50 -0
- package/site/.vitepress/theme/index.ts +6 -0
- package/site/api/webflo-fetch/FormData.md +0 -0
- package/site/api/webflo-fetch/Headers.md +0 -0
- package/site/api/webflo-fetch/LiveResponse.md +0 -0
- package/site/api/webflo-fetch/Request.md +0 -0
- package/site/api/webflo-fetch/Response.md +0 -0
- package/site/api/webflo-fetch/fetch.md +0 -0
- package/site/api/webflo-routing/HttpCookies.md +0 -0
- package/site/api/webflo-routing/HttpEvent/respondWith.md +1 -0
- package/site/api/webflo-routing/HttpEvent/waitUntil.md +1 -0
- package/site/api/webflo-routing/HttpEvent/waitUntilNavigate.md +1 -0
- package/site/api/webflo-routing/HttpEvent.md +30 -0
- package/site/api/webflo-routing/HttpSession.md +0 -0
- package/site/api/webflo-routing/HttpState.md +0 -0
- package/site/api/webflo-routing/HttpUser.md +0 -0
- package/site/api/webflo-routing/handler/fetch.md +42 -0
- package/site/api/webflo-routing/handler/next.md +54 -0
- package/site/api/webflo-routing/handler.md +119 -0
- package/site/api.md +26 -0
- package/site/contributing.md +16 -0
- package/site/docs/advanced/lifecycles.md +20 -0
- package/site/docs/advanced/redirects.md +0 -0
- package/site/docs/advanced/routing.md +1 -0
- package/site/docs/advanced.md +9 -0
- package/site/docs/concepts/realtime.md +637 -0
- package/site/docs/concepts/rendering.md +60 -0
- package/site/docs/concepts/request-response.md +47 -0
- package/site/docs/concepts/routing.md +656 -0
- package/site/docs/concepts/state.md +44 -0
- package/site/docs/concepts/templates.md +48 -0
- package/site/docs/concepts.md +97 -0
- package/site/docs/getting-started.md +378 -0
- package/site/docs/tech-stack.md +56 -0
- package/site/docs.md +100 -0
- package/site/examples/pwa.md +10 -0
- package/site/examples/web.md +11 -0
- package/site/examples.md +10 -0
- package/site/faq.md +13 -0
- package/site/guides/guide-auth.md +13 -0
- package/site/guides/guide-file-upload.md +11 -0
- package/site/guides/guide-service-worker.md +10 -0
- package/site/guides/tutorial-1-todo.md +24 -0
- package/site/guides.md +15 -0
- package/site/index.md +39 -0
- package/site/public/img/brand/logo-670x670.png +0 -0
- package/site/recipes/realtime.md +11 -0
- package/site/recipes/streaming.md +15 -0
- package/site/reference/cli.md +11 -0
- package/site/reference/config.md +13 -0
- package/site/reference/tools.md +9 -0
- package/src/Context.js +3 -11
- package/src/config-pi/deployment/Env.js +6 -19
- package/src/config-pi/deployment/Layout.js +11 -3
- package/src/config-pi/runtime/Client.js +40 -48
- package/src/config-pi/runtime/Server.js +52 -20
- package/src/config-pi/runtime/client/Worker.js +22 -20
- package/src/config-pi/static/Init.js +57 -0
- package/src/config-pi/static/index.js +2 -0
- package/src/deployment-pi/origins/index.js +1 -1
- package/src/deployment-pi/util.js +161 -0
- package/src/index.js +3 -9
- package/src/init-pi/index.js +117 -0
- package/src/init-pi/templates/pwa/app/handler.server.js +8 -0
- package/src/init-pi/templates/pwa/app/page.html +7 -0
- package/src/init-pi/templates/pwa/package.json +19 -0
- package/src/init-pi/templates/pwa/public/assets/app.css +16 -0
- package/src/init-pi/templates/pwa/public/index.html +39 -0
- package/src/init-pi/templates/pwa/public/manifest.json +29 -0
- package/src/init-pi/templates/web/app/handler.server.js +8 -0
- package/src/init-pi/templates/web/app/page.html +7 -0
- package/src/init-pi/templates/web/package.json +19 -0
- package/src/init-pi/templates/web/public/assets/app.css +16 -0
- package/src/init-pi/templates/web/public/index.html +39 -0
- package/src/runtime-pi/WebfloRuntime.js +350 -0
- package/src/runtime-pi/index.js +3 -10
- package/src/runtime-pi/webflo-client/ClientSideCookies.js +17 -0
- package/src/runtime-pi/webflo-client/ClientSideWorkport.js +63 -0
- package/src/runtime-pi/webflo-client/DeviceCapabilities.js +213 -0
- package/src/runtime-pi/webflo-client/WebfloClient.js +500 -0
- package/src/runtime-pi/webflo-client/WebfloRootClient1.js +206 -0
- package/src/runtime-pi/webflo-client/WebfloRootClient2.js +113 -0
- package/src/runtime-pi/webflo-client/WebfloSubClient.js +118 -0
- package/src/runtime-pi/webflo-client/index.js +17 -0
- package/src/runtime-pi/webflo-client/webflo-codegen.js +469 -0
- package/src/runtime-pi/webflo-client/webflo-devmode.js +243 -0
- package/src/runtime-pi/webflo-client/webflo-embedded.js +50 -0
- package/src/runtime-pi/webflo-fetch/LiveResponse.js +437 -0
- package/src/runtime-pi/webflo-fetch/cookies.js +10 -0
- package/src/runtime-pi/webflo-fetch/fetch.js +16 -0
- package/src/runtime-pi/webflo-fetch/formdata.js +54 -0
- package/src/runtime-pi/webflo-fetch/headers.js +151 -0
- package/src/runtime-pi/webflo-fetch/index.js +5 -0
- package/src/runtime-pi/webflo-fetch/message.js +49 -0
- package/src/runtime-pi/webflo-fetch/request.js +62 -0
- package/src/runtime-pi/webflo-fetch/response.js +110 -0
- package/src/runtime-pi/webflo-fetch/util.js +28 -0
- package/src/runtime-pi/webflo-messaging/WQBroadcastChannel.js +10 -0
- package/src/runtime-pi/webflo-messaging/WQMessageChannel.js +26 -0
- package/src/runtime-pi/webflo-messaging/WQMessageEvent.js +87 -0
- package/src/runtime-pi/webflo-messaging/WQMessagePort.js +38 -0
- package/src/runtime-pi/webflo-messaging/WQRelayPort.js +47 -0
- package/src/runtime-pi/webflo-messaging/WQSockPort.js +113 -0
- package/src/runtime-pi/webflo-messaging/WQStarPort.js +104 -0
- package/src/runtime-pi/webflo-messaging/wq-message-port.js +404 -0
- package/src/runtime-pi/webflo-routing/HttpCookies.js +42 -0
- package/src/runtime-pi/webflo-routing/HttpEvent.js +112 -0
- package/src/runtime-pi/webflo-routing/HttpSession.js +11 -0
- package/src/runtime-pi/webflo-routing/HttpState.js +153 -0
- package/src/runtime-pi/webflo-routing/HttpUser.js +54 -0
- package/src/runtime-pi/webflo-routing/WebfloRouter.js +245 -0
- package/src/runtime-pi/webflo-server/ServerSideCookies.js +19 -0
- package/src/runtime-pi/webflo-server/ServerSideSession.js +38 -0
- package/src/runtime-pi/webflo-server/WebfloServer.js +937 -0
- package/src/runtime-pi/webflo-server/index.js +11 -0
- package/src/runtime-pi/webflo-server/messaging/Client.js +27 -0
- package/src/runtime-pi/webflo-server/messaging/ClientRequestRealtime.js +50 -0
- package/src/runtime-pi/webflo-server/messaging/Clients.js +25 -0
- package/src/runtime-pi/webflo-server/webflo-devmode.js +326 -0
- package/src/runtime-pi/{client → webflo-url}/Url.js +27 -76
- package/src/runtime-pi/webflo-url/index.js +1 -0
- package/src/runtime-pi/webflo-url/urlpattern.js +38 -0
- package/src/runtime-pi/{util-url.js → webflo-url/util.js} +5 -43
- package/src/runtime-pi/webflo-url/xURL.js +94 -0
- package/src/runtime-pi/webflo-worker/WebfloWorker.js +234 -0
- package/src/runtime-pi/webflo-worker/WorkerSideCookies.js +19 -0
- package/src/runtime-pi/webflo-worker/WorkerSideWorkport.js +18 -0
- package/src/runtime-pi/webflo-worker/index.js +11 -0
- package/src/services-pi/index.js +2 -0
- package/src/services-pi/push/index.js +23 -0
- package/src/util.js +10 -0
- package/src/{webflo.js → webflo-cli.js} +4 -4
- package/src/runtime-pi/Application.js +0 -29
- package/src/runtime-pi/Cookies.js +0 -82
- package/src/runtime-pi/HttpEvent.js +0 -107
- package/src/runtime-pi/Router.js +0 -130
- package/src/runtime-pi/Runtime.js +0 -21
- package/src/runtime-pi/client/Application.js +0 -76
- package/src/runtime-pi/client/Context.js +0 -7
- package/src/runtime-pi/client/Router.js +0 -48
- package/src/runtime-pi/client/Runtime.js +0 -525
- package/src/runtime-pi/client/Workport.js +0 -190
- package/src/runtime-pi/client/createStorage.js +0 -58
- package/src/runtime-pi/client/generate.js +0 -481
- package/src/runtime-pi/client/index.js +0 -21
- package/src/runtime-pi/client/worker/Application.js +0 -44
- package/src/runtime-pi/client/worker/Context.js +0 -7
- package/src/runtime-pi/client/worker/Runtime.js +0 -275
- package/src/runtime-pi/client/worker/Workport.js +0 -78
- package/src/runtime-pi/client/worker/index.js +0 -21
- package/src/runtime-pi/server/Application.js +0 -101
- package/src/runtime-pi/server/Context.js +0 -16
- package/src/runtime-pi/server/Router.js +0 -159
- package/src/runtime-pi/server/Runtime.js +0 -558
- package/src/runtime-pi/server/index.js +0 -21
- package/src/runtime-pi/util-http.js +0 -86
- package/src/runtime-pi/xFormData.js +0 -24
- package/src/runtime-pi/xHeaders.js +0 -146
- package/src/runtime-pi/xRequest.js +0 -46
- package/src/runtime-pi/xRequestHeaders.js +0 -109
- package/src/runtime-pi/xResponse.js +0 -33
- package/src/runtime-pi/xResponseHeaders.js +0 -117
- package/src/runtime-pi/xURL.js +0 -105
- package/src/runtime-pi/xfetch.js +0 -23
- package/src/runtime-pi/xxHttpMessage.js +0 -102
- package/src/static-pi/index.js +0 -11
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @imports
|
|
5
|
-
*/
|
|
6
|
-
import { _isFunction, _isObject } from '@webqit/util/js/index.js';
|
|
7
|
-
import { Observer } from './Runtime.js';
|
|
8
|
-
|
|
9
|
-
export default class Workport {
|
|
10
|
-
|
|
11
|
-
constructor(file, params = {}, env = {}) {
|
|
12
|
-
this.ready = navigator.serviceWorker ? navigator.serviceWorker.ready : new Promise(() => {});
|
|
13
|
-
|
|
14
|
-
// --------
|
|
15
|
-
// Registration and lifecycle
|
|
16
|
-
// --------
|
|
17
|
-
this.registration = new Promise((resolve, reject) => {
|
|
18
|
-
if (!navigator.serviceWorker) return;
|
|
19
|
-
const register = () => {
|
|
20
|
-
navigator.serviceWorker.register(file, { scope: params.scope || '/' }).then(async registration => {
|
|
21
|
-
|
|
22
|
-
// Helper that updates instance's state
|
|
23
|
-
const state = target => {
|
|
24
|
-
// instance2.state can be any of: "installing", "installed", "activating", "activated", "redundant"
|
|
25
|
-
const equivState = target.state === 'installed' ? 'waiting' :
|
|
26
|
-
(target.state === 'activating' || target.state === 'activated' ? 'active' : target.state)
|
|
27
|
-
Observer.set(this, equivState, target);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// We're always installing at first for a new service worker.
|
|
31
|
-
// An existing service would immediately be active
|
|
32
|
-
const worker = registration.active || registration.waiting || registration.installing;
|
|
33
|
-
state(worker);
|
|
34
|
-
worker.addEventListener('statechange', e => state(e.target));
|
|
35
|
-
|
|
36
|
-
// "updatefound" event - a new worker that will control
|
|
37
|
-
// this page is installing somewhere
|
|
38
|
-
registration.addEventListener('updatefound', () => {
|
|
39
|
-
// If updatefound is fired, it means that there's
|
|
40
|
-
// a new service worker being installed.
|
|
41
|
-
state(registration.installing);
|
|
42
|
-
registration.installing.addEventListener('statechange', e => state(e.target));
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
resolve(registration);
|
|
46
|
-
}).catch(e => reject(e));
|
|
47
|
-
};
|
|
48
|
-
if (params.onWindowLoad) {
|
|
49
|
-
window.addEventListener('load', register);
|
|
50
|
-
} else {
|
|
51
|
-
register();
|
|
52
|
-
}
|
|
53
|
-
if (params.startMessages) {
|
|
54
|
-
navigator.serviceWorker.startMessages();
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// --------
|
|
59
|
-
// Post messaging
|
|
60
|
-
// --------
|
|
61
|
-
const postSendCallback = (message, callback, onAvailability = 1) => {
|
|
62
|
-
if (this.active) {
|
|
63
|
-
if (_isFunction(message)) message = message();
|
|
64
|
-
callback(this.active, message);
|
|
65
|
-
} else if (onAvailability) {
|
|
66
|
-
// Availability Handling
|
|
67
|
-
const availabilityHandler = Observer.observe(this, 'active', entry => {
|
|
68
|
-
if (_isFunction(message)) message = message();
|
|
69
|
-
callback(entry.value, message);
|
|
70
|
-
if (onAvailability !== 2) { availabilityHandler.abort(); }
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
this.messaging = {
|
|
75
|
-
post: (message, onAvailability = 1) => {
|
|
76
|
-
postSendCallback(message, (active, message) => {
|
|
77
|
-
active.postMessage(message);
|
|
78
|
-
}, onAvailability);
|
|
79
|
-
return this;
|
|
80
|
-
},
|
|
81
|
-
listen: callback => {
|
|
82
|
-
if (navigator.serviceWorker) {
|
|
83
|
-
navigator.serviceWorker.addEventListener('message', evt => {
|
|
84
|
-
const response = callback(evt);
|
|
85
|
-
let responsePort = evt.ports[0];
|
|
86
|
-
if (responsePort) {
|
|
87
|
-
if (response instanceof Promise) {
|
|
88
|
-
response.then(data => {
|
|
89
|
-
responsePort.postMessage(data);
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
responsePort.postMessage(response);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return this;
|
|
98
|
-
},
|
|
99
|
-
request: (message, onAvailability = 1) => {
|
|
100
|
-
return new Promise(res => {
|
|
101
|
-
postSendCallback(message, (active, message) => {
|
|
102
|
-
let messageChannel = new MessageChannel();
|
|
103
|
-
active.postMessage(message, [ messageChannel.port2 ]);
|
|
104
|
-
messageChannel.port1.onmessage = e => res(e.data);
|
|
105
|
-
}, onAvailability);
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
|
-
channel(channelId) {
|
|
109
|
-
if (!this.channels.has(channelId)) { this.channels.set(channelId, new BroadcastChannel(channel)); }
|
|
110
|
-
let channel = this.channels.get(channelId);
|
|
111
|
-
return {
|
|
112
|
-
broadcast: message => channel.postMessage(message),
|
|
113
|
-
listen: callback => channel.addEventListener('message', callback),
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
channels: new Map,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// --------
|
|
120
|
-
// Notifications
|
|
121
|
-
// --------
|
|
122
|
-
this.notifications = {
|
|
123
|
-
requestPermission: () => {
|
|
124
|
-
return new Promise(async (resolve, reject) => {
|
|
125
|
-
const permissionResult = Notification.requestPermission(resolve);
|
|
126
|
-
if (permissionResult) { permissionResult.then(resolve, reject); }
|
|
127
|
-
});
|
|
128
|
-
},
|
|
129
|
-
fire: async (title, params = {}) => {
|
|
130
|
-
await this.ready;
|
|
131
|
-
return (await this.registration).showNotification(title, params);
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// --------
|
|
136
|
-
// Push notifications
|
|
137
|
-
// --------
|
|
138
|
-
this.push = {
|
|
139
|
-
getSubscription: async (autoPrompt = true) => {
|
|
140
|
-
await this.ready;
|
|
141
|
-
let subscription = await (await this.registration).pushManager.getSubscription();
|
|
142
|
-
let VAPID_PUBLIC_KEY, PUSH_REGISTRATION_PUBLIC_URL;
|
|
143
|
-
if (!subscription && autoPrompt && (VAPID_PUBLIC_KEY = env[params.vapid_key_env])) {
|
|
144
|
-
subscription = await (await this.registration).pushManager.subscribe({
|
|
145
|
-
userVisibleOnly: true,
|
|
146
|
-
applicationServerKey: urlBase64ToUint8Array(VAPID_PUBLIC_KEY),
|
|
147
|
-
});
|
|
148
|
-
if (PUSH_REGISTRATION_PUBLIC_URL = env[params.push_registration_url_env]) {
|
|
149
|
-
await fetch(PUSH_REGISTRATION_PUBLIC_URL, {
|
|
150
|
-
method: 'POST',
|
|
151
|
-
headers: { 'Content-Type': 'application/json', },
|
|
152
|
-
body: JSON.stringify(subscription),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return subscription;
|
|
157
|
-
},
|
|
158
|
-
unsubscribe: async () => {
|
|
159
|
-
await this.ready;
|
|
160
|
-
const subscription = await (await this.registration).pushManager.getSubscription();
|
|
161
|
-
subscription?.unsubscribe();
|
|
162
|
-
let PUSH_REGISTRATION_PUBLIC_URL;
|
|
163
|
-
if (subscription && (PUSH_REGISTRATION_PUBLIC_URL = env[params.push_registration_url_env])) {
|
|
164
|
-
await fetch(PUSH_REGISTRATION_PUBLIC_URL, {
|
|
165
|
-
method: 'DELETE',
|
|
166
|
-
headers: { 'Content-Type': 'application/json', },
|
|
167
|
-
body: JSON.stringify(subscription),
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Public base64 to Uint
|
|
177
|
-
function urlBase64ToUint8Array(base64String) {
|
|
178
|
-
var padding = '='.repeat((4 - base64String.length % 4) % 4);
|
|
179
|
-
var base64 = (base64String + padding)
|
|
180
|
-
.replace(/\-/g, '+')
|
|
181
|
-
.replace(/_/g, '/');
|
|
182
|
-
|
|
183
|
-
var rawData = window.atob(base64);
|
|
184
|
-
var outputArray = new Uint8Array(rawData.length);
|
|
185
|
-
|
|
186
|
-
for (var i = 0; i < rawData.length; ++i) {
|
|
187
|
-
outputArray[i] = rawData.charCodeAt(i);
|
|
188
|
-
}
|
|
189
|
-
return outputArray;
|
|
190
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @imports
|
|
5
|
-
*/
|
|
6
|
-
import { _isString, _isUndefined } from '@webqit/util/js/index.js';
|
|
7
|
-
import { Observer } from './Runtime.js';
|
|
8
|
-
|
|
9
|
-
export default function(namespace = null, persistent = false) {
|
|
10
|
-
const storeType = persistent ? 'localStorage' : 'sessionStorage';
|
|
11
|
-
if (!window[storeType]) {
|
|
12
|
-
throw new Error(`The specified Web Storage API ${storeType} is invalid or not supported`);
|
|
13
|
-
}
|
|
14
|
-
const _storage = {}, key = e => namespace ? `${namespace}.${e.key}` : e.key;
|
|
15
|
-
Observer.intercept(_storage, {
|
|
16
|
-
get: (event, received, next) => {
|
|
17
|
-
if (!_isString(event.key)) return;
|
|
18
|
-
const value = window[storeType].getItem(key(event));
|
|
19
|
-
return next(!_isUndefined(value) ? JSON.parse(value) : value);
|
|
20
|
-
},
|
|
21
|
-
set: (event, received, next) => {
|
|
22
|
-
if (!_isString(event.key)) return;
|
|
23
|
-
window[storeType].setItem(key(event), !_isUndefined(event.value) ? JSON.stringify(event.value) : event.value);
|
|
24
|
-
return next(true);
|
|
25
|
-
},
|
|
26
|
-
deleteProperty: (event, received, next) => {
|
|
27
|
-
if (!_isString(event.key)) return;
|
|
28
|
-
window[storeType].removeItem(key(event));
|
|
29
|
-
return next(true);
|
|
30
|
-
},
|
|
31
|
-
has: (event, received, next) => {
|
|
32
|
-
if (!_isString(event.key)) return;
|
|
33
|
-
const _key = key(event);
|
|
34
|
-
for(let i = 0; i < window[storeType].length; i ++){
|
|
35
|
-
if (window[storeType].key(i) === _key) {
|
|
36
|
-
return next(true);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
return next(false);
|
|
40
|
-
},
|
|
41
|
-
ownKeys: (event, received, next) => {
|
|
42
|
-
const keys = [];
|
|
43
|
-
for(let i = 0; i < window[storeType].length; i ++){
|
|
44
|
-
keys.push(window[storeType].key(i));
|
|
45
|
-
};
|
|
46
|
-
return next(keys);
|
|
47
|
-
},
|
|
48
|
-
getOwnPropertyDescriptor: (event, received, next) => {
|
|
49
|
-
return next({ enumerable: true, configurable: true });
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return Observer.proxy(_storage);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export {
|
|
57
|
-
Observer,
|
|
58
|
-
}
|