Bazaar.Protocol.Transformer (Bazaar v0.3.0)

Copy Markdown View Source

Transforms requests and responses between UCP and ACP protocol formats.

Internal Format

Bazaar uses UCP as its internal/canonical format. Handlers always receive and return data in UCP format. This module transforms ACP requests into UCP format before they reach the handler, and transforms UCP responses back to ACP format before sending to ACP clients.

ACP Request → transform_request/2 → Handler (UCP) → transform_response/2 → ACP Response
UCP Request → Handler (UCP) → UCP Response (no transformation)

Transformations

This module handles:

  • Address fields (street_address ↔ line_one, etc.)
  • Status values (incomplete ↔ not_ready_for_payment, etc.)
  • Item/line_item structure differences

Address Field Mappings

UCP (internal)ACP
street_addressline_one
extended_addressline_two
address_localitycity
address_regionstate
address_countrycountry
postal_codepostal_code (unchanged)

Item Mappings

UCP (internal)ACP
itemsline_items
skuproduct.id
nameproduct.name
pricebase_amount

Summary

Functions

Transforms address fields between UCP and ACP formats.

Transforms an incoming request from ACP format to internal (UCP) format.

Transforms an outgoing response from internal (UCP) format to protocol format.

Functions

transform_address(address, arg2)

@spec transform_address(map() | nil, :acp_to_ucp | :ucp_to_acp) :: map() | nil

Transforms address fields between UCP and ACP formats.

Direction

  • :acp_to_ucp - Transforms ACP fields (line_one, city) to UCP fields (street_address, address_locality)
  • :ucp_to_acp - Transforms UCP fields to ACP fields

transform_request(request, atom)

@spec transform_request(map(), Bazaar.Protocol.t()) :: {:ok, map()}

Transforms an incoming request from ACP format to internal (UCP) format.

For :ucp protocol, returns the request unchanged. For :acp protocol, transforms address fields and line_items.

transform_response(response, atom)

@spec transform_response(map(), Bazaar.Protocol.t()) :: {:ok, map()}

Transforms an outgoing response from internal (UCP) format to protocol format.

For :ucp protocol, returns the response unchanged. For :acp protocol, transforms status, address fields, and items.