Plugins

Install a Marfa plugin from its bundle bytes, and read a release before the install.

install(pluginBundle:expecting:timeout:) sends a bundle's bytes unchanged to installPlugin. The instance records the SHA-256 of those bytes as the plugin's fingerprint, so bytes from a release record the digest the release lists. The generated installPlugin decodes the bundle and encodes it again, and that fingerprint differs. timeout defaults to 20 seconds. Pass expecting: as the other server calls do.

It needs schema.write, write on each type and edge type, and connectors.manage when the bundle has a connector. The answer is a PluginInstalled, and outcome is .installed, .updated or .unchanged. Install a plugin lists the other refusals. pluginInstallRefusal names the two an app tells the owner about, and is nil for every other error, including when the newer-server details are missing:

CaseMeans
.needsNewerServer(marfa:server:).server for 409 plugin_needs_newer_server. marfa is the oldest release the plugin works with, and server is the release this instance runs.
.carriesGuidance.forbidden for 403 forbidden whose details.changes names guidance. A key an app made cannot install guidance or change it. The same plugin with the guidance left out installs.

A type says where it came from. ItemType.origin, from copy.catalog, is .platform, .registered, .plugin or .unknown, and a plugin's type names it in plugin, a TypePlugin with name and version, kept after the plugin is removed. A test makes one with ItemType(id:origin:plugin:), which defaults to .unknown.

Read a release

PluginRelease(address:timeout:) reads a release the way the command line does. A failure throws PluginReleaseError, and nothing reaches your instance until you install. With no address, it reads the latest release of withmarfa/plugins. Pass address: for the release MARFA_PLUGINS_URL names. timeout waits 30 seconds for more bytes, unless you set it.

PluginReleaseErrorMeans
addressCarriesCredentials, addressUnreadableA bad address, thrown before any request. The error never contains the address.
unreachable(address:reason:)The release could not be read. The index must be format 1, and each bundle file <name>.plugin.json.
digestMismatch(file:found:listed:)The bundle's SHA-256 is not the one the index lists.
canceledThe read was canceled.

index() returns the plugins in the release's order. Each PluginIndexEntry holds name, title, description, mark, maker, version, marfa (the oldest Marfa it works with), hasConnector, and the bundle's file and sha256. bundle(for:) returns a ReleasedPlugin only when the bytes match: install its bytes. Its contents read the types, edge types and connector, which an app can show before installing. A type with guidance there needs the owner's recent sign-in: an older one throws confirmationRequired, and a key an app made .carriesGuidance.

PluginVersion reads MAJOR.MINOR.PATCH with no leading zero, such as 0.0.13. Any other string gives nil. 0.0.0 is a development build: isDevelopment is true, and takes(_:) accepts any plugin. Any other release accepts a plugin whose oldest Marfa is the same or older.

import MarfaAPI

let release = try PluginRelease()
let listed = try await release.index()
if let tickets = listed.first(where: { $0.name == "tickets" }) {
    let bundle = try await release.bundle(for: tickets)
    _ = try await server.install(pluginBundle: bundle.bytes, expecting: instanceID)
}

Installing follows the contract's plugins chapter.