Documentation

Plugin Development Guide

Understand TypeDock's two-tier plugin architecture: native Go core modules and drop-in goja sandboxed JS plugins.

TypeDock uses a two-tier plugin architecture:

  1. Native Go Core Modules (bundled in the binary, toggled from Admin): high-I/O modules such as backup, import-wordpress, image-optimizer, and cloud-storage.
  2. Drop-in JavaScript Plugins (plugins/<slug>/): executed inside an isolated goja ES sandbox with strict execution timeouts, exception isolation, and no Go recompilation required.

Directory Structure

plugins/<slug>/
├── plugin.json    # Manifest (required)
└── plugin.js      # JavaScript entrypoint (default: plugin.js)

Valid slugs match ^[a-z0-9][a-z0-9_-]{0,63}$.

plugin.json Manifest

{
  "slug": "hello-banner",
  "name": "Hello Banner",
  "version": "1.0.0",
  "description": "Renders an announcement banner component.",
  "author": "Your Studio",
  "entry": "plugin.js",
  "provides": [],
  "admin_csp": ""
}
  • provides: Optional list of exclusive capability contracts (e.g. ["captcha"], ["mail"]). TypeDock prevents conflicting plugins from claiming the same capability simultaneously.
  • admin_csp: Optional Content-Security-Policy string applied to the plugin's sandboxed admin iframe.

Host API (ctx)

Your plugin.js runs with a global ctx object providing scoped host capabilities:

  • Identity & Utilities: ctx.slug, ctx.newId(), ctx.now(), ctx.escapeHtml(s), ctx.base64Encode(s), ctx.base64Decode(s)
  • Options: ctx.getOption(key, def), ctx.setOption(key, val), ctx.getSiteOption(key, def), ctx.setSiteOption(key, val)
  • Data & Caching: ctx.db (guarded SQL queries), ctx.cache, ctx.log
  • Outbound HTTP: ctx.http (controlled client with TypeDock-Plugin/<slug> User-Agent)
  • Routing & Admin UI: ctx.registerRoute(method, subPath, fn), ctx.registerAdminRoute(method, subPath, fn), ctx.registerAdminMenu(label, subPath)
  • Components & Blocks: ctx.registerComponent(...) / ctx.registerBlock(...)
  • Slots: ctx.listThemeSlots(), ctx.listSlotPlacements(compType), ctx.addToSlot(...), ctx.removeFromSlot(id)
  • Redirects: ctx.addRedirectResolver(fn)
  • Capabilities & Mail: ctx.hasCapability(name), ctx.registerCapability(name, fn), ctx.callCapability(name, payload), ctx.mailConfigured(), ctx.defaultNotifyEmail(), ctx.sendMail(opts)

For an end-to-end capability example, see Mail Provider Plugin Specification and the bundled reference plugins under plugins/.

Installing a Plugin

Drop the plugin directory into plugins/<slug>/ (or mount it at /app/plugins/<slug> in Docker), then enable it under Admin → Plugins.