mundane.api.set_loader¶
Fetch, allowlist, validate, and snapshot external card sets — the only HTTP-aware card code.
The engine never reaches the network; this module does. Given a list of set URLs it: (1) allowlists
each (only the mundane-cards raw origin), (2) fetches with hardening (https, timeout, no
redirects, size cap, content-type check), (3) validates each body against the vendored schema,
(4) builds the cards via the engine loader, rejecting duplicate composed ids, and (5) returns the
resolved pool plus a JSON-ready snapshot with a content hash so an exported game replays
self-contained. On any failure it raises before the caller stores anything.
Attributes¶
Fetches the raw bytes of a set at a URL. Injectable so tests can serve a fixture offline. |
Exceptions¶
A requested set URL is not on the allowlist. Maps to HTTP 422. |
|
A set could not be fetched (network, timeout, status, content-type, or size). Maps to 502. |
|
A fetched set was not valid JSON or failed schema validation. Maps to HTTP 422. |
Classes¶
The engine-facing pool plus the serialisable snapshot (resolved cards + content hash). |
Functions¶
|
Reject |
|
Fetch |
|
Allowlist, fetch, validate, and build the combined pool + snapshot for |
Module Contents¶
- mundane.api.set_loader.DEFAULT_SET_URLS: tuple[str, Ellipsis] = ('https://raw.githubusercontent.com/letsbuilda/mundane-cards/main/sets/core.json',)[source]¶
- mundane.api.set_loader.Fetcher[source]¶
Fetches the raw bytes of a set at a URL. Injectable so tests can serve a fixture offline.
- exception mundane.api.set_loader.SetURLNotAllowedError[source]¶
Bases:
ExceptionA requested set URL is not on the allowlist. Maps to HTTP 422.
- exception mundane.api.set_loader.SetFetchError[source]¶
Bases:
ExceptionA set could not be fetched (network, timeout, status, content-type, or size). Maps to 502.
- exception mundane.api.set_loader.SetSchemaError[source]¶
Bases:
ExceptionA fetched set was not valid JSON or failed schema validation. Maps to HTTP 422.
- class mundane.api.set_loader.ResolvedPool[source]¶
The engine-facing pool plus the serialisable snapshot (resolved cards + content hash).
- cards: dict[str, mundane.engine.state.Card][source]¶
- mundane.api.set_loader._check_allowed(url: str, host: str, prefix: str) None[source]¶
Reject
urlunless it is https, exactly onhost, and underprefix(parsed, not substring).
- mundane.api.set_loader.default_fetch(url: str) bytes[source]¶
Fetch
urlwith hardening: a hard timeout, no redirects, a size cap, and a content-type check.
- mundane.api.set_loader.load_sets(set_urls: collections.abc.Sequence[str], *, fetch: Fetcher = default_fetch, allowlist_host: str = ALLOWLIST_HOST, allowlist_prefix: str = ALLOWLIST_PATH_PREFIX) ResolvedPool[source]¶
Allowlist, fetch, validate, and build the combined pool + snapshot for
set_urls.Raises before returning on any problem:
SetURLNotAllowedError/SetSchemaError/ engineUnknownEffectError/InvalidEffectParamsError/DuplicateCardError(all 422 at the API), orSetFetchError(502).