anfra docs
anfra SDK

Plugins

What the host installs on your page, and how to check for it

Everything your page reaches beyond itself comes from a plugin that the host installs: running a query, exporting a file, tracing lineage, or saving a PNG or PDF of the page. The host decides which plugins a page gets, and the page can't bring its own. A plugin adds its API under its own name, such as query.export or Anfra.lineage, and only where it is installed.

Checking for a plugin

Anfra.plugins.has('export') // true when the host installed it
Anfra.plugins.list          // [{ name, version }, ...], in install order

When a plugin isn't installed, its member is undefined, and calling it throws a TypeError. Check before you offer anything that needs it, and leave that part of the page out when the plugin is missing:

if (Anfra.plugins.has('export') && Anfra.user.permissions.canExportData) {
  showDownloadButton()
}

Checking the member itself works too: if (Anfra.lineage), or query.export?.().

Built-in plugins

PluginAddsCheck for it
coreRuns every query and loads filter suggestions. Queries, controls and cross-filters all work through it.Never. Every host installs it.
exportquery.export(): a query's whole result as a file.Anfra.plugins.has('export')
lineageAnfra.lineage(): what a field is built from.Anfra.plugins.has('lineage')
renderAnfra.render(): a PNG or PDF of the page or one part of it.Anfra.plugins.has('render')
inspectNothing for your page. The Inspect panel in anfra serve reads your page through it.Not needed.

anfra serve installs all five. Another host may install fewer, or plugins of its own, so a page that checks before it uses a plugin works on every host.

Migrating from Anfra.features

Pages written before plugins checked Anfra.features.export, .render and .lineage. These still answer, from the installed plugins, but they are deprecated: the first read logs a warning in the console, and they will be removed in the next breaking release. Replace each with Anfra.plugins.has():

// Before
if (Anfra.features.export) showDownloadButton()

// After
if (Anfra.plugins.has('export')) showDownloadButton()
  • Environment: the other globals on Anfra.
  • Errors: what a plugin call can reject with.

On this page