@botiverse/porthole 0.6.0 → 0.7.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/README.md +16 -0
- package/dist/bridge/bridge.d.ts +13 -0
- package/dist/bridge/bridge.js +200 -8
- package/dist/bridge/refusal.d.ts +5 -1
- package/dist/bridge/refusal.js +16 -0
- package/dist/bridge/types.d.ts +41 -4
- package/dist/check/check.d.ts +7 -0
- package/dist/check/check.js +1 -0
- package/dist/check/instrument.d.ts +3 -0
- package/dist/check/lint.js +4 -2
- package/dist/check/page-source.js +1 -1
- package/dist/check/page.js +14 -0
- package/dist/check/tools.js +2 -3
- package/dist/compile/policy.d.ts +19 -0
- package/dist/compile/policy.js +42 -0
- package/dist/config/capabilities.d.ts +62 -3
- package/dist/config/capabilities.js +20 -0
- package/dist/config/schema.d.ts +24 -0
- package/dist/config/validate.d.ts +1 -1
- package/dist/config/validate.js +66 -4
- package/dist/conformance/harness-source.js +1 -1
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +2 -0
- package/dist/conformance/runtime.d.ts +58 -0
- package/dist/conformance/runtime.js +314 -0
- package/dist/guide/gates.d.ts +3 -0
- package/dist/guide/gates.js +19 -0
- package/dist/guide/guide.d.ts +2 -0
- package/dist/guide/guide.js +34 -32
- package/dist/guide/limits.js +4 -4
- package/dist/guide/runtime.d.ts +13 -0
- package/dist/guide/runtime.js +202 -0
- package/dist/host/create-host.js +24 -0
- package/dist/host/locate.js +8 -0
- package/dist/host/locator.js +7 -0
- package/dist/host/types.d.ts +18 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +9 -1
- package/dist/isolation/types.d.ts +8 -0
- package/dist/presets/presets.d.ts +6 -0
- package/dist/presets/presets.js +1 -0
- package/dist/protocol/runtime-calls.d.ts +28 -0
- package/dist/protocol/runtime-calls.js +113 -0
- package/dist/protocol/shell-adapter.js +48 -3
- package/dist/react/dialog.js +31 -0
- package/dist/react/frame.d.ts +13 -0
- package/dist/react/frame.js +6 -0
- package/dist/runtime/contract.d.ts +193 -0
- package/dist/runtime/contract.js +216 -0
- package/dist/runtime/db.d.ts +153 -0
- package/dist/runtime/db.js +398 -0
- package/dist/runtime/declaration.d.ts +86 -0
- package/dist/runtime/declaration.js +266 -0
- package/dist/runtime/levels.d.ts +33 -0
- package/dist/runtime/levels.js +41 -0
- package/dist/runtime/requests.d.ts +125 -0
- package/dist/runtime/requests.js +199 -0
- package/dist/runtime/segments.d.ts +8 -0
- package/dist/runtime/segments.js +14 -0
- package/dist/runtime/types.generated.d.ts +1 -0
- package/dist/runtime/types.generated.js +19 -0
- package/dist/server/files.d.ts +14 -1
- package/dist/server/files.js +97 -3
- package/dist/server/host.d.ts +6 -1
- package/dist/server/host.js +5 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +1 -0
- package/dist/server/pseudonym.d.ts +9 -0
- package/dist/server/pseudonym.js +20 -0
- package/dist/server/server.d.ts +0 -5
- package/dist/server/server.js +214 -35
- package/dist/server/types.d.ts +69 -0
- package/dist/shell/document.d.ts +8 -0
- package/dist/shell/document.js +16 -2
- package/dist/shell/legacy.d.ts +21 -0
- package/dist/shell/legacy.js +63 -0
- package/dist/shell/plan.d.ts +17 -1
- package/dist/shell/plan.js +13 -2
- package/dist/shell/runtime.js +29 -42
- package/dist/shell/use.d.ts +15 -0
- package/dist/shell/use.js +235 -0
- package/docs/ADOPTING.md +91 -6
- package/docs/ARCHITECTURE.md +22 -3
- package/docs/DECISIONS.md +415 -6
- package/docs/DESIGN.md +66 -0
- package/package.json +3 -1
- package/src/bridge/bridge.ts +273 -12
- package/src/bridge/refusal.ts +16 -0
- package/src/bridge/types.ts +46 -4
- package/src/check/check.ts +8 -0
- package/src/check/instrument.ts +3 -0
- package/src/check/lint.ts +4 -2
- package/src/check/page.ts +14 -0
- package/src/check/tools.ts +2 -3
- package/src/compile/policy.ts +54 -0
- package/src/config/capabilities.ts +49 -2
- package/src/config/schema.ts +24 -0
- package/src/config/validate.ts +99 -4
- package/src/conformance/index.ts +7 -0
- package/src/conformance/runtime.ts +573 -0
- package/src/guide/gates.ts +25 -0
- package/src/guide/guide.ts +59 -53
- package/src/guide/limits.ts +4 -4
- package/src/guide/runtime.ts +244 -0
- package/src/host/create-host.ts +34 -0
- package/src/host/locate.ts +10 -0
- package/src/host/locator.ts +11 -0
- package/src/host/types.ts +18 -0
- package/src/index.ts +89 -0
- package/src/isolation/types.ts +8 -0
- package/src/presets/presets.ts +7 -0
- package/src/protocol/runtime-calls.ts +138 -0
- package/src/protocol/shell-adapter.ts +52 -3
- package/src/react/dialog.tsx +33 -0
- package/src/react/frame.tsx +19 -0
- package/src/runtime/contract.ts +305 -0
- package/src/runtime/db.ts +530 -0
- package/src/runtime/declaration.ts +378 -0
- package/src/runtime/levels.ts +69 -0
- package/src/runtime/requests.ts +339 -0
- package/src/runtime/segments.ts +17 -0
- package/src/runtime/types.generated.ts +19 -0
- package/src/server/files.ts +117 -4
- package/src/server/host.ts +12 -0
- package/src/server/index.ts +3 -0
- package/src/server/pseudonym.ts +21 -0
- package/src/server/server.ts +247 -37
- package/src/server/types.ts +68 -0
- package/src/shell/document.ts +21 -4
- package/src/shell/legacy.ts +64 -0
- package/src/shell/plan.ts +37 -3
- package/src/shell/runtime.ts +29 -42
- package/src/shell/use.ts +235 -0
- package/types/runtime/v1/artifact.d.ts +50 -0
- package/types/runtime/v1/assets.d.ts +43 -0
- package/types/runtime/v1/chat.d.ts +13 -0
- package/types/runtime/v1/clipboard.d.ts +14 -0
- package/types/runtime/v1/comments.d.ts +24 -0
- package/types/runtime/v1/context.d.ts +16 -0
- package/types/runtime/v1/data.d.ts +29 -0
- package/types/runtime/v1/db.d.ts +110 -0
- package/types/runtime/v1/downloads.d.ts +22 -0
- package/types/runtime/v1/links.d.ts +13 -0
- package/types/runtime/v1/porthole.d.ts +44 -0
- package/types/runtime/v1/user.d.ts +19 -0
package/src/compile/policy.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CAPABILITIES, type CapabilityName, type Gate } from "../config/capabilities.ts";
|
|
2
2
|
import type { PortholeConfig } from "../config/schema.ts";
|
|
3
3
|
import { LIBRARY_PATH } from "../libraries/libraries.ts";
|
|
4
|
+
import { assetCodeRuns, familyOf, methodGates, methodOf } from "../runtime/contract.ts";
|
|
5
|
+
import { ASSET_PATH } from "../runtime/requests.ts";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* The frame's policies, derived from the config: its CSP (in the shell's `<meta>` for opaque
|
|
@@ -30,6 +32,22 @@ export function effectiveGates(config: PortholeConfig, name: CapabilityName): re
|
|
|
30
32
|
return config.capabilities[name]?.gates ?? CAPABILITIES[name].defaultGates;
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The gates one call runs under: its host function's, and its runtime method's own (after the
|
|
37
|
+
* review: `artifact.publish`, `assets.delete`, an upload whose code may run), every one applying.
|
|
38
|
+
*/
|
|
39
|
+
export function callGates(
|
|
40
|
+
config: PortholeConfig,
|
|
41
|
+
name: CapabilityName,
|
|
42
|
+
args: unknown,
|
|
43
|
+
): readonly Gate[] {
|
|
44
|
+
const gates = effectiveGates(config, name);
|
|
45
|
+
const family = familyOf(name);
|
|
46
|
+
const method = family === null ? null : methodOf(name, args);
|
|
47
|
+
const own = family === null || method === null ? [] : methodGates(config, family.name, method);
|
|
48
|
+
return own.length === 0 ? gates : [...gates, ...own.filter((gate) => !gates.includes(gate))];
|
|
49
|
+
}
|
|
50
|
+
|
|
33
51
|
const unique = (values: readonly string[]): string[] => [...new Set(values)];
|
|
34
52
|
|
|
35
53
|
/** The origins content may reach for `kind`: the base allowlist plus every declared capability's. */
|
|
@@ -133,6 +151,42 @@ export function fileSetCspDirectives(
|
|
|
133
151
|
});
|
|
134
152
|
}
|
|
135
153
|
|
|
154
|
+
/**
|
|
155
|
+
* The directives a page opens its artifact's asset library to (P089), at `/_blob/` on its own
|
|
156
|
+
* origin: what loads without running, always; what runs (scripts, styles) only where uploads are
|
|
157
|
+
* the admins' alone, who publish the page's code anyway.
|
|
158
|
+
*/
|
|
159
|
+
export const ASSET_DIRECTIVES = ["img-src", "media-src", "font-src", "connect-src"] as const;
|
|
160
|
+
export const ASSET_CODE_DIRECTIVES = ["script-src", "style-src"] as const;
|
|
161
|
+
|
|
162
|
+
export { assetCodeRuns };
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A served page's CSP with its asset library opened (P089), on `origin` (the page's own, exact:
|
|
166
|
+
* never a sibling's): only where the config declares `assets`. Never `'self'`.
|
|
167
|
+
*/
|
|
168
|
+
export function assetCspDirectives(
|
|
169
|
+
config: PortholeConfig,
|
|
170
|
+
directives: readonly CspDirective[],
|
|
171
|
+
origin: string,
|
|
172
|
+
): CspDirective[] {
|
|
173
|
+
if (config.capabilities.assets === undefined || config.isolation !== "domain") {
|
|
174
|
+
return [...directives];
|
|
175
|
+
}
|
|
176
|
+
const source = `${origin}${ASSET_PATH}`;
|
|
177
|
+
const opened = new Set<string>([
|
|
178
|
+
...ASSET_DIRECTIVES,
|
|
179
|
+
...(assetCodeRuns(config) ? ASSET_CODE_DIRECTIVES : []),
|
|
180
|
+
]);
|
|
181
|
+
return directives.map(([name, ...sources]) => {
|
|
182
|
+
if (!opened.has(name)) {
|
|
183
|
+
return [name, ...sources];
|
|
184
|
+
}
|
|
185
|
+
const kept = sources.filter((each) => each !== "'none'");
|
|
186
|
+
return [name, ...kept, source];
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
136
190
|
/**
|
|
137
191
|
* The CSP of a file of a set that is neither a page nor a script (P081): nothing loads from it,
|
|
138
192
|
* and opened as a document (an SVG, an XML file) it runs nothing, on an opaque origin.
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { AnnotationReport } from "../annotate/types.ts";
|
|
2
|
+
import type { DbRequest, DbResult } from "../runtime/db.ts";
|
|
3
|
+
import type {
|
|
4
|
+
ArtifactInfo,
|
|
5
|
+
ArtifactRequest,
|
|
6
|
+
AssetInfo,
|
|
7
|
+
AssetRequest,
|
|
8
|
+
CommentRequest,
|
|
9
|
+
PublishedVersion,
|
|
10
|
+
UserInfo,
|
|
11
|
+
} from "../runtime/requests.ts";
|
|
2
12
|
|
|
3
13
|
/**
|
|
4
14
|
* The capability vocabulary (PRINCIPLE 4): every power content has beyond drawing is one of these
|
|
@@ -22,6 +32,12 @@ export const CAPABILITY_NAMES = [
|
|
|
22
32
|
"resize",
|
|
23
33
|
"copyText",
|
|
24
34
|
"annotate",
|
|
35
|
+
// The capability runtime's own (P085, `config.runtime`): reached through `porthole.use`.
|
|
36
|
+
"user",
|
|
37
|
+
"comments",
|
|
38
|
+
"artifact",
|
|
39
|
+
"assets",
|
|
40
|
+
"db",
|
|
25
41
|
] as const;
|
|
26
42
|
|
|
27
43
|
export type CapabilityName = (typeof CAPABILITY_NAMES)[number];
|
|
@@ -49,8 +65,11 @@ export type Gate =
|
|
|
49
65
|
export interface CapabilitySpec {
|
|
50
66
|
/** The gates a declared capability gets when its config names none. */
|
|
51
67
|
readonly defaultGates: readonly Gate[];
|
|
52
|
-
/**
|
|
53
|
-
|
|
68
|
+
/**
|
|
69
|
+
* `handler`: the host passes a function that performs it. `event`: the framework emits it.
|
|
70
|
+
* `viewer`: the framework answers it from the viewer the host gave the display (`user`).
|
|
71
|
+
*/
|
|
72
|
+
readonly served: "handler" | "event" | "viewer";
|
|
54
73
|
/** The global the shell defines for it (sugar over the protocol message), if any. */
|
|
55
74
|
readonly global?: string;
|
|
56
75
|
/**
|
|
@@ -129,6 +148,20 @@ export const CAPABILITIES = {
|
|
|
129
148
|
* (it shares the realm): UI hints for the host, never permissions.
|
|
130
149
|
*/
|
|
131
150
|
annotate: { defaultGates: [rate(120)], served: "event" },
|
|
151
|
+
/** Who is viewing (P087): answered from the viewer the host gave the display. */
|
|
152
|
+
user: { defaultGates: [rate(60)], served: "viewer", request: { method: "porthole/call" } },
|
|
153
|
+
/** Opens the host's comment composer at the page's anchor (P090): write-only. */
|
|
154
|
+
comments: {
|
|
155
|
+
defaultGates: ["user-activation", rate(30)],
|
|
156
|
+
served: "handler",
|
|
157
|
+
request: { method: "porthole/call" },
|
|
158
|
+
},
|
|
159
|
+
/** This artifact's current version, and a new version of it, base-checked (P088). */
|
|
160
|
+
artifact: { defaultGates: [rate(10)], served: "handler", request: { method: "porthole/call" } },
|
|
161
|
+
/** The artifact's asset library, served at `/_blob/<id>` (P089). */
|
|
162
|
+
assets: { defaultGates: [rate(30)], served: "handler", request: { method: "porthole/call" } },
|
|
163
|
+
/** The artifact's shared document store (P088). */
|
|
164
|
+
db: { defaultGates: [rate(600)], served: "handler", request: { method: "porthole/call" } },
|
|
132
165
|
} as const satisfies { readonly [N in CapabilityName]: CapabilitySpec };
|
|
133
166
|
|
|
134
167
|
/** The arguments a call carries, once the adapter has validated them. */
|
|
@@ -156,6 +189,12 @@ export interface CapabilityArgs {
|
|
|
156
189
|
readonly copyText: { readonly text: string };
|
|
157
190
|
/** What the frame reported, once checked (`AnnotationReport`). */
|
|
158
191
|
readonly annotate: AnnotationReport;
|
|
192
|
+
readonly user: Readonly<Record<string, never>>;
|
|
193
|
+
readonly comments: CommentRequest;
|
|
194
|
+
readonly artifact: ArtifactRequest;
|
|
195
|
+
readonly assets: AssetRequest;
|
|
196
|
+
/** Paths checked, `me` resolved, the viewer's own data only (P088). */
|
|
197
|
+
readonly db: DbRequest;
|
|
159
198
|
}
|
|
160
199
|
|
|
161
200
|
/** What a call resolves to. Protocol-shaped results (a tool's result) stay opaque to the core. */
|
|
@@ -176,6 +215,14 @@ export interface CapabilityResults {
|
|
|
176
215
|
/** Whether the text was copied. */
|
|
177
216
|
readonly copyText: boolean;
|
|
178
217
|
readonly annotate: undefined;
|
|
218
|
+
readonly user: UserInfo;
|
|
219
|
+
/** Whether the composer opened. Never a thread: content doesn't read comments (P090). */
|
|
220
|
+
readonly comments: boolean;
|
|
221
|
+
/** `get`: the current version; `publish`: the new one. */
|
|
222
|
+
readonly artifact: ArtifactInfo | PublishedVersion;
|
|
223
|
+
/** `list`: the library; `upload`: the new asset; `delete`: whether it was removed. */
|
|
224
|
+
readonly assets: AssetInfo | readonly AssetInfo[] | boolean;
|
|
225
|
+
readonly db: DbResult;
|
|
179
226
|
}
|
|
180
227
|
|
|
181
228
|
/** The capabilities a host serves with a handler. */
|
package/src/config/schema.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { RuntimeVersion } from "../runtime/contract.ts";
|
|
2
|
+
import type { ViewerLevel } from "../runtime/levels.ts";
|
|
1
3
|
import type { CapabilityName, Gate } from "./capabilities.ts";
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -44,6 +46,20 @@ export interface CapabilityConfig {
|
|
|
44
46
|
readonly resource?: readonly string[];
|
|
45
47
|
/** Replaces the generated manual entry for this capability. */
|
|
46
48
|
readonly guide?: string;
|
|
49
|
+
/**
|
|
50
|
+
* The least viewer level that may call each of the runtime methods it serves (P087), by method
|
|
51
|
+
* name (`db: { levels: { set: "admin" } }`, `sendPrompt: { levels: { send: "admin" } }`): over
|
|
52
|
+
* the contract's own, never below a method's floor (`RUNTIME_CAPABILITIES`). For
|
|
53
|
+
* `assets.upload`, `admin` or above also lets the page run what was uploaded as scripts and
|
|
54
|
+
* styles (P089); `interact` doesn't.
|
|
55
|
+
*/
|
|
56
|
+
readonly levels?: Readonly<Record<string, ViewerLevel>>;
|
|
57
|
+
/**
|
|
58
|
+
* Gates of each runtime method it serves, by name, in place of the contract's own (after the
|
|
59
|
+
* review: `artifact.publish` and `assets.delete` need a click and a yes; `assets.upload` a yes
|
|
60
|
+
* where uploaded code may run). Every one applies on top of `gates`. `[]`: none of its own.
|
|
61
|
+
*/
|
|
62
|
+
readonly methodGates?: Readonly<Record<string, readonly Gate[]>>;
|
|
47
63
|
}
|
|
48
64
|
|
|
49
65
|
/** The declared capabilities. Absent: not available, not wired, not in the CSP, not in the manual. */
|
|
@@ -223,6 +239,14 @@ export interface PortholeConfig {
|
|
|
223
239
|
* declares no `reportError`). Absent: the manual says they are reported to the app.
|
|
224
240
|
*/
|
|
225
241
|
readonly errors?: "agent" | "host" | "none";
|
|
242
|
+
/**
|
|
243
|
+
* The capability runtime (P085): content reaches capabilities through one global,
|
|
244
|
+
* `porthole.use(name)`, under this contract version, and the manual teaches it (with declaring
|
|
245
|
+
* them, `capabilities: { name: config }`, for pages that are published). Only with it may the
|
|
246
|
+
* config declare the runtime's own host functions (`user`, `comments`, `artifact`, `assets`,
|
|
247
|
+
* `db`). Absent: 0.6's frames, globals and manual, exactly.
|
|
248
|
+
*/
|
|
249
|
+
readonly runtime?: RuntimeVersion;
|
|
226
250
|
}
|
|
227
251
|
|
|
228
252
|
export interface StorageConfig {
|
package/src/config/validate.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CAPABILITY_NAMES,
|
|
3
|
+
isCapabilityName,
|
|
4
|
+
type CapabilityName,
|
|
5
|
+
type Gate,
|
|
6
|
+
} from "./capabilities.ts";
|
|
7
|
+
import {
|
|
8
|
+
RUNTIME_HOST_FUNCTIONS,
|
|
9
|
+
RUNTIME_VERSIONS,
|
|
10
|
+
familyOf,
|
|
11
|
+
isRuntimeVersion,
|
|
12
|
+
runtimeCapability,
|
|
13
|
+
type RuntimeMethod,
|
|
14
|
+
} from "../runtime/contract.ts";
|
|
15
|
+
import { atLeast, isViewerLevel } from "../runtime/levels.ts";
|
|
2
16
|
import {
|
|
3
17
|
PASSIVE_KINDS,
|
|
4
18
|
URL_PERMISSIONS,
|
|
@@ -24,7 +38,7 @@ export class ConfigError extends Error {
|
|
|
24
38
|
}
|
|
25
39
|
|
|
26
40
|
/** The built-in manual topics; a host's own topics may not reuse these names. */
|
|
27
|
-
export const BUILT_IN_TOPICS = ["widget", "chart", "interactive"] as const;
|
|
41
|
+
export const BUILT_IN_TOPICS = ["widget", "chart", "interactive", "capabilities"] as const;
|
|
28
42
|
|
|
29
43
|
const LOOPBACK = /^(localhost|127\.0\.0\.1|\[::1\])$|\.localhost$/u;
|
|
30
44
|
|
|
@@ -293,6 +307,7 @@ export function validateConfig(input: unknown): PortholeConfig {
|
|
|
293
307
|
"permissions",
|
|
294
308
|
"storage",
|
|
295
309
|
"errors",
|
|
310
|
+
"runtime",
|
|
296
311
|
],
|
|
297
312
|
"config",
|
|
298
313
|
);
|
|
@@ -314,7 +329,56 @@ export function validateConfig(input: unknown): PortholeConfig {
|
|
|
314
329
|
fail(path, `is not a capability (${CAPABILITY_NAMES.join(", ")})`);
|
|
315
330
|
}
|
|
316
331
|
const capability = object(value, path);
|
|
317
|
-
only(capability, ["gates", "connect", "resource", "guide"], path);
|
|
332
|
+
only(capability, ["gates", "connect", "resource", "guide", "levels", "methodGates"], path);
|
|
333
|
+
if (capability.methodGates !== undefined) {
|
|
334
|
+
const family = familyOf(name as CapabilityName);
|
|
335
|
+
for (const [method, gates] of Object.entries(
|
|
336
|
+
object(capability.methodGates, `${path}.methodGates`),
|
|
337
|
+
)) {
|
|
338
|
+
const methods: Readonly<Record<string, RuntimeMethod>> | undefined =
|
|
339
|
+
family === null ? undefined : runtimeCapability(family.name).methods;
|
|
340
|
+
if (
|
|
341
|
+
methods === undefined ||
|
|
342
|
+
!Object.hasOwn(methods, method) ||
|
|
343
|
+
methods[method]?.serves !== name
|
|
344
|
+
) {
|
|
345
|
+
fail(`${path}.methodGates.${method}`, `is not a runtime method ${name} serves`);
|
|
346
|
+
}
|
|
347
|
+
if (!Array.isArray(gates)) {
|
|
348
|
+
fail(`${path}.methodGates.${method}`, "must be an array of gates");
|
|
349
|
+
}
|
|
350
|
+
(gates as unknown[]).forEach((each, index) =>
|
|
351
|
+
gate(each, `${path}.methodGates.${method}[${index}]`),
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (capability.levels !== undefined) {
|
|
356
|
+
const levels = object(capability.levels, `${path}.levels`);
|
|
357
|
+
const family = familyOf(name as CapabilityName);
|
|
358
|
+
for (const [method, level] of Object.entries(levels)) {
|
|
359
|
+
const methods: Readonly<Record<string, RuntimeMethod>> | undefined =
|
|
360
|
+
family === null ? undefined : runtimeCapability(family.name).methods;
|
|
361
|
+
const spec =
|
|
362
|
+
methods !== undefined && Object.hasOwn(methods, method) ? methods[method] : undefined;
|
|
363
|
+
if (family === null || spec === undefined || spec.serves !== name) {
|
|
364
|
+
fail(
|
|
365
|
+
`${path}.levels.${method}`,
|
|
366
|
+
family === null
|
|
367
|
+
? `${name} serves no runtime method: it has no levels`
|
|
368
|
+
: `is not a method ${name} serves (${family.methods.join(", ")})`,
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
if (!isViewerLevel(level)) {
|
|
372
|
+
fail(`${path}.levels.${method}`, "must be view, interact, admin or owner");
|
|
373
|
+
}
|
|
374
|
+
if (spec !== undefined && !atLeast(level as never, spec.floor)) {
|
|
375
|
+
fail(
|
|
376
|
+
`${path}.levels.${method}`,
|
|
377
|
+
`can't be below ${spec.floor} (${family?.name}.${method}'s floor, P087)`,
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
318
382
|
if (capability.gates !== undefined) {
|
|
319
383
|
if (!Array.isArray(capability.gates)) {
|
|
320
384
|
fail(`${path}.gates`, "must be an array");
|
|
@@ -332,6 +396,35 @@ export function validateConfig(input: unknown): PortholeConfig {
|
|
|
332
396
|
if (config.mode === "url" && Object.keys(capabilities).length > 0) {
|
|
333
397
|
fail("config.capabilities", "url mode has no shell, so it can declare no capabilities");
|
|
334
398
|
}
|
|
399
|
+
// The capability runtime (P085): its global and its own host functions.
|
|
400
|
+
if (config.runtime !== undefined) {
|
|
401
|
+
if (!isRuntimeVersion(config.runtime)) {
|
|
402
|
+
fail("config.runtime", `must be a runtime contract version: ${RUNTIME_VERSIONS.join(", ")}`);
|
|
403
|
+
}
|
|
404
|
+
if (config.mode !== "inline" && config.mode !== "artifact") {
|
|
405
|
+
fail("config.runtime", "the runtime is the shell's: inline widgets and artifact pages only");
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
for (const name of RUNTIME_HOST_FUNCTIONS) {
|
|
409
|
+
if (capabilities[name] === undefined) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (config.runtime === undefined) {
|
|
413
|
+
fail(
|
|
414
|
+
`config.capabilities.${name}`,
|
|
415
|
+
"is the capability runtime's: set config.runtime (content reaches it through porthole.use)",
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
if ((name === "artifact" || name === "assets") && config.mode !== "artifact") {
|
|
419
|
+
fail(`config.capabilities.${name}`, "is an artifact page's: artifact mode only");
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (capabilities.assets !== undefined && config.isolation !== "domain") {
|
|
423
|
+
fail(
|
|
424
|
+
"config.capabilities.assets",
|
|
425
|
+
"assets are served from the page's own origin (/_blob/): domain isolation only",
|
|
426
|
+
);
|
|
427
|
+
}
|
|
335
428
|
|
|
336
429
|
const egress = object(config.egress, "config.egress");
|
|
337
430
|
const kinds = ["connect", "script", "style", "img", "font", "media"];
|
|
@@ -477,7 +570,9 @@ export function validateConfig(input: unknown): PortholeConfig {
|
|
|
477
570
|
const path = `config.guide.topics.${name}`;
|
|
478
571
|
if (
|
|
479
572
|
!/^[a-z][a-z0-9-]{0,31}$/u.test(name) ||
|
|
480
|
-
|
|
573
|
+
// `capabilities` is built in only under the runtime (P085): a 0.6 config's own stays.
|
|
574
|
+
((BUILT_IN_TOPICS as readonly string[]).includes(name) &&
|
|
575
|
+
(name !== "capabilities" || config.runtime !== undefined))
|
|
481
576
|
) {
|
|
482
577
|
fail(path, "must be a new topic name (lowercase), not a built-in one");
|
|
483
578
|
}
|
package/src/conformance/index.ts
CHANGED
|
@@ -120,6 +120,13 @@ export {
|
|
|
120
120
|
// Redirect entry's cases (P068).
|
|
121
121
|
export { entryTests, type EntryConformanceHost, type EntrySuiteOptions } from "./entry.ts";
|
|
122
122
|
|
|
123
|
+
// The capability runtime's cases an app runs against its own handlers (P085-P090): no browser.
|
|
124
|
+
export {
|
|
125
|
+
defineRuntimeConformance,
|
|
126
|
+
type RuntimeCase,
|
|
127
|
+
type RuntimeConformanceOptions,
|
|
128
|
+
} from "./runtime.ts";
|
|
129
|
+
|
|
123
130
|
// The runner an app points at its real page and issue endpoint (P066).
|
|
124
131
|
export {
|
|
125
132
|
conformancePage,
|