MPP.Client.SelectionPolicy (mpp v0.16.0)

Copy Markdown View Source

Transport-neutral challenge selection and ordering.

HTTP (MPP.Client.Req) and MCP client orchestration share this policy so challenge ranking is not owned by any one wire transport. The default preserves server-advertised order — first MultiProvider-supported challenge wins — matching mppx client orchestration and the mpp-rs provider default (select_challenge keeps caller order).

Policies

  • :server_order — keep the server's offer order (default)
  • {:accept_payment, entries} — reorder by Accept-Payment preferences
  • an arity-1 function — receives the supported challenges and returns them filtered/reordered; the first remaining challenge is selected

API Functions

FunctionArityDescriptionParam Kinds
select3Pick a challenge using a selection policy and MultiProvider support.challenges: value, multi: value, policy: value
default0Return the default policy (:server_order).-

Summary

Functions

Return the default policy (:server_order).

Pick one supported challenge according to policy.

Types

t()

@type t() ::
  :server_order
  | {:accept_payment, [MPP.AcceptPayment.entry()]}
  | ([MPP.Challenge.t()] -> [MPP.Challenge.t()])

Functions

default()

@spec default() :: :server_order

Return the default policy (:server_order).

select(challenges, multi, policy \\ default())

@spec select([MPP.Challenge.t()], MPP.Client.MultiProvider.t(), t()) ::
  {:ok, MPP.Challenge.t()} | {:error, :no_supported_challenge}

Pick one supported challenge according to policy.

Unsupported challenges are dropped first. The policy then orders what remains and the first entry is selected. Returns {:error, :no_supported_challenge} when nothing is left, including the empty-list case.