@botiverse/porthole 0.13.0 → 0.14.1
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 +770 -0
- package/dist/annotate/types.d.ts +36 -4
- package/dist/annotate/types.js +6 -0
- package/dist/annotate/validate.d.ts +2 -1
- package/dist/annotate/validate.js +30 -6
- package/dist/check/page-source.js +1 -1
- package/dist/compile/policy.d.ts +7 -0
- package/dist/compile/policy.js +13 -1
- package/dist/config/schema.d.ts +11 -0
- package/dist/config/validate.js +19 -0
- package/dist/conformance/harness-source.js +1 -1
- package/dist/displays/displays.js +3 -1
- package/dist/guide/limits.js +1 -1
- package/dist/host/create-host.d.ts +2 -0
- package/dist/host/create-host.js +78 -3
- package/dist/host/pass-on.d.ts +15 -0
- package/dist/host/pass-on.js +65 -0
- package/dist/host/types.d.ts +29 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/isolation/types.d.ts +8 -0
- package/dist/isolation/types.js +8 -0
- package/dist/platform/focus-guard.d.ts +71 -2
- package/dist/platform/focus-guard.js +187 -12
- package/dist/platform/types.d.ts +8 -1
- package/dist/platform/web.js +60 -4
- package/dist/presets/presets.d.ts +2 -0
- package/dist/presets/presets.js +1 -0
- package/dist/react/frame.d.ts +4 -3
- package/dist/server/files.js +19 -3
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +5 -0
- package/dist/server/naming.js +4 -0
- package/dist/server/nested.d.ts +59 -0
- package/dist/server/nested.js +96 -0
- package/dist/server/server.js +193 -23
- package/dist/server/types.d.ts +5 -0
- package/dist/shell/annotate.d.ts +4 -3
- package/dist/shell/annotate.js +179 -9
- package/dist/shell/frame.d.ts +45 -0
- package/dist/shell/frame.js +250 -0
- package/dist/shell/plan.js +2 -1
- package/dist/shell/runtime.d.ts +6 -0
- package/dist/shell/runtime.js +60 -15
- package/docs/ADOPTING.md +85 -2
- package/docs/ARCHITECTURE.md +28 -0
- package/docs/DECISIONS.md +416 -1
- package/docs/DESIGN.md +21 -4
- package/docs/THREAT_MODEL.md +102 -5
- package/package.json +6 -5
- package/src/annotate/types.ts +32 -4
- package/src/annotate/validate.ts +34 -8
- package/src/compile/policy.ts +14 -1
- package/src/config/schema.ts +11 -0
- package/src/config/validate.ts +23 -0
- package/src/displays/displays.ts +3 -1
- package/src/guide/limits.ts +1 -1
- package/src/host/create-host.ts +81 -4
- package/src/host/pass-on.ts +73 -0
- package/src/host/types.ts +27 -0
- package/src/index.ts +4 -1
- package/src/isolation/types.ts +12 -0
- package/src/platform/focus-guard.ts +258 -15
- package/src/platform/types.ts +8 -1
- package/src/platform/web.ts +81 -9
- package/src/presets/presets.ts +3 -0
- package/src/react/frame.tsx +4 -3
- package/src/server/files.ts +19 -3
- package/src/server/index.ts +14 -0
- package/src/server/naming.ts +4 -0
- package/src/server/nested.ts +116 -0
- package/src/server/server.ts +224 -21
- package/src/server/types.ts +5 -0
- package/src/shell/annotate.ts +179 -9
- package/src/shell/frame.ts +268 -0
- package/src/shell/plan.ts +2 -1
- package/src/shell/runtime.ts +61 -15
package/src/shell/runtime.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a draft holds back (P117), spliced into the runtime: a tag start the content was cut in
|
|
3
|
+
* (a trailing `<`, `</`, or `<` and a tag's name or attributes, with no `>` yet) is left out until
|
|
4
|
+
* more comes. Parsed as it is, a cut right after `<` or `</` draws them as text.
|
|
5
|
+
*/
|
|
6
|
+
export const HELD_BACK = String.raw`(html) => {
|
|
7
|
+
const at = html.lastIndexOf("<");
|
|
8
|
+
return at !== -1 && /^\/?(?:[A-Za-z][^>]*)?$/.test(html.slice(at + 1)) ? html.slice(0, at) : html;
|
|
9
|
+
}`;
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* The shell's runtime: the code that runs first in the frame, before any content. Plain ES2020,
|
|
3
13
|
* no imports and no build step, so every engine (a browser frame now, a native web view later)
|
|
@@ -68,6 +78,9 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
68
78
|
}
|
|
69
79
|
};
|
|
70
80
|
|
|
81
|
+
// Whether the page touched storage, told to the host once (P111): yes, never what it keeps.
|
|
82
|
+
let storageTouched = false;
|
|
83
|
+
let tellStorage = () => {};
|
|
71
84
|
if (plan.storage === "memory") {
|
|
72
85
|
// An opaque origin has no storage: a map stands in, for as long as the frame lives.
|
|
73
86
|
const store = () => {
|
|
@@ -84,8 +97,18 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
84
97
|
};
|
|
85
98
|
};
|
|
86
99
|
for (const name of ["localStorage", "sessionStorage"]) {
|
|
100
|
+
const kept = store();
|
|
87
101
|
try {
|
|
88
|
-
Object.defineProperty(window, name, {
|
|
102
|
+
Object.defineProperty(window, name, {
|
|
103
|
+
configurable: true,
|
|
104
|
+
get() {
|
|
105
|
+
if (!storageTouched) {
|
|
106
|
+
storageTouched = true;
|
|
107
|
+
tellStorage();
|
|
108
|
+
}
|
|
109
|
+
return kept;
|
|
110
|
+
},
|
|
111
|
+
});
|
|
89
112
|
} catch (_) {}
|
|
90
113
|
}
|
|
91
114
|
}
|
|
@@ -115,6 +138,8 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
115
138
|
// takes the next load for that page, not for content that left). Anything else stays stopped:
|
|
116
139
|
// another path of the origin, a file that isn't a page, another origin.
|
|
117
140
|
let navigating = (_url) => {};
|
|
141
|
+
// A nested page's files' address renewed by its shell (P111), which the shell's message gives.
|
|
142
|
+
let adoptFiles = (_base) => false;
|
|
118
143
|
let filesBase = plan.files && typeof plan.files.base === "string" ? plan.files.base : null;
|
|
119
144
|
// Every address the page's files had (P083: a sealed one is renewed): what reports say as "./".
|
|
120
145
|
const filesBases = filesBase === null ? [] : [filesBase];
|
|
@@ -880,6 +905,11 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
880
905
|
const filesSet = plan.files && plan.files.set && typeof plan.files.set === "object" ? { id: String(plan.files.set.id), version: String(plan.files.set.version) } : null;
|
|
881
906
|
const notice = (url, more) => post({ method: "porthole/navigating", params: Object.assign({ url: ownAddresses(url).slice(0, 4096) }, filesSet === null ? {} : { set: filesSet }, more) });
|
|
882
907
|
navigating = (url) => notice(url, {});
|
|
908
|
+
// The page used storage (P111): said once, as soon as the shell can speak; never keys or values.
|
|
909
|
+
tellStorage = () => post({ method: "porthole/storage-used", params: {} });
|
|
910
|
+
if (storageTouched) {
|
|
911
|
+
tellStorage();
|
|
912
|
+
}
|
|
883
913
|
if (arrived) {
|
|
884
914
|
notice(location.href, { arrived: true });
|
|
885
915
|
}
|
|
@@ -887,28 +917,38 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
887
917
|
// it ends, the page moved to the new one in place (the same page, the same history entry). Its
|
|
888
918
|
// modules keep the address they loaded from; the server serves their own loads till the session
|
|
889
919
|
// ends.
|
|
920
|
+
const replace = History.prototype.replaceState;
|
|
921
|
+
// The files' origin, read from the address itself: a nested page's own origin is opaque (P111).
|
|
922
|
+
const filesOrigin = filesBase === null ? null : new NativeURL(filesBase).origin;
|
|
923
|
+
// A renewed sealed address (P083): one segment under the same origin's sealed prefix, checked
|
|
924
|
+
// through the platform's own functions (content may have replaced a prototype's, and the base
|
|
925
|
+
// decides where this page may go, ownPage); the page moves there in place.
|
|
926
|
+
const adopt = (base) => {
|
|
927
|
+
const prefix = filesOrigin + "/__porthole/f/";
|
|
928
|
+
if (filesBase === null || typeof base !== "string" || callOf(indexIn, base, [prefix]) !== 0 || callOf(indexIn, callOf(sliceOf, base, [prefix.length, -1]), ["/"]) !== -1 || callOf(sliceOf, base, [-1]) !== "/") {
|
|
929
|
+
return false;
|
|
930
|
+
}
|
|
931
|
+
const here = location.href;
|
|
932
|
+
if (here.indexOf(filesBase) === 0) {
|
|
933
|
+
try {
|
|
934
|
+
applyOf(replace, history, [history.state, "", base + here.slice(filesBase.length)]);
|
|
935
|
+
} catch (_) {}
|
|
936
|
+
}
|
|
937
|
+
filesBase = base;
|
|
938
|
+
filesBases.push(base);
|
|
939
|
+
return true;
|
|
940
|
+
};
|
|
941
|
+
adoptFiles = adopt;
|
|
890
942
|
if (filesBase !== null && typeof plan.files.expires === "number") {
|
|
891
943
|
const nativeFetch = window.fetch.bind(window);
|
|
892
|
-
const replace = History.prototype.replaceState;
|
|
893
944
|
const renewIn = (expires) => Math.max(30000, expires - Date.now() - 300000);
|
|
894
945
|
const renew = () => {
|
|
895
946
|
nativeFetch(filesBase + "__porthole/renew", { credentials: "omit", cache: "no-store" })
|
|
896
947
|
.then((answer) => (answer.ok ? answer.json() : null))
|
|
897
948
|
.then((renewed) => {
|
|
898
|
-
|
|
899
|
-
// and the base decides where this page may go (ownPage).
|
|
900
|
-
const prefix = location.origin + "/__porthole/f/";
|
|
901
|
-
if (!renewed || typeof renewed.base !== "string" || typeof renewed.expires !== "number" || callOf(indexIn, renewed.base, [prefix]) !== 0 || callOf(indexIn, callOf(sliceOf, renewed.base, [prefix.length, -1]), ["/"]) !== -1 || callOf(sliceOf, renewed.base, [-1]) !== "/") {
|
|
949
|
+
if (!renewed || typeof renewed.expires !== "number" || !adopt(renewed.base)) {
|
|
902
950
|
return;
|
|
903
951
|
}
|
|
904
|
-
const here = location.href;
|
|
905
|
-
if (here.indexOf(filesBase) === 0) {
|
|
906
|
-
try {
|
|
907
|
-
applyOf(replace, history, [history.state, "", renewed.base + here.slice(filesBase.length)]);
|
|
908
|
-
} catch (_) {}
|
|
909
|
-
}
|
|
910
|
-
filesBase = renewed.base;
|
|
911
|
-
filesBases.push(renewed.base);
|
|
912
952
|
setTimeout(renew, renewIn(renewed.expires));
|
|
913
953
|
})
|
|
914
954
|
.catch(() => setTimeout(renew, 60000));
|
|
@@ -1393,11 +1433,12 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
1393
1433
|
}
|
|
1394
1434
|
};
|
|
1395
1435
|
let drafted = false;
|
|
1436
|
+
const heldBack = ${HELD_BACK};
|
|
1396
1437
|
const draft = (input) => {
|
|
1397
1438
|
if (rendered || root === null || input === null || typeof input !== "object" || plan.content === "document") {
|
|
1398
1439
|
return;
|
|
1399
1440
|
}
|
|
1400
|
-
morph(root, inert(parseInert(input.html || "")));
|
|
1441
|
+
morph(root, inert(parseInert(heldBack(String(input.html || "")))));
|
|
1401
1442
|
drafted = true;
|
|
1402
1443
|
drawn = true;
|
|
1403
1444
|
schedule();
|
|
@@ -1465,6 +1506,11 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
1465
1506
|
case "ui/notifications/tool-input":
|
|
1466
1507
|
void render(params.arguments);
|
|
1467
1508
|
break;
|
|
1509
|
+
case "porthole/files-renewed":
|
|
1510
|
+
// From the page's parent only (the listener's check): a nested page's shell renewed its
|
|
1511
|
+
// files' sealed address, which this page can't (its loads aren't its origin's own, P111).
|
|
1512
|
+
adoptFiles(params.base);
|
|
1513
|
+
break;
|
|
1468
1514
|
case "ui/notifications/host-context-changed":
|
|
1469
1515
|
applyTheme(params);
|
|
1470
1516
|
break;
|