Skip to content

Frontend SDK: @host/sdk module surface + slug auto-detection + Trusted Types #214

@tayebmokni

Description

@tayebmokni

Summary

Build the @host/sdk TypeScript module — the stable façade plugins import. Versioned in lockstep with abi_version. Provides: host.activePlugins, host.boot(), registration functions (registerMenu, registerAdminRoute, registerBlock, registerEditorPanel, registerInteractiveBlock, ...), glue (api(), i18n, log, events, settings).

Plugins do NOT import React from their own bundle; they get it via the import map. Plugins do NOT make raw HTTP calls; host.api() is the only blessed way.

Design reference

  • docs/02-plugin-system.md §7.2, Appendix C

Acceptance criteria

  • Package @host/sdk with TypeScript source + ambient type declarations
  • host const exposes activePlugins: ReadonlyArray<{slug, entry, version}> (from window.__host_state.plugins) and boot()
  • Registration APIs: registerMenu, registerAdminRoute, registerBlock (thin wrapper that constructs the doc 04 §2.1 BlockTypeDefinition), registerEditorPanel, registerEditorPlugin, registerInteractiveBlock, registerShortcode
  • Glue: api<T>(path, init?) -> hits /api/plugins/{currentSlug}/{path} with auth token attached, rate-limit hints, JSON parse
  • i18n.t(key, vars?) resolves against the current plugins translation map
  • log.debug/info/warn/error -> console + optional remote shipping (per config)
  • events.on(name, fn) and events.emit(name, data?) for cross-extension client-side messaging
  • settings.get<T>(key) / settings.set<T>(key, v) -> persisted via plugin REST API
  • Slug auto-detection: SDK detects the calling plugins slug via the import map URL (so api() automatically targets the correct plugins endpoint) — no manual slug-passing required
  • Trusted Types policy enforced on DOM-mutating sinks the SDK exposes (per §7.6)
  • Tests + type tests (tsd or expectType); SDK loaded in a test page; registration calls update internal registries; api() round-trips through MSW

Dependencies

#206 (frontend serving), doc 04 §2.1 (BlockTypeDefinition)

Complexity

L

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions