# `Alternera.Plugin`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_plugin_sdk/lib/alternera/plugin.ex#L1)

The contract every plugin implements. A plugin is a capability a pipeline
step can use; the step carries the plugin's id and its settings.

Two ideas shape it. From Plug: settings are prepared once by `init/1` and
the prepared form is what every request sees. From Livebook Smart Cells: a
plugin owns its settings, brings the editor for them and registers itself
under a display name (`Alternera.Pipelines.PluginRegistry`).

## Declaring a plugin

    defmodule Alternera.Plugins.Rewrite do
      use Alternera.Plugin,
        id: "rewrite",
        name: "Rewrite",
        description: "Changes the head of the request or of the response."
      ...
    end

`id` is stored in every step that uses the plugin and never changes once
shipped. `directional: true` says the plugin's settings take a
`"direction"` (`"request"` or `"response"`): a stored step carries none,
because the section it sits in is its phase, and the runner injects it
from the section before `init/1` and `load/1` (`Pipelines.Runner`).
A plugin states what its signature cannot derive with twelve
trait options, each `true` or `false` (the default): `any_phase:` (the
step runs wherever the walk reaches it, a bodiless body phase included),
`body_required:` (it runs, to fail, on a body that could not be held),
`runs_bodiless:` (with `body_required:`, it runs on a message that has
no body by the protocol too: a 204, a 304, the response to a HEAD),
`stoppable:` (it stops itself in time, so no watchdog is armed),
`run_in_task:` (it runs in a task the runner can kill), `body_handles:`
(a body held in a file reaches it as a handle), `own_body_handle:` (its
own body held in a file reaches it as a handle), `exchange:` (it reads
the exchange as a whole, beyond its signature) and `writes_url:` (it may
write the request's URL, `url` and its parts; without it such a write
fails the step `invalid_result`) and `tenant_vars:` (it reads the
tenant's variables by a name it only knows when it runs, a script's
`tenant.var/1`, so the runner loads them for every step of it) and
`checks_head:` (a step that reads its side's body runs in its side's
head phase too, at its place in the walk, for what it can check without
the body: `context.phase` says which phase it is in, and what the head
run returns as `carry` reaches the body run as `context.carried`; in a
catch, On error or a For each it runs in one phase alone, which
`context.one_phase?` says, and no other run follows) and `json_doc:`
(it reads and edits its own body through the body's JSON document).
The step's phase,
`neutral?` and `follows?` come from its signature and have no option; a
step whose signature touches nothing runs in its side's head phase.
`sdk` is the major version of this contract the plugin was written
against (`sdk_version/0`). It defaults to the SDK the plugin compiles
with, for a plugin of the proxy's own. A plugin in another Mix project
has to name it: the registry refuses a configured plugin that does not,
or that was written against another major
(`Alternera.Pipelines.PluginRegistry.check_configured!/0`).

Four optional files, each a path relative to the plugin's file, read at
compile time and embedded in the module: `docs:` the plugin's page of
the user guide (`user_doc/0`); `guide:` the notes a model reads about
the plugin's steps (`guide/0`), which the proxy's `get_pipeline_guide`
serves under the plugin's id after the catalogue's entry;
`recipes:` whole pipelines with their tests (`recipes/0`), in the
format `Alternera.Plugin.Recipes` reads, which the proxy indexes
under `recipe:<plugin id>/<slug>` and finds by a query beside its own;
and `migration_guides:` guides for a user bringing an integration from
another platform (`migration_guides/0`), in the format
`Alternera.Plugin.MigrationGuides` reads, which the proxy serves
under `migrate:<plugin id>/<slug>` and finds by a query naming the
platform or its vocabulary. A plugin's guide may name the platform it
is a migration from: the platform is its subject.

## Compatibility

The contract is the plugin model: `call/3`, with `leave/3` for a step
that holds and `signature/2` for what a schema cannot declare. It changes
only in ways a plugin written against an earlier minor keeps working
through:

  * `call/3`'s results (`c:call/3`) are only added to, never removed or
    changed: `{:ok, writes[, summary[, extra]]}`, with `extra` holding
    `outputs` (the step's outputs; a row whose place the step writes
    itself is not written again from them), `directives` (in the request
    head, the keys `Plugin.CallAdapter.directive_keys/0` lists), `calls`
    (a `Provisional.Calls` handle), `record` (what a step that reaches
    outside did, for a played preview to save) and `carry` (with
    `checks_head:`, in the head phase: what the same step's body run
    gets as `context.carried`), each optional,
    `{:respond, answer, writes[, summary]}`, `{:hold, state[, summary]}` (with `leave/3`), `{:refuse,
    type, message, retry_in_ms}` (with `refuses:`), `{:skip, reason}`,
    `{:return, value[, summary]}` and a failure (`t:call_failure/0`), whose map
    takes only the keys listed there. Any other result fails the step
    `invalid_result`, and so does a write of a kind the step's signature
    does not write, checked on every result in every mode;
  * `leave/3`'s results are only added to, and so are the
    `Plugin.BodyObserver` callbacks (a new one optional), whose end is
    called once;
  * a `use Alternera.Plugin` option is only added, and a new one
    defaults to what plugins did before it existed (`directional:`,
    `refuses:`, `previews:`, `streams:` and the trait options
    `any_phase:`, `body_required:`, `runs_bodiless:`, `stoppable:`,
    `run_in_task:`, `body_handles:`, `own_body_handle:`, `exchange:`, `writes_url:`,
    `tenant_vars:` and `checks_head:` today, each `false` by default;
    `previews:` is `:skip` for a holding plugin and `:enter` for any
    other);
    what the signature derives (the phase, `neutral?`, `follows?`) gets
    no option;
  * the schema keys a `Plugin.Signature` is derived from (`role`, with
    the roles `:location`, `:target`, `:template` and `:targets`, `secrecy`,
    `label_suffix`, `item_label`, `template_label`) are only added to, and so are the
    part entries `Plugin.Signature.part_entry/1` takes;
  * `Plugin.Inputs`' `read/2`, `resolve/2` (by the template's settings
    path) and `with_write/3` keep their arguments and results; a new
    function is added beside them;
  * the `Plugin.Location` kinds are only added to; a read-only kind may
    become writable;
  * a key is only ever added to `t:context/0`, `t:metadata/0` and the view
    (`t:Alternera.Plugin.Location.view/0`), and none is renamed,
    removed or changes its type. A `call/3` plugin may rely on
    `tenant_id`, `pipeline_id`, `pipeline_name`, `step`, `phase`,
    `time_left_ms` and `dry_run?`, a `body_required:` one on `unheld`
    (why its body was not held, when it was not) and `body_absent?`
    (true when there was no body to hold), one that reaches
    outside (`side_effect?/0`) on `play?` (the preview plays the step:
    it runs for real and returns its `record`), `provisional?` (the
    request phase runs to decide whether the body must be read, and a
    step that acts outside waits for the deciding pass),
    `body_max_bytes` (the pipeline's body limit, 0 for none) and
    `outputs_read` (the step's outputs a later step reads: a list of
    names, `:all`, or nil for none), and a holding one on `owner` and
    `per_call?` besides, and in `leave/3` on `inputs`, the exchange at
    its Close; it reads the exchange through `Plugin.Inputs`,
    never the view itself;
  * a new callback is optional, and its absence means what every plugin
    did before it existed;
  * a plugin's module name is part of its identity: compiled pipelines
    are stored as bytecode that names the module and embeds its prepared
    settings, so renaming the module, or changing the shape `init/1`
    returns, needs a recompile of every tenant's pipelines (a compiled
    module stamps the SDK major it was built under, and the evaluator
    refuses one built under another).

`Plugin.CallAdapter` is the host's, not the contract. Anything that cannot be done within these rules is a new
major.

## Trust

A plugin is trusted like a dependency. Its steps run in the exchange's
own process (or a task of it), with its inputs, the tenant's
variables (names of the secrets, never their values:
`Pipelines.TenantVars.for_step/1`) and everything the BEAM lets a module
do. The runner contains a *fault* — a raise, throw or exit is a
`crashed` failure, a wrong shape an `invalid_result`, a `load/1` that
raises an unavailable step, a body step over its heap limit a
`memory_limit`, and a step that runs past `time_left_ms` is stopped: an
inline step with the process that runs the decision, which then answers
the request as a `timeout` failure naming the step. That stop is a
`:kill`: no `after` or `rescue` in the step runs, and a process the
step linked to itself without trapping exits dies with it, so a step
that opens something outside the exchange should hold it in a process
it monitors, as Script's sandbox and Request's call do — but not a
hostile plugin: a streaming filter has no timeout, and one
that returns outside its contract ends the forwarder's process. Whoever
lists a module under `:alternera, :plugins` vouches for it the way
they vouch for a dependency in `mix.exs`. A plugin carries no licence
check of its own: what the installation's licence withholds, the host
refuses when the plugin asks for it (`Plugin.Host`).

## Callbacks

`init/1` runs on every write (to validate) and refuses settings with any
entry or key it cannot use. It is pure: no database, no licence check, no
logging of values. Its result must be plain data — the compiler embeds
the prepared settings in the generated module as a literal, so no pids,
functions, references or compiled regexes.

`load/1` prepares settings as stored, when the interpreted pipeline cache
fills, in the compiler and in the preview. It is lenient where `init/1`
is strict: it skips the entries or keys it cannot use (one stored before
a check existed, a value from an older vocabulary) and returns
`{:ok, opts, skipped}`, `skipped` naming each with the reason, so the
step's other entries still apply. It refuses only settings with nothing
usable left. The runner logs every skipped entry and records it on the
step's outcome (`skipped_entries`). The default calls `init/1` and skips
nothing; a plugin whose settings hold separable entries overrides it.

`call/3` is the step's work (`Plugin.CallAdapter`): it reads the
exchange through `Plugin.Inputs` and returns what it writes. It is the
one callback every plugin defines. Where it runs follows from its
`Plugin.Signature`: the phase its reads and writes need (a step on its
side's body runs in the body phase, any other in the head), the request
head for a step that holds (`leave/3`). The runner asks for a response
head or a held body only when some step needs it. A body step gets the
decoded body, and only when the forwarder could hold it within the
tenant's caps; its context also carries `content_type`, the
`Content-Type` value of the message the body belongs to, or nil. A step
that writes that header with the body sends the message with it in place
of the one it had; the runner checks the value (`check_content_type/1`),
and one that is not a valid single header value fails the step.

## Answers and failures

A step may answer the exchange itself: `{:respond, answer, writes}`,
`answer` being `%{status, headers, body, content_type}` (headers a list
of `{name, value}`). The runner checks it (`Runner.check_answer/1`) and
ends the section: the codec serves the answer instead of contacting the
upstream (on the request side) or in place of the upstream's response
(on the response side). A step may fail on purpose with `{:error, type,
message}`: `type` is a slug (`Plugin.Error.valid_type?/1`). A map
(`t:call_failure/0`) adds `status`, the status the error asks an answer
to have, and names what in the request the error is
about (`error.target`, a Fail step's `error_target`) and hands the
error what the step's To rows selected
from the result that failed (`error.outputs`,
`Plugin.Targets.selected/2`) and the marks of those a header row
selected; a failed step still writes nothing. `on_purpose: true` marks
an error the pipeline's author raised (a Fail step, a script's
`fail(...)`): the error answer passes its message and status on to the
client (`Pipelines.ErrorAnswer`). `outbound_us` is the time
the step waited on calls outside the proxy before it failed, which stays
outbound pipeline time (`Pipelines.StepOutcomes.outbound_time/1`), and
`calls` the calls it made (each a map, as a Request step's summary
lists them), which stay on the failed step's summary, and `summary`
more entries of that summary (a plugin host's trace).
`retry_after_ms` is when a refused call may try again (a throttle's or
a circuit breaker's): the error answer's `Retry-After`. A step may end the walk
with a value, `{:return, value}` (`Plugins.Return`): the result of the
call the pipeline runs in, or the end of its side outside one;
`{:return, value, summary}` keeps the step's summary (the calls it made)
on its outcome, as `{:ok, writes, summary}` does.

`Alternera.Pipelines.Runner` is the only caller of `call/3`. It
catches around each call, so a plugin may raise, throw or exit: that is
a failure of type `crashed`, and a result outside the contract
(`{:halt, …}` included) one of type `invalid_result`. A failure is
logged with the pipeline, the step and the exchange and recorded; what
happens next is the step's error policy (`fail`, the default, ends the
exchange's steps; `continue` goes on with the message as it was). A
`load/1` that raises, throws or exits makes its step unavailable: logged,
never run, and the pipeline's other steps still run and compile.

The context of every step carries `:section` (`:flow` or `:on_error`),
`:side` (`:request` above the flow's pivot and in a flow without one,
`:response` below it; On error's is the side of the error it handles),
`:path` (the step's place in the tree),
`:time_left_ms` (the step's timeout or the pipeline's budget left,
whichever is less), `:call_depth`, `:body_max_bytes` (the step's
pipeline's body limit, 0 for none, nil when it sets none), `:error`
(the error a catch or On error handles, else nil) and `:provisional?` (true while the request
phase runs on the head only to decide whether the body must be read; a
step with effects outside the exchange returns `needs_body: true` in its
summary instead of acting, and runs in the pass that decides,
`Pipelines.BodyMatch.body_needed?/1`). `:body_held?` is true when a
`streams: true` plugin's `call/3` runs on a body held whole, which the
adapter feeds through its filter (no cap per piece is needed there).
`:body_declared?`, on the request head alone, says whether the head
declares a body (a Content-Length above zero, a chunked transfer
coding, an HTTP/2 HEADERS frame that does not end the stream); it is
left out where the head does not say. `:dry_run?` is true in a preview
(`Pipelines.Preview`): a step with effects outside the exchange (a call)
describes them in its summary and does not act. `:exchange_request` and
`:plugin` are the host's, not the step's to read: the exchange's request
head, which `Plugin.Provisional.Outbound` takes a call's parent exchange,
trace and secret token from, `Plugin.Provisional.Credentials` a token
fetch's trace and `Plugin.Provisional.Identity` the sign-in, whether or
not the step uses the exchange (a
step reads the exchange through its inputs), and the module
whose step runs, the only plugin whose upstream its calls may reach.

The trait options describe a plugin to the runner and the editor:
`any_phase:` (the step answers or fails where the walk reaches it: in a
catch or On error it runs in whichever phase the error happened in;
Respond and Fail), `stoppable:` (the step stops itself at
`time_left_ms` and fails with `timeout` as an ordinary step failure, so
its error policy, a try and On error apply: Script and Request. Any other
step is stopped at its time left by a kill of the process running the
decision, which fails the request with `timeout` naming the step and
runs no policy or handler), `run_in_task:` (the step waits on I/O: the
runner runs it in a task of its own and kills the task at the step's
time left, so the step is stopped, not waited for; the Request step) and
`body_handles:` (the step takes the bodies as the runner holds them,
`Plugin.Body` handles in memory or in a file, instead of binaries, and
`Plugin.Location.read/2` hands back a whole body held in a file as it
is; the step may write back the handle it got, unchanged. The Request
step says it, so a large source is sent from its file and never read
into the step's memory), `own_body_handle:` (as `body_handles:` for
the step's own body in a body phase alone: held in a file, it reaches
the step as the handle, which the step reads itself, in chunks or whole,
while the rest of its view is read for it; the Script step says it, so
a script run per record reads a spooled body from its file) and
`json_doc:` (the step reads and edits its own body through the body's
JSON document, `Plugin.Inputs.edit_json/3`, and never as text: a body
held in a file is handed to it as the handle, unread and unclaimed, and
an edit is made over the file. The plugin's optional `json_doc?/1` says,
for prepared settings, whether a step takes the document; without it
every step does, `json_doc?/2`). The signature answers `neutral?` (the step
reads no body and writes only the exchange's variables, so it can run in
either phase of its side: in a choice that waits for the body it runs in
the body phase, in a catch or On error in the phase of the error, in a
called pipeline in the phase the Call step first runs in), `follows?`
and `keeps_request_body?` (`Plugin.Signature`).

## Outputs and the To list

`outputs/0` (default `[]`) registers the values one run of the
plugin's steps can produce (`t:output/0`): a name, a label and a
description for the editor and the APIs, a kind, whether it takes a
key (a set of named values, headers, from which a row picks one) and
which output is the default. A step's settings say which of them go
where in `"targets"`, its To list (`Plugin.Targets`); a single
`"target"`, the shape every step had before, is one row of the
default output. `Pipelines.Catalogue` publishes the registration, so
the editor offers only outputs the plugin registered. Return
`Plugin.Targets.parse/4`'s refusal after your plugin's name
(`Store: To row 2 (body): …`): the editor reads the row back
(`Plugin.Targets.row_error/1`, on `Plugin.RowError`) and shows the
reason at that row. A refusal of a row of another list of yours reads
the same way, `<Plugin name>: <label> N: reason`, for your editor to
place with `Plugin.Editor.RowErrors`.

`output_keys/1` (optional, no keys known when absent) names, for a
step's stored settings, the keys a keyed output is known to carry:
`%{"outputs" => ["order_id", "priority"]}` for a script that sets them.
The editor of a later step offers them when it reads that output; a
key it does not list can still be typed, so the answer may be partial.

## A step's error policy

A step stores its error policy as `on_error`, `"fail"` or `"continue"`
(go on); one that stores none fails. `on_error/0` (optional, `:fail`
when absent) is the policy a new step of the plugin starts with, which
the editors store with it: a plugin whose failures are routine, such as
a value that is not there, answers `:continue`. A step stored without
one still fails, so changing the answer never changes a saved step.

## Steps that reach outside

`side_effect?/0` (optional, false when absent) says the plugin's steps
act outside the proxy: a call, a query. The editor marks such a plugin,
and its step can be **played** in the preview: run for real, once, with
the inputs the preview has at that point, its output saved on the
pipeline (`pipelines.step_outputs`) and fed back into later previews in
place of the dry run's empty answer (`Pipelines.Runner`,
`Pipelines.Preview`). Such a plugin follows three conventions the
runner reads without knowing what the step does:

  * its summary carries `:fingerprint`, a string naming the resolved
    call (`"hmac-sha256:" <> hex`, `Pipelines.SavedStepOutputs.fingerprint/1`), in the dry run and in the real run alike
    and computed from the same values, so a saved output whose call no
    longer resolves the same is marked stale. A dry run may add `:call`,
    `%{method, url}`, which the preview compares with the saved call's
    to say what changed;
  * its real run's extras carry `:record`, a JSON-ready copy of what it
    did (for a call: the request as sent and the response as it came),
    saved with the output and shown in the preview;
  * the output a later preview reuses is its `writes`, nothing else.

`replay_recorded/2` (optional) builds the same from what live traffic
recorded: given the prepared settings and the exchange the step's real
run recorded, `{:ok, writes, summary, record}` or `{:error, reason}`.
The editor offers "Use the recorded call" only for a plugin that has it.

`sides/0` names where a step of the plugin may stand: `:request` (above
the flow's pivot, or anywhere in a flow without one), `:response` (below
the pivot) and `:on_error`; the default is all three. The two pivot
plugins say `[:pivot]`: where they stand is `Pipelines.Flow`'s rule. A write that
places a step elsewhere is refused (`Pipelines.FlowCheck`), the editor
offers the plugin only there, and `Pipelines.Catalogue` reports it to
the APIs.

`body_required: true` says a body step cannot be left out: when the
codec cannot hold the body (body transformations off, over the cap, a
coding it cannot decode) the step still runs, with
an empty body and `:unheld` (the reason) in its context, and fails;
`:body_absent?` is true beside it when the message has no body at all
(a request sent without one) rather than one the codec did not hold;
any other body step is recorded as skipped (`Runner.run_body/6`). A
message with no body by the protocol (a 204, a 304, the response to a
HEAD) skips it too, unless it also says `runs_bodiless: true`: then it
runs there with `:body_absent?`, for the parts of the message it checks
beside the body (Validate API definition's status and headers).

## The exchange

A step reads the places of the exchange its signature names
(`Plugin.Location`) through `Plugin.Inputs`, as the earlier steps left
them: the request (as forwarded, in the later phases), the response
head, the bodies the forwarder holds and the exchange's variables. It
returns what it writes as `writes`, `[{location, value}]`, in order. The
runner writes them (`Location.write/3`) and refuses a location the
step's direction may not write (`Location.allowed/3`) or its signature
does not name: any refused or failing write fails the step and undoes
its whole result. A `nil` value writes nothing. Variables are the
exchange's: set in one phase, they are in every later step's inputs.
`exchange: true` gives a step the view of the whole exchange, beyond its
signature.

A step also returns what it produced as `outputs`, output name to value
(`%{"body" => …, "status" => 200, "headers" => %{…}}`), its outputs
whether or not a To row takes them. The runner keeps them in the
exchange under the step's id (`Plugin.StepOutputs`), for the later
steps of the same pipeline to read: the view's `:steps` (the current
pipeline's outputs, by step id), `{"in": "steps"}` locations,
`${steps.<id>.<output>}` templates and `step` conditions. It keeps a
`body` and `outputs` only when a later step reads them, and fails the
step with `step_output_too_large` when one is over the variable cap.

A step whose signature reads a step output or a variable, never its own
body, and writes only exchange-level data follows (`follows?`): placed
after a body step it runs in the body phase, right after it, so it sees
what that step produced (`Pipelines.Runner`'s phase rule). Without it a
head step runs in the head phase, before every body step of its side. A
response step whose signature reads the request body keeps it
(`keeps_request_body?`): the forwarder keeps the request body, as
forwarded, until the response (`Pipelines.Runner.keep_request_body?/1`).

## Streaming steps

A body step normally gets the whole body, so the forwarder holds it
until the steps ran. A plugin declared with `streams: true` can work on
the body as it passes instead: its `call/3` answers `{:stream, first,
{filter, state}, writes}`, `filter` a `Plugin.BodyFilter` module whose
`chunk/2` sees each piece of the decoded body and whose `finish/1` the
last, run in the forwarder's own process in the order the steps are
walked, each one's output the next one's input. Its optional
`stream_hold/1` names, for prepared settings, a reason a step must hold
the body (`streams/2` answers `{:holds, reason}`); the editor and the
validation output show it. `writes` may set the message's
`Content-Type`, nothing else. The filter's optional `abort/2` frees
what it holds when the stream ends before its finish; one that raises
is logged.

A filter's `chunk/2` and `finish/1` may answer `{:error, type, message}`
when it cannot go on: `malformed_body` for a body that turns out to be
one it cannot read (JSON that breaks off partway), which the side that
sent it is blamed for, any other type for the step's own failure. The
step fails with that error; what went out cannot be taken back, so the
codec ends the body where it is and records the step failed
(`Pipelines.Runner.stream_failed/2`). Any other return crashes the
forwarder's process.

A side's body streams only when every step the walk reaches in its body
phase streams (`Pipelines.Runner.plan_body/3`); otherwise it is held,
and the adapter feeds the held body through the same filter in pieces
(`context.body_held?` is then true).

`settings_schema/0` describes the settings `init/1` takes, as plain data
(`t:schema_field/0`): the `reference-plugins` page of the user guide is
generated from it. Build it from the constants `init/1` checks against,
so the two cannot drift; a test per plugin holds them together. A plugin
that does not define it describes no settings (`[]`).

## Tenant variables

A setting may reference the tenant's variables
(`Pipelines.TenantVars`): `{{NAME}}` for a plain one,
`{{secret.NAME}}` for a secret. The optional `templates/1` lists, for
the stored settings, every text that takes references, each with the
kind the setting allows: `:secret` (both kinds: a value that leaves the
proxy toward the upstream) or `:plain` (plain only: a value that goes to
the client or into an error). The save checks those texts, the runner
loads the tenant's variables for a step only when they reference one,
and puts them in the context as `:tenant_vars` (and on the view as
`tenant_vars`, for `Plugin.Template.resolve/3`). A step that reads
variables by a name it only knows when it runs (a script's
`tenant.var/1`) says so in its signature (`Plugin.Signature`'s
`tenant_vars`), or, for every step of the plugin, with
`tenant_vars: true`.

The optional `exchange_templates/1` lists, for the stored settings, the
texts the step resolves with `Plugin.Template.resolve/3`, each with a
label naming where it is (`"Set value 2"`, `"header X-Env"`). The save
refuses one holding a `${…}` no template knows (`Plugin.Template.check/1`)
in a step it writes, with that label in front of the message; a stored
step keeps loading and running as it is. A text the step passes on as
it is besides (a body, which may carry JavaScript's own `${…}`) is left
out.

## Settings by match

A Configuration step may set a plugin's settings for the requests it
matches (its `plugins` key): the runner fills a step's empty
configurable fields from the Configuration steps that ran before it, the
innermost winning, and runs `init/1` on the result. A top-level field
of `settings_schema/0` is configurable unless it decides what the step
does: a field with the role `:location`, `:target` or `:targets`, a
directional plugin's `"direction"`, and a field the plugin marks
`configurable: false` (code, operations, rows: what `init/1` turns into
structure) are not. `configurable: :only` is a field set only there,
hidden in the step editor and refused in a step's stored settings
(`Plugin.CallAdapter.init/2`), for a value a step should never hold,
such as an API key. A Configuration value for a `:template` field holds
literals and `{{NAME}}` / `{{secret.NAME}}` references, never a `${…}`.
A list or map is set and replaced whole. `configurable_fields/1` and
`configurable?/2` answer which; `configurable_fields/2` and
`configurable?/3` answer for one step, leaving out a field marked
`configurable_on` the other side.

A configurable `:enum` may list `skips`: values that skip the step for
the requests the Configuration step matches, as if it were disabled
there. The runner checks them before `init/1`, so the plugin never runs
with one, and a step's stored settings may not hold one
(`skip_errors/2`). With `configurable_on: :response` that turns a check
in After off by match while the same plugin's steps in Before still run.
A plugin declared `checks_head: true` may also list `skips_head` and
`skips_body`: values that skip only the step's head run or only its body
run. The runner does not run that phase of the step (a skipped body run
holds no body for it), and the plugin's `init/1` gets the value, so its
other run knows what it leaves out.

A `required` field that is configurable may be empty in the step:
`init/1` must accept settings without it (the contract kit checks), and
the runner fails the step `not_configured` when it is still empty after
the fill, before `init/1` runs, so no plugin writes that message.

A field declared `reveal: true` may reference a secret the step needs
in-process (a signing key): `Plugin.Secret.reveal/3` resolves it through
the host into a `%Plugin.Secret{}` that no log line, crash report or
output can carry.

## The errors a step raises

The optional `raises/1` lists, for the stored settings, the error
types a step of the plugin can fail with by itself (`t:raises/0`), so
the editor can show On error what may arrive there and a try's catch
what it may match. It names the plugin's own types and the ones it
passes on (a Request step's `connection`, `tls`, `timeout`); the
runner's types any step can fail with (`crashed`, `timeout` at the
step's time, `unresolved_variable` for a setting `templates/1` lists)
are added by the proxy and need not be listed. `:others` says the step
may fail with types the settings do not show (a script's `fail(...)`
with a computed type, a called pipeline's). A plugin without it is
shown as raising types of its own, unnamed.

A type may carry the status the client gets when nothing answers the
error, `{type, status}` (a Response cache's `{"cache_miss", 504}`): the
error answer keeps the status a failure of that type carries when it is
the declared one (`call/3`'s `{:error, type, message, %{status: s}}`),
and the editor shows it. A type without one answers 502, whatever
status the failure carries for On error to read. A plugin with
`refuses:` gets its refusals declared this way from `use`. A type
listed with several statuses (Validate API's `{"validation", 400}`,
`{"validation", 404}` and `{"validation", 405}` on a request) keeps any
of them. A status raised on purpose (a Fail step, a script's
`fail(...)`, `on_purpose`) is the author's own and needs no
declaration.

## The answers a step makes

The optional `responses/1` lists, for the stored settings, the statuses
a step of the plugin answers the client with (`t:responses/0`), so the
editor can show what a pipeline may answer: a Respond's status, Serve
API's 200. `:others` says the step may answer with a status its
settings do not show (a template, one a script computes). An error is
no answer: what a step fails with is `raises/1`'s, with the status the
client gets for it. A plugin without the callback whose
step makes a response (`produces_response?/1`) counts as `:others`; one
that makes none answers nothing. A plugin with `refuses:` gets it from
`use`: the refusals' statuses when its `on_refusal` is
`skip_to_after`, else none.

## The memory a step takes

The optional `memory_factor/1` says, for the stored settings, how many
bytes of memory a step of the plugin takes at its peak per byte of the
bodies it loads (its own and those its view carries), as a whole
number. Before such a step runs on bodies over the inline threshold the
runner claims that much from the application's held-bytes budget, and
waits for room or refuses the step when there is none (`memory_limit`,
`body_too_large`), so the figure is what keeps many large steps at once
within the machine's memory. It is an estimate, not a bound: the step's
heap limit (`Provisional.StepHeap`) stops a step that runs past it. A
plugin without the callback is claimed for at the application's
default. The factor may read only fields a Configuration step cannot
set (`configurable: false`): it is read once from the stored settings
when the pipeline is prepared, not from the settings a step is filled
with as it runs. Measure a plugin's own
figure on the step's outcome (`memory_peak_bytes`, from
`Provisional.HeapPeak`) on a body of a few megabytes, where the
process's fixed size no longer counts, and round it up. A step that
takes its body as a handle (`body_handles:`) loads none, and a plugin
that runs its work in a heap of its own (the Script sandbox) claims
through `Plugin.Host.claim_held_bytes/2` with its own factor.

A plain reference resolves when the step runs, never in `init/1` or
`load/1`. A secret reference is checked then and left as written: no
step ever sees a secret's value, which goes in where the request is
written to a socket (`Pipelines.WireSecrets`). A reference that does
not resolve raises `Plugin.UnresolvedVariableError`; the runner
fails the step with type `unresolved_variable`.

## Reserved

A WebSocket-message phase and plugins not compiled into the release are
not part of the contract. Any result outside `call/3`'s fails the step
`invalid_result`: answering is `{:respond, …}`.

# `answer`

```elixir
@type answer() :: %{
  :status =&gt; 100..599,
  optional(:headers) =&gt; [{String.t(), String.t()}],
  optional(:body) =&gt; binary() | Alternera.Plugin.Body.t(),
  optional(:trailers) =&gt; [{String.t(), String.t()}],
  optional(:content_type) =&gt; String.t() | nil
}
```

An answer a step gives the exchange (`{:respond, answer, writes}`): its
body a binary or a file (`Plugin.Body`, which the door streams and
releases), and trailers sent after it.

# `call_failure`

```elixir
@type call_failure() ::
  {:error, atom() | String.t(), String.t()}
  | {:error, atom() | String.t(), String.t(),
     %{
       optional(:status) =&gt; 100..599,
       optional(:outputs) =&gt; outputs(),
       optional(:target) =&gt; String.t() | nil,
       optional(:on_purpose) =&gt; true,
       optional(:outbound_us) =&gt; non_neg_integer(),
       optional(:header_vars) =&gt; %{required(String.t()) =&gt; String.t()},
       optional(:request) =&gt; map(),
       optional(:response) =&gt; map(),
       optional(:calls) =&gt; [map()],
       optional(:retry_after_ms) =&gt; non_neg_integer() | nil,
       optional(:summary) =&gt; map()
     }}
```

How a `call/3` step fails: a type (`Pipelines.Runner.Error`'s, or the
plugin's own) and a message, and with a map only these keys:
`status`, the HTTP status the error answer takes (100..599);
`outputs`, the step's outputs (`t:outputs/0`), which its To rows pick
from for the error's `outputs` (`${error.outputs.…}`); `target`, what in
the request the error is about (`error.target`, the error answer's
`target`; text, nil for none, from Fail); and `on_purpose: true`, an
error the pipeline's author raised, whose message and status the error
answer passes on to the client (from Fail); and `outbound_us`, the µs
the step waited on a service outside the proxy before it failed (from
Authorize's token fetch). Each later key lands with
the first plugin that needs it, listed here then; any other key, and
any other shape, fails the step `invalid_result` (`Plugin.CallAdapter`).

# `context`

```elixir
@type context() :: %{
  :tenant_id =&gt; String.t() | nil,
  :pipeline_id =&gt; String.t() | nil,
  :pipeline_name =&gt; String.t() | nil,
  :step =&gt; String.t(),
  :phase =&gt; phase(),
  optional(:path) =&gt; String.t(),
  optional(:section) =&gt; :flow | :on_error,
  optional(:side) =&gt; :request | :response,
  optional(:time_left_ms) =&gt; pos_integer(),
  optional(:call_depth) =&gt; non_neg_integer(),
  optional(:body_max_bytes) =&gt; non_neg_integer() | nil,
  optional(:provisional?) =&gt; boolean(),
  optional(:dry_run?) =&gt; boolean(),
  optional(:play?) =&gt; boolean(),
  optional(:outputs_read) =&gt; :all | [String.t()] | nil,
  optional(:unheld) =&gt; String.t(),
  optional(:body_absent?) =&gt; boolean(),
  optional(:directives) =&gt; directives(),
  optional(:error) =&gt; struct() | nil,
  optional(:content_type) =&gt; String.t() | nil,
  optional(:view) =&gt; Alternera.Plugin.Location.view(),
  optional(:exchange_request) =&gt; map() | nil,
  optional(:plugin) =&gt; module() | nil,
  optional(:body_held?) =&gt; boolean(),
  optional(:carried) =&gt; term(),
  optional(:one_phase?) =&gt; boolean(),
  optional(:body_declared?) =&gt; boolean()
}
```

# `directives`

```elixir
@type directives() :: %{
  optional(:retry_policy) =&gt; :disabled | :safe | :idempotent | :all_methods,
  optional(:timeout_ms) =&gt; pos_integer(),
  optional(:protocol_preference) =&gt; :http1 | :http2,
  optional(:spool_threshold_bytes) =&gt; pos_integer(),
  optional(:large_body_recording) =&gt; :spill_to_file | :truncate,
  optional(:plugin_settings) =&gt; %{
    required(String.t()) =&gt; %{required(String.t()) =&gt; term()}
  }
}
```

Handling instructions for the forwarder. The last step to set a key wins.

# `editor`

```elixir
@type editor() :: {:builtin, atom()} | module()
```

What `editor/0` names: `{:builtin, id}` for one of the step editors the
proxy's web layer holds (`:transform`, `:script`, …), which it maps to
the LiveComponent so that no plugin names a web module; or the plugin's
own LiveComponent module, for a plugin that brings its editor
(`Alternera.Plugin.Editor`). A constant: the registry reads it at
boot to check it, the editor each time a step is drawn.

# `metadata`

```elixir
@type metadata() :: %{
  :id =&gt; String.t(),
  :name =&gt; String.t(),
  :description =&gt; String.t(),
  optional(:directional) =&gt; boolean(),
  optional(:sdk) =&gt; pos_integer(),
  optional(:sdk_pinned?) =&gt; boolean()
}
```

# `opts`

```elixir
@type opts() :: term()
```

Settings prepared by `init/1`. Plain data only.

# `output`

```elixir
@type output() :: %{
  name: String.t(),
  label: String.t(),
  description: String.t(),
  kind: :body | :status | :headers | :value,
  keyed?: boolean(),
  default?: boolean()
}
```

A value the plugin's steps can produce (`outputs/0`). `kind` says what
the value is, which bounds where a row may write it
(`Plugin.Targets`): `:body` a body, `:status` a status code,
`:headers` a head's headers (lower-cased names to values), `:value`
anything else. `keyed?` says a row may pick one named value of it
(`"key"`); `default?` marks the output a single `"target"` writes.

# `outputs`

```elixir
@type outputs() :: %{required(String.t()) =&gt; term()}
```

A `call/3` step's outputs: each name one its `outputs/0` registers, with
the value this run produced (a keyed output's value is a map of key to
value). The runner keeps them as `steps.<id>.*`, and the step's To list
(`Plugin.Targets`, a schema field with `role: :targets`) writes them
where its rows say, after the step's own writes.

# `phase`

```elixir
@type phase() :: :request | :response | :request_body | :response_body
```

# `raises`

```elixir
@type raises() :: [String.t() | {String.t(), 200..599} | :others]
```

What `raises/1` answers: error types (slugs, `Plugin.Error.valid_type?/1`),
each alone or with the status the client gets for it (`{type, status}`,
200..599 but 204, 205 and 304, one entry per status when the type has
several), and `:others` when the step may fail
with types its settings do not name.

# `responses`

```elixir
@type responses() :: [100..599 | :others]
```

What `responses/1` answers: the statuses (100..599) a step answers with,
and `:others` when it may answer with one its settings do not show.

# `schema_field`

```elixir
@type schema_field() :: %{
  :key =&gt; String.t(),
  :type =&gt; :enum | :integer | :string | :boolean | :map | :list,
  :required =&gt; boolean(),
  :description =&gt; String.t(),
  optional(:values) =&gt; [String.t()],
  optional(:aliases) =&gt; %{required(String.t()) =&gt; String.t()},
  optional(:range) =&gt; {integer(), integer()},
  optional(:item) =&gt; :string | schema_variants() | %{fields: [schema_field()]},
  optional(:role) =&gt; :location | :target | :targets | :template,
  optional(:label) =&gt; String.t(),
  optional(:configurable) =&gt; false | :only,
  optional(:configurable_on) =&gt; :request | :response,
  optional(:skips) =&gt; [String.t()],
  optional(:skips_head) =&gt; [String.t()],
  optional(:skips_body) =&gt; [String.t()],
  optional(:reveal) =&gt; boolean(),
  optional(:json_schema) =&gt; :one | :by_key,
  optional(:api_definition) =&gt; true | :document | :documents
}
```

One settings key a plugin takes, for the generated reference.

  * `key` — the stored key.
  * `type` — `:enum` (one of `values`), `:integer` (within `range`,
    inclusive), `:string`, `:boolean`, `:map` (an object of names to
    values) or `:list` (of `item`).
  * `required` — whether `init/1` refuses the settings without it.
  * `values` — the values an `:enum` takes.
  * `aliases` — other spellings an `:enum` accepts, each to the value it
    is read as (an older vocabulary).
  * `range` — `{min, max}` of an `:integer`.
  * `item` — what a `:list` holds: `:string`, objects told apart by
    one key (`t:schema_variants/0`), or objects all of one shape
    (`%{fields: [schema_field]}`).
  * `role` — what the value means to the exchange (`Plugin.Signature`).
  * `label` — the name the proxy's UI shows for the field where it
    names it apart from the plugin's own editor (a Configuration step's
    Plugin settings, the "Set by Configuration steps" list), in place of
    `key` (`field_label/1`); YAML and the Text layout keep the key.
  * `configurable` — whether a Configuration step may set the field for
    the requests it matches (see "Settings by match"): absent for the
    default, `false` for never, `:only` for only there.
  * `configurable_on` — `:request` or `:response`: on a directional
    plugin, a Configuration step fills the field only on steps of that
    side (`"direction"` `response`, or any other for `:request`), so a
    setting meant for After never reaches a step in Before.
  * `skips` — values of a configurable `:enum` that, set by a
    Configuration step, skip the step for the requests it matches: the
    step does not run, holds no body and records the outcome `skipped`.
    A step never stores one (`Plugin.CallAdapter.init/2` refuses it).
  * `skips_head`, `skips_body` — values of such an enum that skip only
    the head run or only the body run of a `checks_head: true` step.
    A step never stores one either.
  * `reveal` — whether the step may read the secret the field references
    in-process (`Plugin.Secret.reveal/3`).
  * `json_schema` — the field holds a JSON Schema (`:one`) or an object
    of names to JSON Schemas (`:by_key`). The host resolves a schema's
    `{"$ref": "registry:<name>"}` references to the tenant's stored
    schemas before `init/1` or `load/1` sees the settings
    (`Provisional.JsonSchema`, "Registry references"), so the plugin
    reads a schema that holds everything it refers to.
  * `api_definition` — `true`: the field holds the name of one of the
    tenant's API definitions. Before `init/1` or `load/1` sees the
    settings the host replaces the name with the definition as a step
    checks against it: `%{"name", "revision", "base_path",
    "operations"}`, the revision the traffic reads (the active release's
    on live traffic under release control, the stored one otherwise),
    `base_path` nil or a path such as `"/v1"`, and each operation
    `%{"method", "path", "parameters", "request_body", "responses"}`:
    `method` upper case, `path` as the document keys it (without the
    base path); `parameters` the path, query and header ones as
    `%{"name", "in", "required", "schema", "style", "explode"}`;
    `request_body` nil or `%{"required", "content"}`; `responses`
    `%{status => %{"content", "headers"}}`, a status as the document
    keys it (`"200"`, `"4XX"`, `"default"`), `headers` a list of
    `%{"name", "required", "schema"}`. A `content` is an object of media
    type to schema (nil where the document gives none). Every schema is
    self-contained: the document's own `#/components/schemas` and the
    registry's references are embedded, and a schema without `$schema`
    is given 2020-12, OpenAPI 3.1's. `:document`: the same name,
    replaced with the definition as a document that stands on its own,
    for a step that serves it: `%{"name", "revision", "base_path",
    "document"}`, `document` the OpenAPI 3.1 object with every
    registry schema it reaches under `components.schemas` and, when it
    gives no `servers`, the base path as its one server
    (`Plugin.Host.write_yaml/1` writes it as YAML). It is for writing:
    an `examples` map whose named examples have an order, which a map
    does not keep, comes as a `Jason.OrderedObject` in that order, and
    `Jason` and `Plugin.Host.write_yaml/1` both write it so. Where no tenant is at
    hand (a save's checks, the editor) `init/1` sees the name as stored.
    `:documents`: the field holds a list of names, or none (or `[]`)
    for every definition of the tenant, and the host replaces it with
    `%{"definitions" => [document]}`, each as `:document` gives it with
    the definition's `"hosts"` beside it, in the listed order (by name
    for all). Its version setting differs from the others': none reads
    each definition's newest release (`*`), a range the release it
    picks, and only `draft` the drafts. With all of them, a definition
    no release matches is left out, as is one that cannot be read
    (logged); a named one fails the step's preparation. Where no tenant
    is at hand `init/1` sees the list as stored.

# `schema_variants`

```elixir
@type schema_variants() :: %{
  tag: String.t(),
  variants: [
    %{
      :value =&gt; String.t(),
      :description =&gt; String.t(),
      :fields =&gt; [schema_field()],
      optional(:only) =&gt; %{required(String.t()) =&gt; [String.t()]}
    }
  ]
}
```

The objects of a list, told apart by the value of their `tag` key
(`"type"`, `"action"`). Each variant has its own fields besides the tag;
`only` limits it to settings whose other keys hold one of the listed
values (`%{"direction" => ["request"]}`), and is absent when the variant
is always taken.

# `settings`

```elixir
@type settings() :: map()
```

A step's settings as stored: string keys, JSON-safe.

# `writes`

```elixir
@type writes() :: [{Alternera.Plugin.Location.t(), term()}]
```

Locations a step writes (see "The exchange").

# `call`

```elixir
@callback call(Alternera.Plugin.Inputs.t(), opts(), context()) ::
  {:ok, writes()}
  | {:ok, writes(), map()}
  | {:ok, writes(), map(),
     %{optional(:outputs) =&gt; outputs(), optional(:directives) =&gt; map()}}
  | {:respond, answer(), writes()}
  | {:respond, answer(), writes(), map()}
  | {:hold, term()}
  | {:hold, term(), map()}
  | {:stream, iodata(), {module(), term()}, writes()}
  | {:refuse, String.t(), String.t(), pos_integer() | nil}
  | {:skip, atom() | String.t()}
  | {:return, term()}
  | {:return, term(), map()}
  | call_failure()
```

The step's work, inputs in and writes out (`Plugin.CallAdapter`): it reads
through `Plugin.Inputs` and returns the `{location, value}` pairs the
runner writes, an answer, a hold (a plugin with `leave/3`) or a refusal
(one of the types `refuses:` declares). Every plugin defines it; where
the step runs follows from its `Plugin.Signature`, and what the
signature cannot say from `use Alternera.Plugin`'s trait options.
A `streams: true` plugin may answer `{:stream, first, {filter, state},
writes}` instead (`Plugin.BodyFilter`).

# `calls`
*optional* 

```elixir
@callback calls(opts()) :: [String.t()]
```

# `describe`

```elixir
@callback describe(settings()) :: String.t()
```

# `editor`

```elixir
@callback editor() :: editor()
```

# `exchange_templates`
*optional* 

```elixir
@callback exchange_templates(settings()) :: [{label :: String.t(), text :: String.t()}]
```

# `guide`

```elixir
@callback guide() :: String.t() | nil
```

# `init`

```elixir
@callback init(settings()) :: {:ok, opts()} | {:error, [String.t()]}
```

# `leave`
*optional* 

```elixir
@callback leave(term(), Alternera.Plugin.Provisional.Hold.outcome(), map()) ::
  :ok
  | {:ok, map()}
  | {:ok, writes(), map()}
  | {:observe_body, {module(), term()}, map()}
  | {:observe_body, {module(), term()}, writes(), map()}
```

What `call/3` held, given back exactly once with how the exchange ended,
at the step's Close in After (`Plugin.CallAdapter`); `{:observe_body,
{module, state}, summary}` asks to see the response body as it leaves,
`module` a `Plugin.BodyObserver`. At the Close it may write the
response's headers besides (`{:ok, writes, summary}`, `{:observe_body,
observer, writes, summary}`), of the kinds its signature writes, after
the observer saw the head; a write of another kind is logged and dropped
with the others, and a hold given back anywhere else writes nothing. The context's `inputs` reads the
exchange as it stands at the Close (the response head, the request, the
variables), over the step's signature; a hold given back where the
exchange ended before its Close reads an empty exchange.
A plugin that defines it holds: its step stands in Before and runs in the
request head.

# `load`

```elixir
@callback load(settings()) ::
  {:ok, opts(), skipped :: [String.t()]} | {:error, [String.t()]}
```

# `memory_factor`
*optional* 

```elixir
@callback memory_factor(settings()) :: pos_integer()
```

# `migration_guides`

```elixir
@callback migration_guides() :: String.t() | nil
```

# `on_error`
*optional* 

```elixir
@callback on_error() :: :fail | :continue
```

# `output_keys`
*optional* 

```elixir
@callback output_keys(settings()) :: %{required(String.t()) =&gt; [String.t()]}
```

# `outputs`

```elixir
@callback outputs() :: [output()]
```

# `raises`
*optional* 

```elixir
@callback raises(settings()) :: raises()
```

# `recipes`

```elixir
@callback recipes() :: String.t() | nil
```

# `replay_recorded`
*optional* 

```elixir
@callback replay_recorded(opts(), exchange :: map()) ::
  {:ok, [{map(), term()}], map(), map()} | {:error, String.t()}
```

# `responses`
*optional* 

```elixir
@callback responses(settings()) :: responses()
```

# `save_warnings`
*optional* 

```elixir
@callback save_warnings(settings(), %{tenant_id: term()}) :: [String.t()]
```

Warnings about a step's settings that only the plugin's outside world
can give, shown when the pipeline is saved and never refusing it: a
plugin host's check of a document the step holds, say. `context` has
the pipeline's `:tenant_id`. Called on an enabled step whose settings
`init/1` takes, not on an import, with a deadline (`save_warnings/3`
below): a plugin that cannot answer in time says so in a warning of its
own rather than block the save.

# `settings_schema`

```elixir
@callback settings_schema() :: [schema_field()]
```

# `side_effect?`

```elixir
@callback side_effect?() :: boolean()
```

# `sides`

```elixir
@callback sides() :: [:request | :response | :on_error | :pivot]
```

# `signature`
*optional* 

```elixir
@callback signature(settings(), Alternera.Plugin.Signature.t()) ::
  Alternera.Plugin.Signature.t()
```

What a plugin adds to its derived `Plugin.Signature` for these stored
settings (`Plugin.Signature.extend/2` checks it): reads, writes and
templates its schema cannot name, a write it can name only at run time as
a part entry (`Plugin.Signature.part_entry/1`). It never removes what the
schema's roles declare and never changes the direction; the phase follows
from the result. Optional: without it the signature is the derived one.

# `templates`
*optional* 

```elixir
@callback templates(settings()) :: [{String.t(), :plain | :secret}]
```

# `user_doc`

```elixir
@callback user_doc() :: String.t() | nil
```

# `variable_readers`
*optional* 

```elixir
@callback variable_readers(tenant_id :: String.t()) :: [
  %{label: String.t(), variables: [String.t()]}
]
```

What of the plugin's own, outside any step, reads the tenant's variables:
each `%{label, variables}`, `label` naming it for a person ("Camel host
erp") and `variables` the names it reads as a template writes them
(`NAME`, `secret.NAME`). The tenant's Variables page marks them, and
asks before deleting one. A plugin host's entry is one such reader.

# `variables_changed`
*optional* 

```elixir
@callback variables_changed(tenant_id :: String.t()) :: :ok
```

The tenant's variables changed (one was saved or deleted), on any node:
called on every node, after the change committed, with the node's
variable cache already dropped. A plugin that holds values outside a
step's run (a plugin host started with them) takes the new ones. Must
return at once.

# `check_content_type`

```elixir
@spec check_content_type(term()) :: :ok | {:error, String.t()}
```

Checks a `Content-Type` value a body step sets: a non-empty string of
at most 256 bytes, one header value, so no CR, LF,
NUL or other control character (a tab included), and no leading or
trailing space. `:ok`, or `{:error, reason}` naming what is wrong (never
the value: it is the plugin's output).

# `configurable?`

```elixir
@spec configurable?(module(), String.t()) :: boolean()
```

Whether a Configuration step may set `key` of `module`'s settings.

# `configurable?`

```elixir
@spec configurable?(module(), String.t(), map() | nil) :: boolean()
```

Whether a Configuration step may set `key` on a step with stored `settings`.

# `configurable_fields`

```elixir
@spec configurable_fields(module()) :: [schema_field()]
```

The top-level fields of `module`'s `settings_schema/0` a Configuration
step may set (see "Settings by match"), in schema order.

# `configurable_fields`

```elixir
@spec configurable_fields(module(), map() | nil) :: [schema_field()]
```

The configurable fields a Configuration step fills on one step with
stored `settings`: `configurable_fields/1` without those marked
`configurable_on` the side the step is not on.

# `configuration_only_keys`

```elixir
@spec configuration_only_keys(module()) :: [String.t()]
```

The keys of `module`'s settings set only by a Configuration step (`configurable: :only`).

# `empty_setting?`

```elixir
@spec empty_setting?(term()) :: boolean()
```

Whether a setting's value counts as not set: absent (`nil`), `""`, `[]`
or `%{}`. The runner fills such a configurable field, and a required one
still empty after the fill fails the step `not_configured`.

# `field_label`

```elixir
@spec field_label(schema_field()) :: String.t()
```

The name the UI shows for a schema field: its `label`, else its `key`.

# `field_label`

```elixir
@spec field_label(module(), String.t()) :: String.t()
```

`field_label/1` of `module`'s field `key`, or `key` when it has none.

# `json_doc?`

```elixir
@spec json_doc?(module(), map()) :: boolean()
```

Whether a step of `module` with `opts` reads and edits its own body only
through the body's JSON document: a plugin declared `json_doc: true`
whose `json_doc?/1`, when it has one, says so for these opts.

# `load_via_init`

```elixir
@spec load_via_init({:ok, opts()} | {:error, [String.t()]}) ::
  {:ok, opts(), [String.t()]} | {:error, [String.t()]}
```

`load/1`'s default: the result of `init/1` with nothing skipped. The
injected default calls `init/1` through `apply/3`, so a plugin whose
`init/1` only ever succeeds (or only ever fails or raises) is not flagged
by the type checker for a clause that can never match.

# `part_skip_values`

```elixir
@spec part_skip_values(module()) :: %{
  required(String.t()) =&gt; %{required(String.t()) =&gt; :head | :body}
}
```

The values of `module`'s fields that skip one run of a `checks_head: true`
step when a Configuration step sets them (`skips_head`, `skips_body`),
as `%{key => %{value => :head | :body}}`; `%{}` for none.

# `save_warnings`

```elixir
@spec save_warnings(module(), settings(), %{tenant_id: term()}) :: [String.t()]
```

`module`'s `c:save_warnings/2` for a step's settings, or `[]` when it has
none. A plugin that raises is logged and gives none.

# `sdk_version`

```elixir
@spec sdk_version() :: pos_integer()
```

The major version of the plugin contract this SDK implements.

# `skip_errors`

```elixir
@spec skip_errors(module(), term()) :: [String.t()]
```

Messages for a skip value (`skips`, `skips_head`, `skips_body`) a step's
stored `settings` hold: only a Configuration step sets one.

# `skip_values`

```elixir
@spec skip_values(module()) :: %{required(String.t()) =&gt; [String.t()]}
```

The values of `module`'s fields that skip a step when a Configuration
step sets them (`skips`), as `%{key => [value]}`; `%{}` for none.

# `streams`

```elixir
@spec streams(module(), map()) :: true | {:holds, String.t()}
```

Whether a step of `module` with `opts` streams its body: `true`, or
`{:holds, reason}`; `{:holds, "not streamable"}` for a plugin not
declared `streams: true`, and the reason its `stream_hold/1` names for
one that is (`Plugin.CallAdapter.streams/2`).

# `variable_readers`

```elixir
@spec variable_readers(module(), String.t()) :: [
  %{label: String.t(), variables: [String.t()]}
]
```

`module`'s `c:variable_readers/1` for the tenant, `[]` when it has none.
A plugin that raises is logged and gives none.

# `variables_changed`

```elixir
@spec variables_changed(module(), String.t()) :: :ok
```

Tells `module` the tenant's variables changed (`c:variables_changed/1`),
when it wants to know. A plugin that raises is logged.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
