Plugins: signed visuals, themes and connectors

@prismbi/prismbi/plugins loads extensions at runtime, from your own server or a catalog. Code only runs after two checks pass:

Both checks use WebCrypto, so they work in browsers, workers and Node 20+.

import { loadPlugin } from '@prismbi/prismbi/plugins';

const plugin = await loadPlugin('https://plugins.example.com/sankey-pro/manifest.json', {
  trustedKeys: { acme: acmePublicJwk },
});
plugin.registered; // { visuals: ['sankeyPro'], themes: [], connectors: [] }

Failures throw before any plugin code runs:

Writing a plugin #

A plugin is a self-contained ES module: bundle its dependencies, because it's imported from a blob or data URL where bare imports can't resolve. Its default export can contain:

export default {
  visuals: [{ type: 'sankeyPro', displayName: 'Sankey Pro', category: 'chart', roles: [/* … */], render(ctx) { /* … */ } }],
  themes: [{ name: 'acme', /* Theme tokens */ }],
  connectors: { loadAcmeCrm: async (opts) => rows },
  register(api) { /* api.registerVisual, api.registerTheme */ },
};

Visuals follow the same contract as custom visuals. Write them as plain objects; defineVisual is only a typing helper.

Manifest and signing #

{
  "name": "sankey-pro",
  "version": "1.2.0",
  "kind": "visual",
  "entry": "dist/index.js",
  "displayName": "Sankey Pro",
  "description": "Multi-level flows",
  "author": "Acme"
}
npx prismbi-sign-plugin keygen keys/                               # keys/private.jwk (secret), keys/public.jwk (share)
npx prismbi-sign-plugin sign manifest.json keys/private.jwk acme   # adds integrity, keyId and signature

Catalogs (marketplace) #

A catalog is a JSON file that lists plugins with their manifest URLs:

{ "name": "Acme plugins", "plugins": [{ "name": "sankey-pro", "version": "1.2.0", "kind": "visual", "manifest": "sankey-pro/manifest.json", "description": "Multi-level flows", "author": "Acme" }] }
const catalog = await fetchCatalog('https://plugins.example.com/catalog.json');
renderPluginGallery(panel, catalog, { trustedKeys, onInstalled: (p) => console.log(p.registered) });

renderPluginGallery renders a list with Install buttons; installed plugins show as installed. loadedPlugins() lists everything loaded in the page.