fulltime_plugin_api/lib.rs
1//! Canonical league-data schema, data-provider WIT interface, and plugin manifest format
2//! shared by the `FullTime` plugin host and every data-provider plugin.
3//!
4//! Neither the host nor any plugin owns this contract: it is versioned and published
5//! independently of both so the host and plugins can evolve without a lockstep release.
6//! See `openspec/changes/define-league-data-contract/proposal.md` for the full rationale.
7//!
8//! # Examples
9//!
10//! ```
11//! use fulltime_plugin_api::{Manifest, SCHEMA_VERSION};
12//!
13//! let source = include_str!("../tests/fixtures/manifest.toml");
14//! let manifest = Manifest::parse(source)?;
15//! assert!(SCHEMA_VERSION.accepts(manifest.schema_version));
16//! # Ok::<(), Box<dyn std::error::Error>>(())
17//! ```
18
19#![warn(clippy::pedantic, clippy::nursery, missing_docs, rust_2018_idioms)]
20#![deny(unsafe_op_in_unsafe_fn)]
21#![forbid(unsafe_code)]
22
23mod bindings;
24mod manifest;
25mod version;
26
27pub use manifest::{Manifest, ManifestError, ManifestField};
28pub use version::{ParseVersionError, Version};
29
30pub use bindings::fulltime::plugin_api::errors::*;
31pub use bindings::fulltime::plugin_api::types::*;
32
33pub use bindings::export;
34pub use bindings::exports;
35pub use bindings::exports::fulltime::plugin_api::data_provider::Guest;
36
37/// Fetches the response body for an HTTP GET request to `url`, via the host's `fetch`
38/// capability.
39///
40/// This only links and behaves correctly when compiled as part of a `wasm32` component
41/// instantiated by a host implementing the `host` interface's `fetch` function (see
42/// `wit/data-provider.wit`) — it has no behavior of its own independent of that generated
43/// import. Callers should gate use of it behind `#[cfg(target_arch = "wasm32")]` and keep
44/// a separate, injectable seam for native unit/integration tests.
45///
46/// # Errors
47/// Returns [`NetworkFailure`] if the host reports the request failed (network error,
48/// non-2xx status, or a plugin-manifest network-host restriction).
49pub fn host_fetch(url: &str) -> Result<Vec<u8>, NetworkFailure> {
50 bindings::fulltime::plugin_api::host::fetch(url)
51}
52
53/// Current version of the canonical `league-data-schema` (see [`types`
54/// interface](https://github.com/pilgrimagesoftware/fulltime-plugin-api/blob/develop/wit/data-provider.wit)).
55///
56/// A plugin declaring a `schema_version` in its manifest is compatible with a host running
57/// this version when `SCHEMA_VERSION.accepts(plugin_schema_version)` is `true` — see
58/// [`Version::accepts`].
59pub const SCHEMA_VERSION: Version = Version::new(1, 0);
60
61/// Current version of the `data-provider` WIT interface.
62///
63/// A plugin declaring an `interface_version` in its manifest is compatible with a host
64/// running this version when `INTERFACE_VERSION.accepts(plugin_interface_version)` is
65/// `true` — see [`Version::accepts`].
66pub const INTERFACE_VERSION: Version = Version::new(2, 0);