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

Provisional: moved here from the Request step for plugins that reach
outside the proxy, and a change to it needs a changelog line but no new
major (`docs/USER_PLUGINS_DESIGN.md`). The namespace has nothing to do with
the context's `:provisional?` key.

What a step that reaches outside the proxy (`side_effect?/0`) gives the
pipeline editor so a played run can be saved and fed to later previews:

  * `fingerprint/1`, a keyed hash of the resolved call, so a saved output
    can be told stale when the step would now call something else;
  * `copy_body/1`, a body as the step's record (`:record` extra) shows it:
    text cut on a whole UTF-8 character, or base64, with its size and
    whether it was cut.

# `part`

```elixir
@type part() ::
  String.t() | nil | [{String.t(), String.t()}] | Alternera.Plugin.Body.t()
```

One part of a call: text, nil, `{name, value}` pairs, or a held body.

# `copy_body`

```elixir
@spec copy_body(binary() | Alternera.Plugin.Body.t() | nil) :: %{
  required(String.t()) =&gt; term()
}
```

`body` (a binary, a held body or nil) as a record shows it, JSON-ready:
`%{"text" => …}` cut at the application's copy limit on a whole UTF-8
character, or `%{"base64" => …}` of at most that many bytes when it is not
text, each with `"size"` (the whole body's) and `"truncated"`. A body in a
file is read only as far as the copy keeps.

# `cut`

```elixir
@spec cut(binary(), pos_integer()) :: binary()
```

`body` cut at `max` bytes on a whole UTF-8 character, unmarked: when the
byte after the cut continues a character (10xxxxxx), the cut moves back to
where that character starts, at most three bytes.

# `fingerprint`

```elixir
@spec fingerprint([part()]) :: String.t()
```

A fingerprint of a resolved call from its parts, `"hmac-sha256:"` and
hex: each part written length-prefixed in order, so it depends only on the
values and never on the runtime's term encoding (a saved output stays
current across an OTP upgrade). The parts can hold secrets (a resolved
header value), so it is an HMAC keyed with the application's secret: a
stored fingerprint cannot confirm a guessed secret without that key.

A held body (`Plugin.Body`) hashes as its bytes would, read from its file a
chunk at a time, so a body in memory and the same body in a file have one
fingerprint. Equal fingerprints mean the same call.

---

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