Bazaar.Message (Bazaar v0.3.0)

Copy Markdown View Source

Business logic helpers for UCP Messages (errors, warnings, info).

Messages communicate session state to agents and buyers. Each message has a type discriminator that determines which fields are applicable.

Message Types

  • :error - Indicates a problem that prevents checkout completion
  • :warning - Indicates a potential issue that may need attention
  • :info - Provides informational context

Example

# Error message
Bazaar.Message.error(%{
  "code" => "out_of_stock",
  "content" => "Item SKU-123 is no longer available",
  "severity" => "recoverable",
  "path" => "$.line_items[0]"
})

# Warning message
Bazaar.Message.warning(%{
  "code" => "price_changed",
  "content" => "Price has increased since item was added"
})

Summary

Functions

Creates an error message changeset.

Creates an info message changeset.

Parses a message from params, determining type from the type field.

Returns the severity values.

Returns the message type values.

Validates a list of messages, routing each to the appropriate schema.

Creates a warning message changeset.

Returns well-known error codes from the UCP spec.

Functions

error(params \\ %{})

Creates an error message changeset.

Required Fields

  • code - Error code identifier
  • content - User-facing error description
  • severity - Resolution responsibility level

info(params \\ %{})

Creates an info message changeset.

Required Fields

  • code - Info code identifier
  • content - User-facing info description

parse(params)

Parses a message from params, determining type from the type field.

This implements oneOf-like behavior by routing to the appropriate schema based on the discriminator field.

severity_values()

Returns the severity values.

type_values()

Returns the message type values.

validate_messages(messages)

Validates a list of messages, routing each to the appropriate schema.

Returns {:ok, messages} if all valid, or {:error, errors} with details.

warning(params \\ %{})

Creates a warning message changeset.

Required Fields

  • code - Warning code identifier
  • content - User-facing warning description

well_known_codes()

Returns well-known error codes from the UCP spec.