PhoenixKit.API.Config (phoenix_kit v2.63.0)

Copy Markdown View Source

Settings accessors for the shop API.

Every function reads a core setting through PhoenixKit.Settings and applies a safe default. The API is off by default and fails closed: a switch is on only when its setting reads exactly "true", so a missing row, an unreadable database, an unexpected value or a Settings error all count as off.

Settings

KeyDefault
api_admin_enabledfalse
api_public_enabledfalse
api_disabled_tools"" (newline separated tool names)
api_mcp_allowed_origins"" (newline separated origins)
api_admin_preauth_fail_per_min20
api_admin_rate_per_min600
api_public_cart_rate_per_min120
api_public_ip_rate_per_min300
api_public_cart_rows_per_ip_hour120
api_public_cart_rows_global_hour2000

List settings are stored as newline-separated strings: PhoenixKit.Settings has no list setter and a JSON setting cannot hold a bare list. Use encode_list/1 when writing one and parse_list/1 when reading one.

Summary

Functions

Whether the admin API (/api/admin/v1) is switched on. Fails closed.

Tool names the install has hidden (api_disabled_tools). For display only: a list that cannot be read is [] here, so request paths (PhoenixKit.API.Registry) use fetch_disabled_tools/0, which does not treat it as "nothing is hidden".

Joins a list into the newline-separated form the list settings are stored in.

Tool names the install has hidden (api_disabled_tools), telling a list that is empty from one that could not be read at all (a read that raises or exits).

Reads an integer setting.

Largest request body the API accepts, in bytes (2 MB).

Extra origins allowed to call the MCP endpoint (api_mcp_allowed_origins).

Splits a newline-separated setting value into a list.

Whether the public API (/api/shop/v1, MCP) is switched on. Fails closed.

The rate-limit settings as one map.

Functions

admin_enabled?()

@spec admin_enabled?() :: boolean()

Whether the admin API (/api/admin/v1) is switched on. Fails closed.

disabled_tools()

@spec disabled_tools() :: [String.t()]

Tool names the install has hidden (api_disabled_tools). For display only: a list that cannot be read is [] here, so request paths (PhoenixKit.API.Registry) use fetch_disabled_tools/0, which does not treat it as "nothing is hidden".

encode_list(items)

@spec encode_list([String.t()]) :: String.t()

Joins a list into the newline-separated form the list settings are stored in.

fetch_disabled_tools()

@spec fetch_disabled_tools() :: {:ok, [String.t()]} | :unreadable

Tool names the install has hidden (api_disabled_tools), telling a list that is empty from one that could not be read at all (a read that raises or exits).

The tool registry fails closed on :unreadable: a tool the admin switched off must not come back because of a settings problem. This is the one reader of the setting.

int(key, default)

@spec int(String.t(), integer()) :: integer()

Reads an integer setting.

Returns default when the setting is missing, is not a whole number ("12abc" and "1.5" are not read by their prefix), is zero or negative, or cannot be read. Every API integer setting is a positive limit, and a zero limit would silently refuse every request, so a non-positive value is treated as unset.

max_body_bytes()

@spec max_body_bytes() :: 2_097_152

Largest request body the API accepts, in bytes (2 MB).

mcp_allowed_origins()

@spec mcp_allowed_origins() :: [String.t()]

Extra origins allowed to call the MCP endpoint (api_mcp_allowed_origins).

parse_list(value)

@spec parse_list(String.t() | nil) :: [String.t()]

Splits a newline-separated setting value into a list.

Lines are trimmed; blank lines and duplicates are dropped. nil is [].

public_enabled?()

@spec public_enabled?() :: boolean()

Whether the public API (/api/shop/v1, MCP) is switched on. Fails closed.

rate_limits()

@spec rate_limits() :: %{
  preauth_fail_per_min: pos_integer(),
  admin_per_min: pos_integer(),
  public_cart_per_min: pos_integer(),
  public_ip_per_min: pos_integer(),
  cart_rows_ip_hour: pos_integer(),
  cart_rows_global_hour: pos_integer()
}

The rate-limit settings as one map.

*_per_min limits count over a 60 second window and *_hour limits over a one hour window (see PhoenixKit.API.RateLimit).