@kitionstage/sdk 0.0.0-stage → 0.5.2-stage.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/README.md +69 -2
- package/dist/LICENSE +177 -0
- package/dist/THIRD_PARTY_NOTICES +28 -0
- package/dist/lib/assets/kitEngine.worker-9haDiVHZ.js +13220 -0
- package/dist/lib/chunks/batch-BWpAyHvP.js +789 -0
- package/dist/lib/chunks/canonical-BIWfVCL-.js +87 -0
- package/dist/lib/chunks/envelope-D6MGY-ZN.js +61 -0
- package/dist/lib/chunks/replica-D8w3I4sn.js +2472 -0
- package/dist/lib/chunks/runtime-BVJHE1Pg.js +997 -0
- package/dist/lib/chunks/session-BqXC9a1-.js +281 -0
- package/dist/lib/chunks/toolIds-BCeSGHpV.js +821 -0
- package/dist/lib/chunks/workspaceTree-Destqupf.js +23 -0
- package/dist/lib/convergence/index.js +1035 -0
- package/dist/lib/convergence/node.js +8 -0
- package/dist/lib/embed-server/callbacks.js +37 -0
- package/dist/lib/embed-server/cli.js +19 -0
- package/dist/lib/embed-server/index.js +272 -0
- package/dist/lib/extensions/index.js +439 -0
- package/dist/lib/extensions/panel.html +208 -0
- package/dist/lib/extensions/runtime.js +198 -0
- package/dist/lib/extensions/sandbox.html +35 -0
- package/dist/lib/kdm/index.js +437 -0
- package/dist/lib/kit-dev-host/checkUiIds.mjs +44 -0
- package/dist/lib/kit-dev-host/index.js +308 -0
- package/dist/lib/kit-dev-host/lineRow.mjs +47 -0
- package/dist/lib/kit-dev-host/modeSmoke.mjs +178 -0
- package/dist/lib/kit-editor/index.js +6489 -0
- package/dist/lib/kit-editor/styles.css +807 -0
- package/dist/lib/kit-editor/workspaceTree.js +1 -0
- package/dist/lib/kit-engine/index.js +7 -0
- package/dist/lib/kit-host/index.js +530 -0
- package/dist/lib/kit-ui-protocol/index.js +336 -0
- package/dist/lib/node-only/embed-server-callbacks.js +2 -0
- package/dist/lib/node-only/embed-server.js +2 -0
- package/dist/lib/sync/index.js +1008 -0
- package/dist/lib/sync/openToken.js +201 -0
- package/dist/lib/sync/replicaVersions.js +51 -0
- package/dist/standalone/chunks/batch-CAGYk6m4.js +789 -0
- package/dist/standalone/chunks/client-B9xkOcvf.js +772 -0
- package/dist/standalone/chunks/collab-B5TbpTyO.js +1022 -0
- package/dist/standalone/chunks/comment-Ds9t8xSE.js +94 -0
- package/dist/standalone/chunks/comments-uVDS8Wxp.js +41 -0
- package/dist/standalone/chunks/document-CuIGSDsY.js +324 -0
- package/dist/standalone/chunks/envelope-GX4Cynkx.js +7612 -0
- package/dist/standalone/chunks/index-BEgEEnhU.js +287 -0
- package/dist/standalone/chunks/index-Blc_B6iX.js +1967 -0
- package/dist/standalone/chunks/kits-Cp51mDlw.js +9 -0
- package/dist/standalone/chunks/replica-Di2iCPiD.js +3281 -0
- package/dist/standalone/chunks/replicaVersions-C3rJxnk9.js +50 -0
- package/dist/standalone/chunks/touched-T9jKJjxn.js +78 -0
- package/dist/standalone/index.js +12 -0
- package/dist/standalone/script/index.js +339 -0
- package/dist/standalone/script/kits/board.js +5 -0
- package/dist/standalone/script/kits/cad.js +5 -0
- package/dist/standalone/script/kits/design.js +5 -0
- package/dist/standalone/script/kits/doc.js +5 -0
- package/dist/standalone/script/kits/film.js +5 -0
- package/dist/standalone/script/kits/html.js +5 -0
- package/dist/standalone/script/kits/index.js +38 -0
- package/dist/standalone/script/kits/layout.js +5 -0
- package/dist/standalone/script/kits/motion.js +5 -0
- package/dist/standalone/script/kits/note.js +5 -0
- package/dist/standalone/script/kits/pdf.js +5 -0
- package/dist/standalone/script/kits/photo.js +5 -0
- package/dist/standalone/script/kits/scene.js +5 -0
- package/dist/standalone/script/kits/sheet.js +5 -0
- package/dist/standalone/script/kits/slide.js +5 -0
- package/dist/standalone/script/kits/table.js +5 -0
- package/dist/standalone/script/kits/vector.js +5 -0
- package/dist/standalone/script/node.js +401 -0
- package/dist/standalone/script/proxy.js +254 -0
- package/dist/types/convergence/src/adapter.d.ts +131 -0
- package/dist/types/convergence/src/engine.d.ts +66 -0
- package/dist/types/convergence/src/index.d.ts +21 -0
- package/dist/types/convergence/src/net.d.ts +52 -0
- package/dist/types/convergence/src/node.d.ts +6 -0
- package/dist/types/convergence/src/report.d.ts +56 -0
- package/dist/types/convergence/src/rng.d.ts +12 -0
- package/dist/types/convergence/src/scenarios.d.ts +15 -0
- package/dist/types/convergence/src/state.d.ts +67 -0
- package/dist/types/embed/src/agent.d.ts +88 -0
- package/dist/types/embed/src/blobs.d.ts +2 -0
- package/dist/types/embed/src/collab.d.ts +250 -0
- package/dist/types/embed/src/comments.d.ts +30 -0
- package/dist/types/embed/src/errors.d.ts +24 -0
- package/dist/types/embed/src/handlers.d.ts +92 -0
- package/dist/types/embed/src/index.d.ts +20 -0
- package/dist/types/embed/src/mount.d.ts +39 -0
- package/dist/types/embed/src/replicaStore.d.ts +3 -0
- package/dist/types/embed/src/rooms.d.ts +40 -0
- package/dist/types/embed/src/schemas.d.ts +7 -0
- package/dist/types/embed/src/syncClients.d.ts +28 -0
- package/dist/types/embed/src/theme.d.ts +7 -0
- package/dist/types/embed/src/types.d.ts +596 -0
- package/dist/types/embed/src/ui.d.ts +33 -0
- package/dist/types/embed/src/version.d.ts +2 -0
- package/dist/types/embed-server/src/callbacks.d.ts +30 -0
- package/dist/types/embed-server/src/cli.d.ts +1 -0
- package/dist/types/embed-server/src/index.d.ts +19 -0
- package/dist/types/embed-server/src/page.d.ts +15 -0
- package/dist/types/embed-server/src/server.d.ts +39 -0
- package/dist/types/embed-server/src/session.d.ts +22 -0
- package/dist/types/extensions/src/gate.d.ts +17 -0
- package/dist/types/extensions/src/generated/runtime.d.ts +8 -0
- package/dist/types/extensions/src/host.d.ts +135 -0
- package/dist/types/extensions/src/index.d.ts +13 -0
- package/dist/types/extensions/src/manifest.d.ts +82 -0
- package/dist/types/extensions/src/protocol.d.ts +159 -0
- package/dist/types/extensions/src/rpc.d.ts +52 -0
- package/dist/types/extensions/src/runtime/document.d.ts +40 -0
- package/dist/types/extensions/src/runtime/index.d.ts +10 -0
- package/dist/types/extensions/src/runtime/panel.d.ts +19 -0
- package/dist/types/extensions/src/runtime/runtime.d.ts +54 -0
- package/dist/types/extensions/src/runtime/worker.d.ts +1 -0
- package/dist/types/extensions/src/sandbox.d.ts +41 -0
- package/dist/types/kdm/src/args.d.ts +12 -0
- package/dist/types/kdm/src/batch.d.ts +118 -0
- package/dist/types/kdm/src/canonical.d.ts +25 -0
- package/dist/types/kdm/src/comment.d.ts +114 -0
- package/dist/types/kdm/src/diff.d.ts +125 -0
- package/dist/types/kdm/src/envelope.d.ts +27 -0
- package/dist/types/kdm/src/errors.d.ts +28 -0
- package/dist/types/kdm/src/footprint.d.ts +21 -0
- package/dist/types/kdm/src/ids.d.ts +57 -0
- package/dist/types/kdm/src/index.d.ts +18 -0
- package/dist/types/kdm/src/marks.d.ts +32 -0
- package/dist/types/kdm/src/op.d.ts +124 -0
- package/dist/types/kdm/src/origin.d.ts +41 -0
- package/dist/types/kdm/src/overlay.d.ts +92 -0
- package/dist/types/kdm/src/projection.d.ts +29 -0
- package/dist/types/kdm/src/read.d.ts +90 -0
- package/dist/types/kdm/src/replica.d.ts +403 -0
- package/dist/types/kdm/src/schema.d.ts +185 -0
- package/dist/types/kdm/src/testing.d.ts +28 -0
- package/dist/types/kdm/src/toolIds.d.ts +61 -0
- package/dist/types/kdm/src/touched.d.ts +24 -0
- package/dist/types/kdm/src/tx.d.ts +215 -0
- package/dist/types/kdm/src/value.d.ts +23 -0
- package/dist/types/kit-dev-host/src/checkNoPaths.d.ts +19 -0
- package/dist/types/kit-dev-host/src/checkUiIds.d.mts +2 -0
- package/dist/types/kit-dev-host/src/index.d.ts +179 -0
- package/dist/types/kit-dev-host/src/lineRow.d.mts +14 -0
- package/dist/types/kit-dev-host/src/memoryFiles.d.ts +15 -0
- package/dist/types/kit-dev-host/src/modeSmoke.d.mts +8 -0
- package/dist/types/kit-editor/src/CommandDialog.d.ts +22 -0
- package/dist/types/kit-editor/src/CommentsPanel.d.ts +45 -0
- package/dist/types/kit-editor/src/CustomizeDialog.d.ts +32 -0
- package/dist/types/kit-editor/src/HostButtons.d.ts +11 -0
- package/dist/types/kit-editor/src/RenderFailure.d.ts +7 -0
- package/dist/types/kit-editor/src/TextSink.d.ts +6 -0
- package/dist/types/kit-editor/src/brand.d.ts +2 -0
- package/dist/types/kit-editor/src/catalogMenus.d.ts +27 -0
- package/dist/types/kit-editor/src/chart.d.ts +138 -0
- package/dist/types/kit-editor/src/conflicts.d.ts +12 -0
- package/dist/types/kit-editor/src/drawing.d.ts +83 -0
- package/dist/types/kit-editor/src/editor.d.ts +544 -0
- package/dist/types/kit-editor/src/engine/KitCanvas.d.ts +70 -0
- package/dist/types/kit-editor/src/engine/backdrop.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/createKitFile.d.ts +12 -0
- package/dist/types/kit-editor/src/engine/decorations.d.ts +14 -0
- package/dist/types/kit-editor/src/engine/engineOverlays.d.ts +197 -0
- package/dist/types/kit-editor/src/engine/engineTools.d.ts +116 -0
- package/dist/types/kit-editor/src/engine/kitDraft.d.ts +70 -0
- package/dist/types/kit-editor/src/engine/kitEngine.d.ts +390 -0
- package/dist/types/kit-editor/src/engine/kitEngine.worker.d.ts +30 -0
- package/dist/types/kit-editor/src/engine/kitHost.d.ts +41 -0
- package/dist/types/kit-editor/src/engine/kitModel.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/kitModelRunner.d.ts +99 -0
- package/dist/types/kit-editor/src/engine/kitModule.d.ts +185 -0
- package/dist/types/kit-editor/src/engine/kitShortcuts.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/kitTools.d.ts +79 -0
- package/dist/types/kit-editor/src/engine/lazyFonts.d.ts +34 -0
- package/dist/types/kit-editor/src/engine/lentFiles.d.ts +29 -0
- package/dist/types/kit-editor/src/engine/rasterViewport.d.ts +178 -0
- package/dist/types/kit-editor/src/engine/readOnly.d.ts +78 -0
- package/dist/types/kit-editor/src/engine/refusal.d.ts +39 -0
- package/dist/types/kit-editor/src/engine/replica.d.ts +23 -0
- package/dist/types/kit-editor/src/engine/useKitDocument.d.ts +154 -0
- package/dist/types/kit-editor/src/engine/workerRelay.d.ts +62 -0
- package/dist/types/kit-editor/src/files.d.ts +74 -0
- package/dist/types/kit-editor/src/frame/EditorFrame.d.ts +74 -0
- package/dist/types/kit-editor/src/frame/FocusBar.d.ts +10 -0
- package/dist/types/kit-editor/src/frame/MenuNodes.d.ts +20 -0
- package/dist/types/kit-editor/src/frame/MenuRibbon.d.ts +8 -0
- package/dist/types/kit-editor/src/frame/ModeButton.d.ts +7 -0
- package/dist/types/kit-editor/src/frame/menus.d.ts +64 -0
- package/dist/types/kit-editor/src/frame/modes.d.ts +51 -0
- package/dist/types/kit-editor/src/frame/useFrameLayout.d.ts +34 -0
- package/dist/types/kit-editor/src/host.d.ts +127 -0
- package/dist/types/kit-editor/src/index.d.ts +85 -0
- package/dist/types/kit-editor/src/ink.d.ts +26 -0
- package/dist/types/kit-editor/src/lease.d.ts +53 -0
- package/dist/types/kit-editor/src/oneInFlight.d.ts +7 -0
- package/dist/types/kit-editor/src/phrases.d.ts +25 -0
- package/dist/types/kit-editor/src/presence.d.ts +79 -0
- package/dist/types/kit-editor/src/strings.d.ts +6 -0
- package/dist/types/kit-editor/src/toolIcons.d.ts +32 -0
- package/dist/types/kit-editor/src/uiCatalog.d.ts +59 -0
- package/dist/types/kit-editor/src/uiConfig.d.ts +53 -0
- package/dist/types/kit-editor/src/uiContext.d.ts +65 -0
- package/dist/types/kit-editor/src/uiStore.d.ts +20 -0
- package/dist/types/kit-editor/src/useCommentAnchors.d.ts +29 -0
- package/dist/types/kit-editor/src/useKitSession.d.ts +115 -0
- package/dist/types/kit-editor/src/workspaceTree.d.ts +5 -0
- package/dist/types/kit-engine/src/contract.d.ts +154 -0
- package/dist/types/kit-engine/src/index.d.ts +2 -0
- package/dist/types/kit-engine/src/session.d.ts +133 -0
- package/dist/types/kit-host/src/files.d.ts +163 -0
- package/dist/types/kit-host/src/index.d.ts +315 -0
- package/dist/types/kit-ui-protocol/src/index.d.ts +1145 -0
- package/dist/types/loro-crdt.d.ts +9 -0
- package/dist/types/script/kits/board.d.ts +534 -0
- package/dist/types/script/kits/cad.d.ts +2937 -0
- package/dist/types/script/kits/design.d.ts +3213 -0
- package/dist/types/script/kits/doc.d.ts +2575 -0
- package/dist/types/script/kits/film.d.ts +4067 -0
- package/dist/types/script/kits/html.d.ts +38 -0
- package/dist/types/script/kits/index.d.ts +20 -0
- package/dist/types/script/kits/layout.d.ts +3483 -0
- package/dist/types/script/kits/motion.d.ts +4826 -0
- package/dist/types/script/kits/note.d.ts +631 -0
- package/dist/types/script/kits/pdf.d.ts +829 -0
- package/dist/types/script/kits/photo.d.ts +7574 -0
- package/dist/types/script/kits/scene.d.ts +2962 -0
- package/dist/types/script/kits/sheet.d.ts +2419 -0
- package/dist/types/script/kits/slide.d.ts +1894 -0
- package/dist/types/script/kits/table.d.ts +654 -0
- package/dist/types/script/kits/vector.d.ts +5167 -0
- package/dist/types/script/src/agentRelay.d.ts +48 -0
- package/dist/types/script/src/capabilities.d.ts +21 -0
- package/dist/types/script/src/document.d.ts +87 -0
- package/dist/types/script/src/drafts.d.ts +141 -0
- package/dist/types/script/src/exchange.d.ts +30 -0
- package/dist/types/script/src/headless.d.ts +190 -0
- package/dist/types/script/src/index.d.ts +15 -0
- package/dist/types/script/src/kitModel.d.ts +17 -0
- package/dist/types/script/src/kits.d.ts +8 -0
- package/dist/types/script/src/node.d.ts +42 -0
- package/dist/types/script/src/port.d.ts +89 -0
- package/dist/types/script/src/proxy.d.ts +132 -0
- package/dist/types/script/src/room.d.ts +162 -0
- package/dist/types/script/src/sources.d.ts +73 -0
- package/dist/types/sync/src/backoff.d.ts +9 -0
- package/dist/types/sync/src/blobSection.d.ts +23 -0
- package/dist/types/sync/src/capabilities.d.ts +20 -0
- package/dist/types/sync/src/client.d.ts +253 -0
- package/dist/types/sync/src/framing.d.ts +35 -0
- package/dist/types/sync/src/hash.d.ts +2 -0
- package/dist/types/sync/src/index.d.ts +19 -0
- package/dist/types/sync/src/leases.d.ts +82 -0
- package/dist/types/sync/src/openToken.d.ts +104 -0
- package/dist/types/sync/src/protocol.d.ts +484 -0
- package/dist/types/sync/src/relay.d.ts +52 -0
- package/dist/types/sync/src/replicaVersions.d.ts +17 -0
- package/dist/types/sync/src/saveMachine.d.ts +83 -0
- package/dist/types/sync/src/saveRun.d.ts +52 -0
- package/dist/types/sync/src/transport.d.ts +19 -0
- package/package.json +229 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type EmbedServerConfig } from './server.js';
|
|
2
|
+
export { createEmbedServer, type EmbedServerConfig, type Integrator, type KitRoute } from './server.js';
|
|
3
|
+
export { callbackHeaders, signCallback, verifyCallback, CALLBACK_SKEW_SECS } from './callbacks.js';
|
|
4
|
+
export { makeSession, readSession, type Session } from './session.js';
|
|
5
|
+
/**
|
|
6
|
+
* Listens on `port` (0: any free one). With `kitsDir`, also serves the kit packages there on
|
|
7
|
+
* `kitsPort`, another origin, and `kitsUrl` defaults to it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function startEmbedServer(config: Omit<EmbedServerConfig, 'kitsUrl'> & {
|
|
10
|
+
kitsUrl?: string;
|
|
11
|
+
port?: number;
|
|
12
|
+
host?: string;
|
|
13
|
+
kitsDir?: string;
|
|
14
|
+
kitsPort?: number;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
url: string;
|
|
17
|
+
kitsUrl: string;
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The editor page the service answers `GET /v1/open` with: `@kition/embed` mounting the kit for the
|
|
3
|
+
* session's file, its storage provider the service's own `/v1/file` and `/v1/replica`, with the
|
|
4
|
+
* session as the bearer. Nothing in it is trusted by the service: every call is checked again.
|
|
5
|
+
*/
|
|
6
|
+
import type { Session } from './session.js';
|
|
7
|
+
export type PageOptions = {
|
|
8
|
+
session: string;
|
|
9
|
+
claims: Session;
|
|
10
|
+
kitUrl: string;
|
|
11
|
+
embedModule: string;
|
|
12
|
+
nonce: string;
|
|
13
|
+
title: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function editorPage({ session, claims, kitUrl, embedModule, nonce, title }: PageOptions): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { type OpenTokenKey } from '../../sync/src/openToken.js';
|
|
3
|
+
export type Integrator = {
|
|
4
|
+
/** The issuer its open tokens name (`iss`). */
|
|
5
|
+
iss: string;
|
|
6
|
+
/** Its keys: each bound to its tenant and to `iss`. */
|
|
7
|
+
keys: OpenTokenKey[];
|
|
8
|
+
/** Where its callbacks are (`{callbackUrl}/files/{file}`). */
|
|
9
|
+
callbackUrl: string;
|
|
10
|
+
/** The secret callbacks are signed with (shared with the integrator). */
|
|
11
|
+
secret: string;
|
|
12
|
+
/** Origins allowed to frame the editor (`frame-ancestors`). */
|
|
13
|
+
origins: string[];
|
|
14
|
+
};
|
|
15
|
+
export type KitRoute = {
|
|
16
|
+
id: string;
|
|
17
|
+
path: string;
|
|
18
|
+
extensions: string[];
|
|
19
|
+
};
|
|
20
|
+
export type EmbedServerConfig = {
|
|
21
|
+
/** The service's id: the `aud` its open tokens name. */
|
|
22
|
+
id: string;
|
|
23
|
+
/** Signs sessions; at least 32 characters, never shared. */
|
|
24
|
+
secret: string;
|
|
25
|
+
integrators: Integrator[];
|
|
26
|
+
/** Which kit opens which files, by name extension; `path` is the kit package under `kitsUrl`. */
|
|
27
|
+
kits: KitRoute[];
|
|
28
|
+
/** Where kit packages are served: another origin than the service's (EM4). */
|
|
29
|
+
kitsUrl: string;
|
|
30
|
+
/** `@kition/embed`'s built module directory (its `dist`); default: the installed `@kition/embed`'s. */
|
|
31
|
+
embedDir?: string;
|
|
32
|
+
/** A session's life, seconds (default 8 hours). */
|
|
33
|
+
sessionTtl?: number;
|
|
34
|
+
/** The largest document or replica a page may write, bytes (default 256 MiB). */
|
|
35
|
+
maxBytes?: number;
|
|
36
|
+
fetch?: typeof fetch;
|
|
37
|
+
now?: () => number;
|
|
38
|
+
};
|
|
39
|
+
export declare function createEmbedServer(config: EmbedServerConfig): (request: IncomingMessage, response: ServerResponse) => Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OpenPerms } from '../../sync/src/openToken.js';
|
|
2
|
+
export type Session = {
|
|
3
|
+
/** The integrator (`iss`) and its tenant. */
|
|
4
|
+
iss: string;
|
|
5
|
+
tenant: string;
|
|
6
|
+
sub: string;
|
|
7
|
+
name: string;
|
|
8
|
+
file: string;
|
|
9
|
+
version: string;
|
|
10
|
+
docKey: string;
|
|
11
|
+
perms: OpenPerms;
|
|
12
|
+
watermark: {
|
|
13
|
+
text: string;
|
|
14
|
+
} | null;
|
|
15
|
+
/** The kit the page opens. */
|
|
16
|
+
kit: string;
|
|
17
|
+
/** Unix seconds. */
|
|
18
|
+
exp: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function makeSession(secret: string, session: Session): string;
|
|
21
|
+
/** The session `token` names, or `null` when it is not one of ours, was changed, or expired. */
|
|
22
|
+
export declare function readSession(secret: string, token: string | null | undefined, now?: number): Session | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each object-model call needs (`KitExtensions 1.0` permissions). The host checks every
|
|
3
|
+
* call from an extension's worker here before it reaches the document.
|
|
4
|
+
*/
|
|
5
|
+
import type { BatchRequest } from '../../kdm/src/index.js';
|
|
6
|
+
import type { KitCommandInfo } from '../../script/src/index.js';
|
|
7
|
+
import { type Permission } from './manifest.js';
|
|
8
|
+
import { ExtensionError } from './rpc.js';
|
|
9
|
+
export declare function permissionDenied(extension: string, permission: Permission, what: string): ExtensionError;
|
|
10
|
+
export declare function requirePermission(extension: string, permissions: readonly string[], permission: Permission, what: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Checks a `model/batch` against `permissions`. Loads need `model.read`; every operation but a
|
|
13
|
+
* command needs `model.write`; a command needs `commands.run`, and `model.write` too unless the
|
|
14
|
+
* kit's catalogue says it does not mutate (`catalogue` answers it; only asked for when the batch
|
|
15
|
+
* has commands).
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkBatch(extension: string, permissions: readonly string[], request: BatchRequest, catalogue: () => Promise<KitCommandInfo[]>): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A hash of the sources this module was built from (scripts/runtime-inputs.mjs). */
|
|
2
|
+
export declare const RUNTIME_INPUTS_SHA256 = "3071d6975d6f0993907c0a6ea5c8bc97769cd3b4bba46377ebfd63b1404baf6c";
|
|
3
|
+
/** The sandbox worker: one classic script (src/runtime/worker.ts and what it imports). */
|
|
4
|
+
export declare const WORKER_RUNTIME: string;
|
|
5
|
+
/** The sandbox page (sandbox/sandbox.html), for hosts that serve it from memory. */
|
|
6
|
+
export declare const SANDBOX_HTML: string;
|
|
7
|
+
/** The panel page (sandbox/panel.html), for hosts that serve it from memory. */
|
|
8
|
+
export declare const PANEL_HTML: string;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { type ModelPort } from '../../script/src/index.js';
|
|
2
|
+
import '../../script/kits/index.js';
|
|
3
|
+
import { type ExtensionCommand, type ExtensionManifest, type ExtensionPanel, type Permission } from './manifest.js';
|
|
4
|
+
import type { Notice } from './protocol.js';
|
|
5
|
+
import { type PortLike } from './rpc.js';
|
|
6
|
+
/**
|
|
7
|
+
* An installed extension: its manifest, its entry module's source, and its other files as text
|
|
8
|
+
* by package path (each panel's HTML entry).
|
|
9
|
+
*/
|
|
10
|
+
export type ExtensionPackage = {
|
|
11
|
+
manifest: ExtensionManifest | unknown;
|
|
12
|
+
source: string;
|
|
13
|
+
files?: Record<string, string>;
|
|
14
|
+
};
|
|
15
|
+
/** A started sandbox: the channel to its worker, and how to tear it down. */
|
|
16
|
+
export type SandboxConnection = {
|
|
17
|
+
port: PortLike;
|
|
18
|
+
dispose: () => void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Starts a sandbox for one extension: a worker on an opaque origin that runs `runtime` and may
|
|
22
|
+
* reach only `connect` (a CSP `connect-src` value). `iframeSandbox` is the one for pages.
|
|
23
|
+
*/
|
|
24
|
+
export type SandboxFactory = (options: {
|
|
25
|
+
id: string;
|
|
26
|
+
connect: string;
|
|
27
|
+
}) => Promise<SandboxConnection>;
|
|
28
|
+
/** A document open in the host that extensions may work on. */
|
|
29
|
+
export type HostDocument = {
|
|
30
|
+
/** The host's id for it (Kition: its workspace path). */
|
|
31
|
+
id: string;
|
|
32
|
+
kitId: string;
|
|
33
|
+
/** Its path or file name; `activation.formats` match its extension. */
|
|
34
|
+
path?: string;
|
|
35
|
+
/** The document's object model port (`portFromConnection`, `portFromEngine`, …). */
|
|
36
|
+
port: ModelPort;
|
|
37
|
+
/** The kit's schema when the kit is not registered with `@kition/script` (`registerKit`). */
|
|
38
|
+
schema?: object;
|
|
39
|
+
};
|
|
40
|
+
export type ExtensionNotice = Notice & {
|
|
41
|
+
extension: string;
|
|
42
|
+
};
|
|
43
|
+
export type ExtensionHostOptions = {
|
|
44
|
+
sandbox: SandboxFactory;
|
|
45
|
+
/** The kit's schema for documents that bring none; `@kition/script`'s registered kits otherwise. */
|
|
46
|
+
schema?: (kitId: string) => object | undefined;
|
|
47
|
+
/** `ctx.notify` of extensions, and the host's reports of their failures. */
|
|
48
|
+
notify?: (notice: ExtensionNotice) => void;
|
|
49
|
+
/** How long a sandbox may take to start an extension (ms). */
|
|
50
|
+
startTimeoutMs?: number;
|
|
51
|
+
};
|
|
52
|
+
/** A contributed command as a host lists it (palette, menus). */
|
|
53
|
+
export type ContributedCommand = ExtensionCommand & {
|
|
54
|
+
extension: string;
|
|
55
|
+
extensionName: string;
|
|
56
|
+
};
|
|
57
|
+
/** A contributed panel as a host lists it. */
|
|
58
|
+
export type ContributedPanel = ExtensionPanel & {
|
|
59
|
+
extension: string;
|
|
60
|
+
extensionName: string;
|
|
61
|
+
};
|
|
62
|
+
/** What a host needs to show a panel: its HTML and its `connect-src` (the extension's). */
|
|
63
|
+
export type PanelContent = {
|
|
64
|
+
html: string;
|
|
65
|
+
connect: string;
|
|
66
|
+
title: string;
|
|
67
|
+
};
|
|
68
|
+
/** A panel open on a document; `close` ends it in the extension's worker. */
|
|
69
|
+
export type PanelSession = {
|
|
70
|
+
session: string;
|
|
71
|
+
close: () => void;
|
|
72
|
+
};
|
|
73
|
+
/** The permissions of a script run with `runScript`. */
|
|
74
|
+
export declare const SCRIPT_PERMISSIONS: Permission[];
|
|
75
|
+
type Activation = {
|
|
76
|
+
commands: Set<string>;
|
|
77
|
+
unsubscribe: () => void;
|
|
78
|
+
};
|
|
79
|
+
export declare class ExtensionHost {
|
|
80
|
+
private readonly options;
|
|
81
|
+
private loaded;
|
|
82
|
+
private documents;
|
|
83
|
+
private scripts;
|
|
84
|
+
private panelSessions;
|
|
85
|
+
constructor(options: ExtensionHostOptions);
|
|
86
|
+
/** Checks and loads an extension (its code runs when it is first activated); replaces one with its id. */
|
|
87
|
+
load(pkg: ExtensionPackage): ExtensionManifest;
|
|
88
|
+
/** Deactivates an extension everywhere and stops its sandbox. */
|
|
89
|
+
unload(id: string): void;
|
|
90
|
+
extensions(): ExtensionManifest[];
|
|
91
|
+
/** Offers a document to extensions; those that activate on open do. Answers `closeDocument`. */
|
|
92
|
+
openDocument(document: HostDocument): () => void;
|
|
93
|
+
/** Deactivates every extension on the document. */
|
|
94
|
+
closeDocument(id: string): void;
|
|
95
|
+
/** The commands loaded extensions contribute to a document, in load order. */
|
|
96
|
+
commandsFor(documentId: string): ContributedCommand[];
|
|
97
|
+
/** The panels loaded extensions contribute to a document, in load order. */
|
|
98
|
+
panelsFor(documentId: string): ContributedPanel[];
|
|
99
|
+
/** A contributed panel's HTML and the network origins its frame may reach (the extension's). */
|
|
100
|
+
panelContent(extensionId: string, panelId: string): PanelContent;
|
|
101
|
+
/**
|
|
102
|
+
* Opens a contributed panel on a document: activates the extension there first when needed, then
|
|
103
|
+
* hands its worker `port`, the worker's end of the panel's channel (the panel's frame gets the
|
|
104
|
+
* other end). Answers the session; closing the document or the extension closes it too.
|
|
105
|
+
*/
|
|
106
|
+
openPanel(documentId: string, extensionId: string, panelId: string, port: MessagePort): Promise<PanelSession>;
|
|
107
|
+
/** Runs a contributed command on a document, activating its extension first when needed. */
|
|
108
|
+
runCommand(documentId: string, extensionId: string, commandId: string): Promise<unknown>;
|
|
109
|
+
/** Activates an extension on a document (once); answers when its `activate` has returned. */
|
|
110
|
+
activate(extensionId: string, documentId: string): Promise<Activation>;
|
|
111
|
+
/**
|
|
112
|
+
* Runs a script (an ES module whose default export, or `run`, takes the same `ctx` as
|
|
113
|
+
* `activate`) once against a document, in a sandbox of its own with `permissions`. Answers what
|
|
114
|
+
* it answers.
|
|
115
|
+
*/
|
|
116
|
+
runScript(script: {
|
|
117
|
+
source: string;
|
|
118
|
+
name?: string;
|
|
119
|
+
}, documentId: string, permissions?: Permission[]): Promise<unknown>;
|
|
120
|
+
/** Stops every sandbox and forgets every document. */
|
|
121
|
+
dispose(): void;
|
|
122
|
+
private require;
|
|
123
|
+
private info;
|
|
124
|
+
private activateReporting;
|
|
125
|
+
private report;
|
|
126
|
+
/** The document's object model, opened once and shared by every extension on it. */
|
|
127
|
+
private model;
|
|
128
|
+
/** The sandbox of an extension, started once. */
|
|
129
|
+
private start;
|
|
130
|
+
private stop;
|
|
131
|
+
private deactivate;
|
|
132
|
+
/** What the extension's worker may ask of the host. */
|
|
133
|
+
private serve;
|
|
134
|
+
}
|
|
135
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@kition/extensions`: the extension host (`KitExtensions 1.0`). A host loads extensions
|
|
3
|
+
* (`extension.json` + one ES module), runs each in a sandboxed worker on an opaque origin with only
|
|
4
|
+
* its declared network origins, and serves it the object model (`@kition/script`) of the documents it
|
|
5
|
+
* is active on, checked against its permissions. Extension authors: see `@kition/extensions/runtime`
|
|
6
|
+
* for `activate(ctx)`'s types.
|
|
7
|
+
*/
|
|
8
|
+
export { checkBatch, permissionDenied, requirePermission } from './gate.js';
|
|
9
|
+
export { ExtensionHost, SCRIPT_PERMISSIONS, type ContributedCommand, type ContributedPanel, type PanelContent, type PanelSession, type ExtensionHostOptions, type ExtensionNotice, type ExtensionPackage, type HostDocument, type SandboxConnection, type SandboxFactory } from './host.js';
|
|
10
|
+
export { appliesTo, connectSources, hasPermission, KIT_EXTENSIONS_CAPABILITY, MANIFEST_VERSION, ManifestError, networkSources, panelAppliesTo, parseManifest, type ExtensionActivation, type ExtensionCommand, type ExtensionManifest, type ExtensionPanel, type Permission, } from './manifest.js';
|
|
11
|
+
export { PANEL_TAG, SANDBOX_TAG, type DocumentInfo, type HostToWorker, type Notice, type PanelChannel, type PanelInfo, type PanelStart, type SandboxStart, type WorkerToHost } from './protocol.js';
|
|
12
|
+
export { CHANNEL_TAG, ExtensionError, RpcPeer, type PortLike } from './rpc.js';
|
|
13
|
+
export { iframeSandbox, openPanelFrame, type IframeSandboxOptions, type PanelFrame, type PanelFrameOptions } from './sandbox.js';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `extension.json` (`KitExtensions 1.0`): what an extension is, which documents it applies to,
|
|
3
|
+
* what it adds, and what it may do. Everything here is checked before any of its code runs.
|
|
4
|
+
*/
|
|
5
|
+
export declare const KIT_EXTENSIONS_CAPABILITY = "KitExtensions 1.0";
|
|
6
|
+
/** The manifest version this host reads. */
|
|
7
|
+
export declare const MANIFEST_VERSION = "1.0";
|
|
8
|
+
/**
|
|
9
|
+
* - `model.read`: read the document (`load`, `describe`, the command catalogue).
|
|
10
|
+
* - `model.write`: change it (every write operation; a mutating command also needs it).
|
|
11
|
+
* - `commands.run`: run the kit's commands.
|
|
12
|
+
* - `network:<origin>`: reach that origin (`fetch`, WebSocket, …); nothing else is reachable.
|
|
13
|
+
*/
|
|
14
|
+
export type Permission = 'model.read' | 'model.write' | 'commands.run' | `network:${string}`;
|
|
15
|
+
export type ExtensionCommand = {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A panel the extension draws next to the kit's editor: one self-contained HTML file of the
|
|
22
|
+
* package (`entry`), shown in a sandboxed frame that talks to the extension's worker. `kits`
|
|
23
|
+
* narrows the documents it is offered for to some of `activation.kits`.
|
|
24
|
+
*/
|
|
25
|
+
export type ExtensionPanel = {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
entry: string;
|
|
29
|
+
kits?: string[];
|
|
30
|
+
};
|
|
31
|
+
export type ExtensionActivation = {
|
|
32
|
+
/** The kits the extension applies to (`kit.slide`, …). */
|
|
33
|
+
kits: string[];
|
|
34
|
+
/** File extensions (no dot) that narrow `kits`; every file of those kits when absent. */
|
|
35
|
+
formats?: string[];
|
|
36
|
+
/** `open`: activate when a matching document opens; `command` (default): on its first command. */
|
|
37
|
+
on?: 'open' | 'command';
|
|
38
|
+
};
|
|
39
|
+
export type ExtensionManifest = {
|
|
40
|
+
kitExtensions: typeof MANIFEST_VERSION;
|
|
41
|
+
/** Reverse domain name, lower case: `com.example.title-case`. */
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
/** Semantic version. */
|
|
45
|
+
version: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
publisher?: string;
|
|
48
|
+
/** The ES module, relative to the package: one self-contained file (no relative imports). */
|
|
49
|
+
entry: string;
|
|
50
|
+
activation: ExtensionActivation;
|
|
51
|
+
contributes: {
|
|
52
|
+
commands: ExtensionCommand[];
|
|
53
|
+
panels?: ExtensionPanel[];
|
|
54
|
+
};
|
|
55
|
+
permissions: Permission[];
|
|
56
|
+
};
|
|
57
|
+
/** A manifest this host refuses, with every problem found. */
|
|
58
|
+
export declare class ManifestError extends Error {
|
|
59
|
+
readonly problems: string[];
|
|
60
|
+
constructor(problems: string[]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The origins a `network:` permission names, as CSP sources: `network:api.example.com` is
|
|
64
|
+
* `https://api.example.com` and `wss://api.example.com`; a scheme may be given (`https`, `wss`,
|
|
65
|
+
* or `http`/`ws` for loopback only), and a port. Answers `null` when it is not one.
|
|
66
|
+
*/
|
|
67
|
+
export declare function networkSources(permission: string): string[] | null;
|
|
68
|
+
/** The CSP `connect-src` value for `permissions`: their declared origins, or `'none'`. */
|
|
69
|
+
export declare function connectSources(permissions: readonly string[]): string;
|
|
70
|
+
export declare const hasPermission: (permissions: readonly string[], permission: Permission) => boolean;
|
|
71
|
+
/** Reads and checks an `extension.json` (text or parsed); throws `ManifestError` with every problem. */
|
|
72
|
+
export declare function parseManifest(input: unknown): ExtensionManifest;
|
|
73
|
+
/** Whether `manifest` applies to a document of `kitId` at `path`. */
|
|
74
|
+
export declare function appliesTo(manifest: ExtensionManifest, document: {
|
|
75
|
+
kitId: string;
|
|
76
|
+
path?: string;
|
|
77
|
+
}): boolean;
|
|
78
|
+
/** Whether `panel` of `manifest` is offered for a document of `kitId` at `path`. */
|
|
79
|
+
export declare function panelAppliesTo(manifest: ExtensionManifest, panel: ExtensionPanel, document: {
|
|
80
|
+
kitId: string;
|
|
81
|
+
path?: string;
|
|
82
|
+
}): boolean;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The methods between the host and an extension's worker (`KitExtensions 1.0`). The host starts
|
|
3
|
+
* the extension, activates it per document, and runs its commands; the worker reads and edits the
|
|
4
|
+
* documents it is active on through the host, which checks every call against its permissions.
|
|
5
|
+
*/
|
|
6
|
+
import type { BatchRequest, BatchResult } from '../../kdm/src/index.js';
|
|
7
|
+
import type { KitCommandInfo } from '../../script/src/index.js';
|
|
8
|
+
import type { ExtensionManifest } from './manifest.js';
|
|
9
|
+
/** The message the host posts to the sandbox page with the channel's port (see `sandbox/`). */
|
|
10
|
+
export declare const SANDBOX_TAG = "kition-ext-sandbox/1";
|
|
11
|
+
export type SandboxStart = {
|
|
12
|
+
tag: typeof SANDBOX_TAG;
|
|
13
|
+
type: 'start';
|
|
14
|
+
runtime: string;
|
|
15
|
+
connect: string;
|
|
16
|
+
};
|
|
17
|
+
/** The message the host posts to a panel page (`sandbox/panel.html`) with the panel's port. */
|
|
18
|
+
export declare const PANEL_TAG = "kition-ext-panel/1";
|
|
19
|
+
export type PanelStart = {
|
|
20
|
+
tag: typeof PANEL_TAG;
|
|
21
|
+
type: 'start';
|
|
22
|
+
/** The panel's HTML (its entry file). */
|
|
23
|
+
html: string;
|
|
24
|
+
/** Its CSP `connect-src`: the extension's `network:` origins, or `'none'`. */
|
|
25
|
+
connect: string;
|
|
26
|
+
/** CSS custom properties for the panel's root (the host's theme), as `--name: value`. */
|
|
27
|
+
theme?: Record<string, string>;
|
|
28
|
+
info: PanelInfo;
|
|
29
|
+
};
|
|
30
|
+
/** What a panel knows of itself (`kitionPanel.info` in the panel). */
|
|
31
|
+
export type PanelInfo = {
|
|
32
|
+
extension: string;
|
|
33
|
+
panel: string;
|
|
34
|
+
documentId: string;
|
|
35
|
+
title: string;
|
|
36
|
+
locale?: string;
|
|
37
|
+
};
|
|
38
|
+
export type DocumentInfo = {
|
|
39
|
+
documentId: string;
|
|
40
|
+
kitId: string;
|
|
41
|
+
/** The document's file name in the host (no folders), when it has one. */
|
|
42
|
+
name?: string;
|
|
43
|
+
/** The kit's KDM schema: the proxies need it. */
|
|
44
|
+
schema: object;
|
|
45
|
+
/** Whether writes are refused: the document is read-only, or the extension may not write. */
|
|
46
|
+
readOnly: boolean;
|
|
47
|
+
};
|
|
48
|
+
/** Host to worker. */
|
|
49
|
+
export type HostToWorker = {
|
|
50
|
+
/** Loads the extension's module (`kind: script` for a script run once). */
|
|
51
|
+
'extension/start': {
|
|
52
|
+
params: {
|
|
53
|
+
manifest: ExtensionManifest;
|
|
54
|
+
source: string;
|
|
55
|
+
kind?: 'extension' | 'script';
|
|
56
|
+
};
|
|
57
|
+
result: null;
|
|
58
|
+
};
|
|
59
|
+
/** Calls `activate(ctx)` for one document; answers the commands it registered. */
|
|
60
|
+
'extension/activate': {
|
|
61
|
+
params: DocumentInfo;
|
|
62
|
+
result: {
|
|
63
|
+
commands: string[];
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
'extension/command': {
|
|
67
|
+
params: {
|
|
68
|
+
documentId: string;
|
|
69
|
+
command: string;
|
|
70
|
+
};
|
|
71
|
+
result: unknown;
|
|
72
|
+
};
|
|
73
|
+
'extension/deactivate': {
|
|
74
|
+
params: {
|
|
75
|
+
documentId: string;
|
|
76
|
+
};
|
|
77
|
+
result: null;
|
|
78
|
+
};
|
|
79
|
+
/** A script's default export, run once against the document. */
|
|
80
|
+
'script/run': {
|
|
81
|
+
params: DocumentInfo;
|
|
82
|
+
result: unknown;
|
|
83
|
+
};
|
|
84
|
+
/** Notification: the document changed (`local`: the extension's own batch). */
|
|
85
|
+
'document/changed': {
|
|
86
|
+
params: {
|
|
87
|
+
documentId: string;
|
|
88
|
+
origin: 'local' | 'kit';
|
|
89
|
+
};
|
|
90
|
+
result: never;
|
|
91
|
+
};
|
|
92
|
+
/** A panel opened on a document: its `MessagePort` comes with the request (`session` names it). */
|
|
93
|
+
'panel/open': {
|
|
94
|
+
params: {
|
|
95
|
+
documentId: string;
|
|
96
|
+
panel: string;
|
|
97
|
+
session: string;
|
|
98
|
+
};
|
|
99
|
+
result: null;
|
|
100
|
+
};
|
|
101
|
+
'panel/close': {
|
|
102
|
+
params: {
|
|
103
|
+
session: string;
|
|
104
|
+
};
|
|
105
|
+
result: null;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
/** Between a panel and the extension's worker, over the panel's own channel. */
|
|
109
|
+
export type PanelChannel = {
|
|
110
|
+
/** Panel to worker: what the panel asks; the worker's `onRequest` handler answers. */
|
|
111
|
+
'panel/request': {
|
|
112
|
+
params: unknown;
|
|
113
|
+
result: unknown;
|
|
114
|
+
};
|
|
115
|
+
/** Notification, worker to panel: `panel.post(message)`. */
|
|
116
|
+
'panel/message': {
|
|
117
|
+
params: unknown;
|
|
118
|
+
result: never;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
/** Worker to host. */
|
|
122
|
+
export type WorkerToHost = {
|
|
123
|
+
'model/batch': {
|
|
124
|
+
params: {
|
|
125
|
+
documentId: string;
|
|
126
|
+
request: BatchRequest;
|
|
127
|
+
};
|
|
128
|
+
result: BatchResult;
|
|
129
|
+
};
|
|
130
|
+
'model/describe': {
|
|
131
|
+
params: {
|
|
132
|
+
documentId: string;
|
|
133
|
+
};
|
|
134
|
+
result: Record<string, unknown>;
|
|
135
|
+
};
|
|
136
|
+
'model/commands': {
|
|
137
|
+
params: {
|
|
138
|
+
documentId: string;
|
|
139
|
+
};
|
|
140
|
+
result: KitCommandInfo[];
|
|
141
|
+
};
|
|
142
|
+
'commands/register': {
|
|
143
|
+
params: {
|
|
144
|
+
documentId: string;
|
|
145
|
+
command: string;
|
|
146
|
+
};
|
|
147
|
+
result: null;
|
|
148
|
+
};
|
|
149
|
+
/** Notification: a message for the person. */
|
|
150
|
+
'host/notify': {
|
|
151
|
+
params: Notice;
|
|
152
|
+
result: never;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
export type Notice = {
|
|
156
|
+
level: 'info' | 'success' | 'warning' | 'error';
|
|
157
|
+
title: string;
|
|
158
|
+
description?: string;
|
|
159
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The channel between the host and an extension's worker: requests, answers, and notifications
|
|
3
|
+
* as plain objects over one `MessagePort` (or anything with its `postMessage` and `onmessage`).
|
|
4
|
+
*/
|
|
5
|
+
/** What a `MessagePort` offers that the channel uses; fakes in tests offer the same. */
|
|
6
|
+
export interface PortLike {
|
|
7
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
8
|
+
onmessage: {
|
|
9
|
+
bivarianceHack(event: {
|
|
10
|
+
data: unknown;
|
|
11
|
+
ports?: readonly MessagePort[];
|
|
12
|
+
}): void;
|
|
13
|
+
}['bivarianceHack'] | null;
|
|
14
|
+
start?(): void;
|
|
15
|
+
close?(): void;
|
|
16
|
+
}
|
|
17
|
+
/** Every message on the channel carries this tag; anything else is ignored. */
|
|
18
|
+
export declare const CHANNEL_TAG = "kition-ext/1";
|
|
19
|
+
/**
|
|
20
|
+
* An error that crosses the channel. `code` is `permission-denied`, `not-found`, `invalid`,
|
|
21
|
+
* `failed`, or one of the object model's batch codes (`read-only`, `invalid-op`, …).
|
|
22
|
+
*/
|
|
23
|
+
export declare class ExtensionError extends Error {
|
|
24
|
+
readonly code: string;
|
|
25
|
+
readonly data?: Record<string, unknown> | undefined;
|
|
26
|
+
constructor(code: string, message: string, data?: Record<string, unknown> | undefined);
|
|
27
|
+
toJSON(): {
|
|
28
|
+
data?: Record<string, unknown> | undefined;
|
|
29
|
+
code: string;
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Answers a request or a notification; `ports` are the `MessagePort`s that came with it. */
|
|
34
|
+
export type Handler = (params: never, ports: readonly MessagePort[]) => unknown;
|
|
35
|
+
/** One end of the channel. */
|
|
36
|
+
export declare class RpcPeer {
|
|
37
|
+
private readonly port;
|
|
38
|
+
private next;
|
|
39
|
+
private pending;
|
|
40
|
+
private handlers;
|
|
41
|
+
private closed;
|
|
42
|
+
constructor(port: PortLike);
|
|
43
|
+
/** Answers `method` with `handler` (its result, or the error it throws). */
|
|
44
|
+
handle(method: string, handler: Handler): this;
|
|
45
|
+
/** Asks `method`; `transfer` (a `MessagePort`, …) goes with the request. */
|
|
46
|
+
request<T = unknown>(method: string, params?: unknown, timeoutMs?: number, transfer?: Transferable[]): Promise<T>;
|
|
47
|
+
notify(method: string, params?: unknown): void;
|
|
48
|
+
/** Fails every request still waiting and stops listening. */
|
|
49
|
+
close(reason?: string): void;
|
|
50
|
+
private receive;
|
|
51
|
+
private answer;
|
|
52
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ctx.document` inside an extension's worker: `@kition/script`'s document API (`run`, `context`,
|
|
3
|
+
* proxies, `sync()`, `commands`, `changed`) over the host, which runs each batch on the document
|
|
4
|
+
* and checks it against the extension's permissions.
|
|
5
|
+
*/
|
|
6
|
+
import type { BatchRequest, BatchResult, Schema } from '../../../kdm/src/index.js';
|
|
7
|
+
import { RequestContext, type CommandMap, type ModelObject } from '../../../script/src/proxy.js';
|
|
8
|
+
import type { KitCommandInfo } from '../../../script/src/index.js';
|
|
9
|
+
import type { DocumentInfo } from '../protocol.js';
|
|
10
|
+
import type { RpcPeer } from '../rpc.js';
|
|
11
|
+
export type DocumentChangedEvent = {
|
|
12
|
+
origin: 'local' | 'kit';
|
|
13
|
+
};
|
|
14
|
+
export declare class ExtensionDocument<Root extends ModelObject = ModelObject, C extends CommandMap = CommandMap> {
|
|
15
|
+
private readonly peer;
|
|
16
|
+
private listeners;
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly kitId: string;
|
|
19
|
+
/** The document's file name, when the host gives it. */
|
|
20
|
+
readonly name: string | undefined;
|
|
21
|
+
/** Whether writes are refused (a read-only document, or no `model.write` permission). */
|
|
22
|
+
readonly readOnly: boolean;
|
|
23
|
+
readonly schema: Schema;
|
|
24
|
+
constructor(info: DocumentInfo, peer: RpcPeer);
|
|
25
|
+
/** Runs `script` with a new request context; what it queued and did not `sync()` is sent when it returns. */
|
|
26
|
+
run<T>(script: (context: RequestContext<Root, C>) => Promise<T> | T): Promise<T>;
|
|
27
|
+
context(): RequestContext<Root, C>;
|
|
28
|
+
/** One `model/batch` in its wire form (the host sets its origin). */
|
|
29
|
+
batch(request: BatchRequest): Promise<BatchResult>;
|
|
30
|
+
describe(): Promise<Record<string, unknown>>;
|
|
31
|
+
readonly commands: {
|
|
32
|
+
list: () => Promise<KitCommandInfo[]>;
|
|
33
|
+
enabled: (id: string) => Promise<boolean>;
|
|
34
|
+
run: <K extends keyof C & string>(id: K, params?: C[K]) => Promise<unknown>;
|
|
35
|
+
};
|
|
36
|
+
on(event: 'changed', listener: (event: DocumentChangedEvent) => void): () => void;
|
|
37
|
+
/** The host's `document/changed`. */
|
|
38
|
+
emit(event: DocumentChangedEvent): void;
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@kition/extensions/runtime`: the extension's side. `startRuntime` serves the host on a port
|
|
3
|
+
* (the sandbox worker runs it); `ExtensionContext` is what an extension's `activate(ctx)` gets.
|
|
4
|
+
* `WORKER_RUNTIME`, `SANDBOX_HTML`, and `PANEL_HTML` are the built worker, sandbox page, and panel
|
|
5
|
+
* page; `KitionPanel` is what a panel's scripts get as `window.kitionPanel`.
|
|
6
|
+
*/
|
|
7
|
+
export { PANEL_HTML, RUNTIME_INPUTS_SHA256, SANDBOX_HTML, WORKER_RUNTIME } from '../generated/runtime.js';
|
|
8
|
+
export { ExtensionDocument, type DocumentChangedEvent } from './document.js';
|
|
9
|
+
export type { KitionPanel } from './panel.js';
|
|
10
|
+
export { startRuntime, type CommandHandler, type ExtensionContext, type ExtensionModule, type ModuleLoader, type PanelConnection, type PanelHandler } from './runtime.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The panel page's only script (bundled into `sandbox/panel.html` by scripts/build-runtime.mjs and
|
|
3
|
+
* allowed by its hash). The host posts it the panel's HTML, the extension's `connect-src`, the
|
|
4
|
+
* host's theme, and the panel's end of a channel to the extension's worker. It adds the
|
|
5
|
+
* `connect-src` policy, gives the panel `kitionPanel` (`request`, `onMessage`, `info`), and then
|
|
6
|
+
* shows the panel's HTML, running its inline scripts in order as blob scripts (the page's CSP
|
|
7
|
+
* allows nothing else).
|
|
8
|
+
*/
|
|
9
|
+
import { type PanelInfo } from '../protocol.js';
|
|
10
|
+
type Listener = (message: unknown) => void;
|
|
11
|
+
/** What the panel's scripts get as `window.kitionPanel`. */
|
|
12
|
+
export type KitionPanel = {
|
|
13
|
+
readonly info: PanelInfo;
|
|
14
|
+
/** Asks the extension's worker (its `panel.onRequest` handler); answers what it answers. */
|
|
15
|
+
request(message: unknown): Promise<unknown>;
|
|
16
|
+
/** Hears what the worker sends (`panel.post(message)`); answers an unsubscribe. */
|
|
17
|
+
onMessage(listener: Listener): () => void;
|
|
18
|
+
};
|
|
19
|
+
export {};
|