|
All checks were successful
CD / Build and push images (push) Successful in 3m54s
CD / Deploy to Test (push) Successful in 10s
CI / Lint, typecheck, test (push) Successful in 4m9s
CI / Build container images (push) Has been skipped
CD / Smoke tests against Test (push) Successful in 1m13s
CD / Promote to Int (push) Successful in 13s
CI / Auth e2e pack (push) Successful in 5m36s
CI / Import/export fidelity gate (push) Successful in 47s
A new block plugin bundling the OFFICIAL draw.io editor — nothing ever
loads from diagrams.net; the sandbox CSP pins every request to the
plugin's own version-pinned asset path (zero-external-network verified
live via a request-capture run).
Plugin (packages/plugins/drawio):
- block data { xml, svg }: xml is the draw.io source (document of
record), svg the rendered snapshot as raw markup — render mode,
office/PDF exports (the existing fallback renderer already inlines
data.svg) and the public view all show the diagram without running
diagram code
- edit mode: snapshot + "edit in fullscreen" (an empty block opens the
editor immediately); the bundled editor runs in a child iframe of the
plugin's own assets and speaks draw.io's JSON embed protocol —
Save & Exit exports xmlsvg, persists { xml, svg } via blockData, and
drops back to the inline size
- build.mjs fetches the pinned release (v30.3.6) into a gitignored
vendor/ cache (fonts-build pattern; skipped in CI — plugin.js still
bundles, the installable ZIP needs a dev machine) and packs a trimmed
webapp subset: no dev sources, no embed.diagrams.net integrations
bundle, no standalone viewers, no MathJax/templates/PWA — 27 MiB ZIP,
85 MiB unpacked, de+en editor languages
Host/SDK extensions (generic, not drawio-specific):
- new ui.enterFullscreen()/exitFullscreen(): the surface's frame becomes
a viewport-covering overlay — same sandboxed iframe, only geometry
changes; destroy removes the frame, so a vanished plugin can never
leave the app covered
- sandbox CSP: connect-src/frame-src now allow the plugin's OWN asset
path (was 'none') — bundled apps lazy-load their resources and run in
a child frame, but the api and external hosts stay unreachable; HTML
assets are served with the same CSP so a packaged page cannot widen
the rules, and child frames inherit the sandbox attribute
- plugin size limits raised (ZIP 5→64 MiB, unpacked 20→256 MiB) for
bundled-app plugins; content types for xml/txt/ico assets
Verified end to end against a local stack (9/9): install via dropzone
(85 MiB validation), block insert, fullscreen entry, bundled editor
boots inside the double sandbox (German UI), shape drawn, Save & Exit
persists, snapshot renders inline, survives reload, zero off-origin
requests throughout.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EwZ4jR4KFAPvpjWevfUGX1
|
||
|---|---|---|
| .. | ||
| fixtures/manifests | ||
| src | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vitest.config.ts | ||
@dorfteich/plugin-sdk
The contract between the Dorfteich host app and a plugin bundle: the
manifest schema, the capability names, and the typed postMessage RPC
protocol. It is the one package a plugin author needs — it builds standalone
and pulls in only zod.
Read ADR 0008 and
plugin-architecture.md first;
the manifest example there is normative and mirrored by the fixtures under
fixtures/manifests/.
What's in here
| Module | Purpose |
|---|---|
manifest.ts |
Zod schema for manifest.json + validateManifest / parseManifest. |
api-version.ts |
checkApiVersion — is a plugin's apiVersion within the host's supported range? |
capabilities.ts |
Capability names and the method → capability map that gates RPC calls. |
rpc.ts |
Transport-agnostic RPC engine (createRpcEndpoint) + a windowTransport adapter. |
host.ts |
createHostBridge — host end: routes plugin calls through the permission gate. |
plugin.ts |
createPlugin — plugin end: answers lifecycle calls, exposes a typed host proxy. |
Manifest
import { validateManifest } from '@dorfteich/plugin-sdk';
const result = validateManifest(JSON.parse(raw));
if (!result.success) {
// result.issues: [{ path: 'extensionPoints.0.type', message: '…' }, …]
}
validateManifest never throws — it returns a flat list of { path, message }
issues so the install path (#71) can show a Site Admin every problem at once.
parseManifest is the throwing variant. Cross-field rules enforced beyond the
field shapes:
- extension point types must match the plugin
kind(section_style→sectionStyleonly;code→block/pageTool); - extension point
ids are unique within the manifest; section_styleplugins run no JavaScript and must not declarepermissions.
RPC protocol
Every code-plugin surface runs in a sandboxed <iframe> with an opaque
origin (ADR 0008): no cookies, no host DOM, no storage, no network. Host and
plugin talk only through postMessage with structured-clone payloads.
Message shapes
All messages carry protocol: "dorfteich.plugin.rpc/1"; anything else on the
channel is ignored.
// request (either direction)
{ "protocol": "dorfteich.plugin.rpc/1", "type": "request",
"id": "rpc-…", "method": "getContent", "params": { } }
// success response
{ "protocol": "dorfteich.plugin.rpc/1", "type": "response",
"id": "rpc-…", "ok": true, "result": "# Hello" }
// error response
{ "protocol": "dorfteich.plugin.rpc/1", "type": "response",
"id": "rpc-…", "ok": false,
"error": { "code": "capability_not_permitted", "message": "…" } }
Both directions are symmetric — the same engine answers incoming requests and
correlates outgoing ones by id:
- plugin → host: capability calls (
getContent,listPages, …). The host gate resolves each method to its capability, rejects it withcapability_not_permittedunless the manifest declared that capability, then executes it against the REST API with the viewing user's session — so a plugin can never read more than the person looking at it could. - host → plugin: lifecycle calls (
render,edit,destroy).
Error codes: unknown_method, capability_not_permitted, handler_error,
timeout, endpoint_disposed. Every outgoing request has a timeout (default
10 s), so a hung plugin never blocks the app.
Sequence
sequenceDiagram
participant H as Host (parent window)
participant P as Plugin (sandboxed iframe)
Note over H,P: mount
H->>P: request render { extensionPointId, locale, data }
activate P
P->>H: request getContent
activate H
H-->>P: response ok "# Hello"
deactivate H
P-->>H: response ok (rendered)
deactivate P
Note over H,P: undeclared capability
P->>H: request listPages
H-->>P: response error capability_not_permitted
Note over H,P: hung call
P->>H: request getPageContent
Note right of P: no response within timeout
P--xP: reject timeout
Wiring the transport
The engine is transport-agnostic; hand it a post/listen pair. In the host
app the sandbox runtime (#73) builds it from the iframe boundary:
import { createHostBridge, windowTransport } from '@dorfteich/plugin-sdk';
const bridge = createHostBridge({
manifest,
capabilities: { getContent: () => currentPageMarkdown() /* … */ },
transport: windowTransport({ target: iframe.contentWindow!, source: window, targetOrigin: '*' }),
});
await bridge.invoke('render', { extensionPointId, locale, data });
Inside the plugin bundle:
import { createPlugin, windowTransport } from '@dorfteich/plugin-sdk';
const { host } = createPlugin({
transport: windowTransport({ target: window.parent, source: window, targetOrigin: '*' }),
onRender: async ({ locale }) => {
const md = await host.readCurrentPage.getContent();
// …render into document.body…
},
});
targetOrigin: '*' is intentional for sandbox frames: an allow-scripts
iframe without allow-same-origin has an opaque origin there is nothing to
pin, and the CSP already blocks it from reaching anywhere else.
Scripts
pnpm build— bundle ESM + CJS + types via tsup.pnpm test— Vitest (jsdom); the RPC suite drives a realMessageChannel.pnpm typecheck—tsc --noEmit.