@basthon/kernel-base 0.73.1 → 0.73.2
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/lib/commons.js +7 -8
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/worker/kernel-worker.d.ts +5 -0
- package/lib/worker/kernel-worker.js +12 -0
- package/lib/worker/proxy.d.ts +1 -1
- package/lib/worker/proxy.js +5 -3
- package/package.json +2 -2
package/lib/commons.js
CHANGED
|
@@ -68,23 +68,22 @@ const mockFetch = (legacy) => {
|
|
|
68
68
|
const trueFetch = self.fetch;
|
|
69
69
|
const assetsURL = self._assetsURL;
|
|
70
70
|
async function mockedFetch(request, init) {
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const url = request.url ?? request.toString();
|
|
71
|
+
// build new request from init
|
|
72
|
+
request = new Request(request, init);
|
|
73
|
+
const url = request.url;
|
|
75
74
|
const localfsScheme = "filesystem:/";
|
|
76
75
|
// in legacy mode, only local FS is mocked
|
|
77
76
|
if (legacy) {
|
|
78
77
|
if (url.startsWith(localfsScheme))
|
|
79
78
|
return await fetchFromLocalFS(localfsScheme, url);
|
|
80
|
-
return await trueFetch(
|
|
79
|
+
return await trueFetch(request);
|
|
81
80
|
}
|
|
82
81
|
// not a true worker? -> error
|
|
83
82
|
if (self.importScripts == null || assetsURL == null)
|
|
84
83
|
return Response.error();
|
|
85
84
|
// non-legacy mode (true isolated secure worker)
|
|
86
85
|
// ensure credentials are not sent
|
|
87
|
-
|
|
86
|
+
request = new Request(request, { credentials: "omit" });
|
|
88
87
|
try {
|
|
89
88
|
// requests towards localfs
|
|
90
89
|
if (url.startsWith(localfsScheme)) {
|
|
@@ -95,12 +94,12 @@ const mockFetch = (legacy) => {
|
|
|
95
94
|
// only url under the assets folder are proxyied
|
|
96
95
|
if (parent(url).startsWith(assetsURL)) {
|
|
97
96
|
const proxy = self._remoteProxy;
|
|
98
|
-
const { body, options } = await proxy.fetch(
|
|
97
|
+
const { body, options } = await proxy.fetch(request);
|
|
99
98
|
return new Response(body, options);
|
|
100
99
|
}
|
|
101
100
|
throw new Error("Ressource is outside the proxy' scope");
|
|
102
101
|
}
|
|
103
|
-
return await trueFetch(
|
|
102
|
+
return await trueFetch(request);
|
|
104
103
|
}
|
|
105
104
|
catch (e) {
|
|
106
105
|
console.error(`security proxy: request to ${url} throw error: ${e.toString()}`);
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.73.
|
|
1
|
+
export declare const VERSION = "0.73.2";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.73.
|
|
1
|
+
export const VERSION = "0.73.2";
|
|
@@ -183,5 +183,10 @@ declare class KernelWorkerBase {
|
|
|
183
183
|
* Ask main thread to go to the next breakpoint.
|
|
184
184
|
*/
|
|
185
185
|
breakpointMoveOn(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Create the message channel between kernel and iframe,
|
|
188
|
+
* send one port and the iframe to main thread and return the other one.
|
|
189
|
+
*/
|
|
190
|
+
displayKernelIFrame(iframeHTML: string): MessagePort;
|
|
186
191
|
}
|
|
187
192
|
export { ExecuteResult, KernelWorkerBase };
|
|
@@ -416,5 +416,17 @@ class KernelWorkerBase {
|
|
|
416
416
|
const data = this.clone(this.__eval_data__);
|
|
417
417
|
this.postMessage?.({ type: "breakpoint-move-on", content: { data } });
|
|
418
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Create the message channel between kernel and iframe,
|
|
421
|
+
* send one port and the iframe to main thread and return the other one.
|
|
422
|
+
*/
|
|
423
|
+
displayKernelIFrame(iframeHTML) {
|
|
424
|
+
const { port1, port2 } = new MessageChannel();
|
|
425
|
+
const content = { html: iframeHTML, port: port1 };
|
|
426
|
+
const display_type = "kernel-iframe";
|
|
427
|
+
const data = { ...this.clone(this.__eval_data__), content, display_type };
|
|
428
|
+
this.postMessage?.({ data, type: "display" }, [port1]);
|
|
429
|
+
return port2;
|
|
430
|
+
}
|
|
419
431
|
}
|
|
420
432
|
export { KernelWorkerBase };
|
package/lib/worker/proxy.d.ts
CHANGED
package/lib/worker/proxy.js
CHANGED
|
@@ -4,16 +4,18 @@ import { transfer } from "comlink";
|
|
|
4
4
|
* to fetch assets.
|
|
5
5
|
*/
|
|
6
6
|
export class ProxyFetch {
|
|
7
|
-
async fetch(
|
|
7
|
+
async fetch(request, init) {
|
|
8
|
+
request = new Request(request, init);
|
|
9
|
+
const url = request.url;
|
|
8
10
|
const parentURL = (s) => s.substring(0, s.lastIndexOf("/"));
|
|
9
11
|
const assetsURL = parentURL(new URL(globalThis.location.toString()).href);
|
|
10
12
|
const baseURL = parentURL(new URL(url).href);
|
|
11
13
|
if (!baseURL.startsWith(assetsURL))
|
|
12
14
|
throw new Error(`URL ${url} is outside of proxy' scope`);
|
|
13
15
|
// force credentials omition
|
|
14
|
-
if (
|
|
16
|
+
if (request.credentials !== "omit")
|
|
15
17
|
throw new Error("Request tries to use credentials");
|
|
16
|
-
const response = await globalThis.fetch(
|
|
18
|
+
const response = await globalThis.fetch(request);
|
|
17
19
|
const buffer = await response.arrayBuffer();
|
|
18
20
|
return {
|
|
19
21
|
body: transfer(buffer, [buffer]),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basthon/kernel-base",
|
|
3
|
-
"version": "0.73.
|
|
3
|
+
"version": "0.73.2",
|
|
4
4
|
"description": "Basthon - Base Kernel",
|
|
5
5
|
"homepage": "https://basthon.fr",
|
|
6
6
|
"bugs": {
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "95bbd19a61673aecea85f72bc03cfe5cbcb26660"
|
|
51
51
|
}
|