Reusable Plug/Phoenix adapter for idempotent controller actions.
This module is host-app agnostic. Supply app-specific callbacks via options:
:idempotency_module(required): module implementingrequest_hash/1,claim_request/4, andcomplete_request/4:render_error_fun(optional):(conn, status, detail, metadata) -> conn
Summary
Types
@type error_spec() :: %{ :status => response_status(), :detail => String.t(), optional(:code) => String.t(), optional(:metadata) => map() }
@type persist_response_fun() :: (Plug.Conn.t(), term() -> persist_result())
@type persist_result() :: {:ok, String.t(), pos_integer(), map()} | {:error, term()}
@type render_error_fun() :: (Plug.Conn.t(), response_status(), String.t(), map() -> Plug.Conn.t())
@type replay_response_fun() :: (Plug.Conn.t(), term() -> {:ok, Plug.Conn.t()} | :default | {:error, term()})
Functions
@spec maybe_run(Plug.Conn.t(), keyword(), (Plug.Conn.t() -> Plug.Conn.t())) :: {:handled, Plug.Conn.t()} | {:no_key, Plug.Conn.t()}
@spec maybe_run_for_user( Plug.Conn.t(), pos_integer(), String.t(), term(), (Plug.Conn.t() -> Plug.Conn.t()), keyword() ) :: {:handled, Plug.Conn.t()} | {:no_key, Plug.Conn.t()}