@webqit/webflo 0.11.21 → 0.11.24
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/.gitignore +7 -7
- package/LICENSE +20 -20
- package/README.md +2074 -2071
- package/package.json +82 -82
- package/src/Context.js +79 -79
- package/src/config-pi/deployment/Env.js +69 -69
- package/src/config-pi/deployment/Layout.js +65 -65
- package/src/config-pi/deployment/Origins.js +133 -133
- package/src/config-pi/deployment/Virtualization.js +65 -65
- package/src/config-pi/deployment/index.js +17 -17
- package/src/config-pi/index.js +15 -15
- package/src/config-pi/runtime/Client.js +101 -101
- package/src/config-pi/runtime/Server.js +128 -128
- package/src/config-pi/runtime/client/Worker.js +135 -135
- package/src/config-pi/runtime/client/index.js +11 -11
- package/src/config-pi/runtime/index.js +17 -17
- package/src/config-pi/runtime/server/Headers.js +77 -77
- package/src/config-pi/runtime/server/Redirects.js +73 -73
- package/src/config-pi/runtime/server/index.js +13 -13
- package/src/config-pi/static/Manifest.js +321 -321
- package/src/config-pi/static/Ssg.js +51 -51
- package/src/config-pi/static/index.js +13 -13
- package/src/deployment-pi/index.js +10 -10
- package/src/deployment-pi/origins/index.js +215 -215
- package/src/index.js +19 -19
- package/src/runtime-pi/Router.js +131 -131
- package/src/runtime-pi/client/Context.js +6 -6
- package/src/runtime-pi/client/Router.js +47 -47
- package/src/runtime-pi/client/Runtime.js +357 -341
- package/src/runtime-pi/client/RuntimeClient.js +98 -98
- package/src/runtime-pi/client/Storage.js +56 -56
- package/src/runtime-pi/client/Url.js +205 -205
- package/src/runtime-pi/client/Workport.js +163 -163
- package/src/runtime-pi/client/generate.js +467 -467
- package/src/runtime-pi/client/index.js +23 -23
- package/src/runtime-pi/client/oohtml/full.js +6 -6
- package/src/runtime-pi/client/oohtml/namespacing.js +6 -6
- package/src/runtime-pi/client/oohtml/scripting.js +7 -7
- package/src/runtime-pi/client/oohtml/templating.js +7 -7
- package/src/runtime-pi/client/whatwag.js +27 -27
- package/src/runtime-pi/client/worker/Context.js +6 -6
- package/src/runtime-pi/client/worker/Worker.js +291 -291
- package/src/runtime-pi/client/worker/WorkerClient.js +46 -46
- package/src/runtime-pi/client/worker/Workport.js +79 -79
- package/src/runtime-pi/client/worker/index.js +23 -23
- package/src/runtime-pi/index.js +13 -13
- package/src/runtime-pi/server/Context.js +15 -15
- package/src/runtime-pi/server/Router.js +157 -157
- package/src/runtime-pi/server/Runtime.js +547 -547
- package/src/runtime-pi/server/RuntimeClient.js +112 -112
- package/src/runtime-pi/server/index.js +23 -23
- package/src/runtime-pi/server/whatwag.js +35 -35
- package/src/runtime-pi/util.js +162 -162
- package/src/runtime-pi/xFormData.js +59 -59
- package/src/runtime-pi/xHeaders.js +87 -87
- package/src/runtime-pi/xHttpEvent.js +92 -92
- package/src/runtime-pi/xHttpMessage.js +179 -179
- package/src/runtime-pi/xRequest.js +73 -73
- package/src/runtime-pi/xRequestHeaders.js +94 -94
- package/src/runtime-pi/xResponse.js +68 -68
- package/src/runtime-pi/xResponseHeaders.js +109 -109
- package/src/runtime-pi/xURL.js +110 -110
- package/src/runtime-pi/xfetch.js +6 -6
- package/src/services-pi/certbot/http-auth-hook.js +22 -22
- package/src/services-pi/certbot/http-cleanup-hook.js +22 -22
- package/src/services-pi/certbot/index.js +79 -79
- package/src/services-pi/index.js +8 -8
- package/src/static-pi/index.js +10 -10
- package/src/webflo.js +31 -31
- package/test/index.test.js +26 -25
- package/test/site/package.json +9 -9
- package/test/site/public/bundle.html +5 -5
- package/test/site/public/bundle.html.json +3 -3
- package/test/site/public/bundle.js +2 -2
- package/test/site/public/bundle.webflo.js +15 -15
- package/test/site/public/index.html +29 -29
- package/test/site/public/index1.html +34 -34
- package/test/site/public/page-2/bundle.html +4 -4
- package/test/site/public/page-2/bundle.js +2 -2
- package/test/site/public/page-2/index.html +45 -45
- package/test/site/public/page-2/main.html +2 -2
- package/test/site/public/page-4/subpage/bundle.js +2 -2
- package/test/site/public/page-4/subpage/index.html +30 -30
- package/test/site/public/sparoots.json +4 -4
- package/test/site/public/worker.js +3 -3
- package/test/site/server/index.js +15 -15
|
@@ -1,163 +1,163 @@
|
|
|
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 = {}) {
|
|
12
|
-
this.ready = navigator.serviceWorker.ready;
|
|
13
|
-
|
|
14
|
-
// --------
|
|
15
|
-
// Registration and lifecycle
|
|
16
|
-
// --------
|
|
17
|
-
this.registration = new Promise((resolve, reject) => {
|
|
18
|
-
const register = () => {
|
|
19
|
-
navigator.serviceWorker.register(file, { scope: params.scope || '/' }).then(async registration => {
|
|
20
|
-
|
|
21
|
-
// Helper that updates instance's state
|
|
22
|
-
const state = target => {
|
|
23
|
-
// instance2.state can be any of: "installing", "installed", "activating", "activated", "redundant"
|
|
24
|
-
const equivState = target.state === 'installed' ? 'waiting' :
|
|
25
|
-
(target.state === 'activating' || target.state === 'activated' ? 'active' : target.state)
|
|
26
|
-
Observer.set(this, equivState, target);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// We're always installing at first for a new service worker.
|
|
30
|
-
// An existing service would immediately be active
|
|
31
|
-
const worker = registration.active || registration.waiting || registration.installing;
|
|
32
|
-
state(worker);
|
|
33
|
-
worker.addEventListener('statechange', e => state(e.target));
|
|
34
|
-
|
|
35
|
-
// "updatefound" event - a new worker that will control
|
|
36
|
-
// this page is installing somewhere
|
|
37
|
-
registration.addEventListener('updatefound', () => {
|
|
38
|
-
// If updatefound is fired, it means that there's
|
|
39
|
-
// a new service worker being installed.
|
|
40
|
-
state(registration.installing);
|
|
41
|
-
registration.installing.addEventListener('statechange', e => state(e.target));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
resolve(registration);
|
|
45
|
-
}).catch(e => reject(e));
|
|
46
|
-
};
|
|
47
|
-
if (params.onWondowLoad) {
|
|
48
|
-
window.addEventListener('load', register);
|
|
49
|
-
} else {
|
|
50
|
-
register();
|
|
51
|
-
}
|
|
52
|
-
if (params.startMessages) {
|
|
53
|
-
navigator.serviceWorker.startMessages();
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// --------
|
|
58
|
-
// Post messaging
|
|
59
|
-
// --------
|
|
60
|
-
const postSendCallback = (message, callback, onAvailability = 1) => {
|
|
61
|
-
if (this.active) {
|
|
62
|
-
if (_isFunction(message)) message = message();
|
|
63
|
-
callback(this.active, message);
|
|
64
|
-
} else if (onAvailability) {
|
|
65
|
-
// Availability Handling
|
|
66
|
-
const availabilityHandler = entry => {
|
|
67
|
-
if (_isFunction(message)) message = message();
|
|
68
|
-
callback(entry.value, message);
|
|
69
|
-
if (onAvailability !== 2) {
|
|
70
|
-
Observer.unobserve(this, 'active', availabilityHandler);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
Observer.observe(this, 'active', availabilityHandler);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
this.messaging = {
|
|
77
|
-
post: (message, onAvailability = 1) => {
|
|
78
|
-
postSendCallback(message, (active, message) => {
|
|
79
|
-
active.postMessage(message);
|
|
80
|
-
}, onAvailability);
|
|
81
|
-
return this.post;
|
|
82
|
-
},
|
|
83
|
-
listen: callback => {
|
|
84
|
-
navigator.serviceWorker.addEventListener('message', callback);
|
|
85
|
-
return this.post;
|
|
86
|
-
},
|
|
87
|
-
request: (message, onAvailability = 1) => {
|
|
88
|
-
return new Promise(res => {
|
|
89
|
-
postSendCallback(message, (active, message) => {
|
|
90
|
-
let messageChannel = new MessageChannel();
|
|
91
|
-
active.postMessage(message, [ messageChannel.port2 ]);
|
|
92
|
-
messageChannel.port1.onmessage = e => res(e.data);
|
|
93
|
-
}, onAvailability);
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
channel(channelId) {
|
|
97
|
-
if (!this.channels.has(channelId)) { this.channels.set(channelId, new BroadcastChannel(channel)); }
|
|
98
|
-
let channel = this.channels.get(channelId);
|
|
99
|
-
return {
|
|
100
|
-
broadcast: message => channel.postMessage(message),
|
|
101
|
-
listen: callback => channel.addEventListener('message', callback),
|
|
102
|
-
};
|
|
103
|
-
},
|
|
104
|
-
channels: new Map,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// --------
|
|
108
|
-
// Notifications
|
|
109
|
-
// --------
|
|
110
|
-
this.notifications = {
|
|
111
|
-
fire: (title, params = {}) => {
|
|
112
|
-
return new Promise((res, rej) => {
|
|
113
|
-
if (typeof Notification === 'undefined' || Notification.permission !== 'granted') {
|
|
114
|
-
return rej(typeof Notification !== 'undefined' && Notification && Notification.permission);
|
|
115
|
-
}
|
|
116
|
-
notification.addEventListener('error', rej);
|
|
117
|
-
let notification = new Notification(title, params);
|
|
118
|
-
notification.addEventListener('click', res);
|
|
119
|
-
notification.addEventListener('close', res);
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// --------
|
|
125
|
-
// Push notifications
|
|
126
|
-
// --------
|
|
127
|
-
this.push = {
|
|
128
|
-
getSubscription: async () => {
|
|
129
|
-
return (await this.registration).pushManager.getSubscription();
|
|
130
|
-
},
|
|
131
|
-
subscribe: async (publicKey, params = {}) => {
|
|
132
|
-
var subscription = await this.push.getSubscription();
|
|
133
|
-
return subscription ? subscription : (await this.registration).pushManager.subscribe(
|
|
134
|
-
_isObject(publicKey) ? publicKey : {
|
|
135
|
-
applicationServerKey: urlBase64ToUint8Array(publicKey),
|
|
136
|
-
...params,
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
},
|
|
140
|
-
unsubscribe: async () => {
|
|
141
|
-
var subscription = await this.push.getSubscription();
|
|
142
|
-
return !subscription ? null : subscription.unsubscribe();
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Public base64 to Uint
|
|
150
|
-
function urlBase64ToUint8Array(base64String) {
|
|
151
|
-
var padding = '='.repeat((4 - base64String.length % 4) % 4);
|
|
152
|
-
var base64 = (base64String + padding)
|
|
153
|
-
.replace(/\-/g, '+')
|
|
154
|
-
.replace(/_/g, '/');
|
|
155
|
-
|
|
156
|
-
var rawData = window.atob(base64);
|
|
157
|
-
var outputArray = new Uint8Array(rawData.length);
|
|
158
|
-
|
|
159
|
-
for (var i = 0; i < rawData.length; ++i) {
|
|
160
|
-
outputArray[i] = rawData.charCodeAt(i);
|
|
161
|
-
}
|
|
162
|
-
return outputArray;
|
|
163
|
-
}
|
|
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 = {}) {
|
|
12
|
+
this.ready = navigator.serviceWorker.ready;
|
|
13
|
+
|
|
14
|
+
// --------
|
|
15
|
+
// Registration and lifecycle
|
|
16
|
+
// --------
|
|
17
|
+
this.registration = new Promise((resolve, reject) => {
|
|
18
|
+
const register = () => {
|
|
19
|
+
navigator.serviceWorker.register(file, { scope: params.scope || '/' }).then(async registration => {
|
|
20
|
+
|
|
21
|
+
// Helper that updates instance's state
|
|
22
|
+
const state = target => {
|
|
23
|
+
// instance2.state can be any of: "installing", "installed", "activating", "activated", "redundant"
|
|
24
|
+
const equivState = target.state === 'installed' ? 'waiting' :
|
|
25
|
+
(target.state === 'activating' || target.state === 'activated' ? 'active' : target.state)
|
|
26
|
+
Observer.set(this, equivState, target);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// We're always installing at first for a new service worker.
|
|
30
|
+
// An existing service would immediately be active
|
|
31
|
+
const worker = registration.active || registration.waiting || registration.installing;
|
|
32
|
+
state(worker);
|
|
33
|
+
worker.addEventListener('statechange', e => state(e.target));
|
|
34
|
+
|
|
35
|
+
// "updatefound" event - a new worker that will control
|
|
36
|
+
// this page is installing somewhere
|
|
37
|
+
registration.addEventListener('updatefound', () => {
|
|
38
|
+
// If updatefound is fired, it means that there's
|
|
39
|
+
// a new service worker being installed.
|
|
40
|
+
state(registration.installing);
|
|
41
|
+
registration.installing.addEventListener('statechange', e => state(e.target));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
resolve(registration);
|
|
45
|
+
}).catch(e => reject(e));
|
|
46
|
+
};
|
|
47
|
+
if (params.onWondowLoad) {
|
|
48
|
+
window.addEventListener('load', register);
|
|
49
|
+
} else {
|
|
50
|
+
register();
|
|
51
|
+
}
|
|
52
|
+
if (params.startMessages) {
|
|
53
|
+
navigator.serviceWorker.startMessages();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// --------
|
|
58
|
+
// Post messaging
|
|
59
|
+
// --------
|
|
60
|
+
const postSendCallback = (message, callback, onAvailability = 1) => {
|
|
61
|
+
if (this.active) {
|
|
62
|
+
if (_isFunction(message)) message = message();
|
|
63
|
+
callback(this.active, message);
|
|
64
|
+
} else if (onAvailability) {
|
|
65
|
+
// Availability Handling
|
|
66
|
+
const availabilityHandler = entry => {
|
|
67
|
+
if (_isFunction(message)) message = message();
|
|
68
|
+
callback(entry.value, message);
|
|
69
|
+
if (onAvailability !== 2) {
|
|
70
|
+
Observer.unobserve(this, 'active', availabilityHandler);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
Observer.observe(this, 'active', availabilityHandler);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
this.messaging = {
|
|
77
|
+
post: (message, onAvailability = 1) => {
|
|
78
|
+
postSendCallback(message, (active, message) => {
|
|
79
|
+
active.postMessage(message);
|
|
80
|
+
}, onAvailability);
|
|
81
|
+
return this.post;
|
|
82
|
+
},
|
|
83
|
+
listen: callback => {
|
|
84
|
+
navigator.serviceWorker.addEventListener('message', callback);
|
|
85
|
+
return this.post;
|
|
86
|
+
},
|
|
87
|
+
request: (message, onAvailability = 1) => {
|
|
88
|
+
return new Promise(res => {
|
|
89
|
+
postSendCallback(message, (active, message) => {
|
|
90
|
+
let messageChannel = new MessageChannel();
|
|
91
|
+
active.postMessage(message, [ messageChannel.port2 ]);
|
|
92
|
+
messageChannel.port1.onmessage = e => res(e.data);
|
|
93
|
+
}, onAvailability);
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
channel(channelId) {
|
|
97
|
+
if (!this.channels.has(channelId)) { this.channels.set(channelId, new BroadcastChannel(channel)); }
|
|
98
|
+
let channel = this.channels.get(channelId);
|
|
99
|
+
return {
|
|
100
|
+
broadcast: message => channel.postMessage(message),
|
|
101
|
+
listen: callback => channel.addEventListener('message', callback),
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
channels: new Map,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// --------
|
|
108
|
+
// Notifications
|
|
109
|
+
// --------
|
|
110
|
+
this.notifications = {
|
|
111
|
+
fire: (title, params = {}) => {
|
|
112
|
+
return new Promise((res, rej) => {
|
|
113
|
+
if (typeof Notification === 'undefined' || Notification.permission !== 'granted') {
|
|
114
|
+
return rej(typeof Notification !== 'undefined' && Notification && Notification.permission);
|
|
115
|
+
}
|
|
116
|
+
notification.addEventListener('error', rej);
|
|
117
|
+
let notification = new Notification(title, params);
|
|
118
|
+
notification.addEventListener('click', res);
|
|
119
|
+
notification.addEventListener('close', res);
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// --------
|
|
125
|
+
// Push notifications
|
|
126
|
+
// --------
|
|
127
|
+
this.push = {
|
|
128
|
+
getSubscription: async () => {
|
|
129
|
+
return (await this.registration).pushManager.getSubscription();
|
|
130
|
+
},
|
|
131
|
+
subscribe: async (publicKey, params = {}) => {
|
|
132
|
+
var subscription = await this.push.getSubscription();
|
|
133
|
+
return subscription ? subscription : (await this.registration).pushManager.subscribe(
|
|
134
|
+
_isObject(publicKey) ? publicKey : {
|
|
135
|
+
applicationServerKey: urlBase64ToUint8Array(publicKey),
|
|
136
|
+
...params,
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
unsubscribe: async () => {
|
|
141
|
+
var subscription = await this.push.getSubscription();
|
|
142
|
+
return !subscription ? null : subscription.unsubscribe();
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Public base64 to Uint
|
|
150
|
+
function urlBase64ToUint8Array(base64String) {
|
|
151
|
+
var padding = '='.repeat((4 - base64String.length % 4) % 4);
|
|
152
|
+
var base64 = (base64String + padding)
|
|
153
|
+
.replace(/\-/g, '+')
|
|
154
|
+
.replace(/_/g, '/');
|
|
155
|
+
|
|
156
|
+
var rawData = window.atob(base64);
|
|
157
|
+
var outputArray = new Uint8Array(rawData.length);
|
|
158
|
+
|
|
159
|
+
for (var i = 0; i < rawData.length; ++i) {
|
|
160
|
+
outputArray[i] = rawData.charCodeAt(i);
|
|
161
|
+
}
|
|
162
|
+
return outputArray;
|
|
163
|
+
}
|