# `Spectre.Event.Envelope`
[🔗](https://github.com/elchemista/spectre/blob/0.3.0/lib/spectre/event/envelope.ex#L1)

Portable event envelope whose owner is fixed at Instance admission time.

Origins are evidence; they never select the Definition that consumes an
event. A continuation owns replies, policy answers and operational progress.
Events without a continuation are owned by the active Definition after the
admission and schema-compatibility checks have succeeded.

# `continuation_ref`

```elixir
@type continuation_ref() :: Spectre.Run.Ref.t() | Spectre.Operation.Ref.t() | nil
```

# `event_class`

```elixir
@type event_class() ::
  :input
  | :reply
  | :policy_answer
  | :flow_progress
  | :flow_completion
  | :work_progress
  | :work_completion
  | :vigil_progress
  | :vigil_completion
  | :global
```

# `status`

```elixir
@type status() :: :pending | :admitted | :quarantined
```

# `t`

```elixir
@type t() :: %Spectre.Event.Envelope{
  admission_receipt: String.t() | nil,
  admission_revision: pos_integer() | nil,
  admitted_activation_generation: non_neg_integer() | nil,
  admitted_at: non_neg_integer() | nil,
  authenticity: map(),
  authority_epoch: non_neg_integer() | nil,
  causation_id: String.t() | nil,
  class_ref: String.t(),
  continuation_ref: continuation_ref(),
  correlation_id: String.t(),
  emitted_at: non_neg_integer(),
  event_class: event_class(),
  id: String.t(),
  origin_definition_ref: Spectre.Definition.Ref.t() | nil,
  owner_definition_ref: Spectre.Definition.Ref.t() | nil,
  owner_fencing_token: pos_integer() | nil,
  payload: term(),
  payload_schema_ref: String.t(),
  provenance: map(),
  quarantine_reason: term(),
  schema_version: pos_integer(),
  status: status()
}
```

# `admit`

```elixir
@spec admit(t(), map() | keyword()) :: {:ok, t()} | {:error, term()}
```

Applies the sequencer-owned admission fields to a pending envelope.

# `admitted?`

```elixir
@spec admitted?(t()) :: boolean()
```

Returns true only after the Instance sequencer admitted or quarantined the event.

# `classes`

```elixir
@spec classes() :: [event_class()]
```

Returns the event classes understood by this release.

# `decode`

```elixir
@spec decode(binary()) :: {:ok, t()} | {:error, term()}
```

Decodes and validates canonical Event Envelope bytes.

# `encode`

```elixir
@spec encode(t()) :: {:ok, binary()} | {:error, term()}
```

Encodes an envelope into canonical portable bytes.

# `from_data`

```elixir
@spec from_data(map()) :: {:ok, t()} | {:error, term()}
```

Restores and verifies an envelope from decoded canonical data.

# `intent_digest`

```elixir
@spec intent_digest(t()) :: String.t()
```

Returns a digest of fields supplied before Instance admission.

# `new`

```elixir
@spec new(t() | map() | keyword()) :: {:ok, t()} | {:error, term()}
```

Builds and validates a pending or admitted event envelope.

# `new!`

```elixir
@spec new!(t() | map() | keyword()) :: t()
```

Builds an envelope or raises with its stable validation reason.

# `schema_version`

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

Returns the Event Envelope schema version.

# `to_data`

```elixir
@spec to_data(t()) :: map()
```

Returns portable canonical data.

---

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