mockforge_plugin_sdk/lib.rs
1//! # MockForge Plugin SDK
2//!
3//! Official SDK for developing MockForge plugins with ease.
4//!
5//! This SDK provides:
6//! - Helper macros for plugin creation
7//! - Builder patterns for manifests
8//! - Testing utilities
9//! - Type-safe plugin development
10//!
11//! ## Quick Start
12//!
13//! ```rust,no_run
14//! use mockforge_plugin_sdk::prelude::*;
15//!
16//! #[derive(Debug)]
17//! pub struct MyPlugin;
18//!
19//! #[async_trait]
20//! impl AuthPlugin for MyPlugin {
21//! async fn authenticate(
22//! &self,
23//! context: &PluginContext,
24//! credentials: &AuthCredentials,
25//! ) -> PluginResult<AuthResult> {
26//! Ok(AuthResult::authenticated("user123"))
27//! }
28//! }
29//!
30//! export_plugin!(MyPlugin);
31//! ```
32
33pub mod builders;
34pub mod macros;
35pub mod prelude;
36
37#[cfg(feature = "testing")]
38pub mod testing;
39
40// Re-export core plugin types
41pub use mockforge_plugin_core::*;
42
43/// SDK version
44pub const SDK_VERSION: &str = env!("CARGO_PKG_VERSION");
45
46/// Recommended WASM target
47pub const WASM_TARGET: &str = "wasm32-wasi";
48
49/// Plugin SDK result type
50pub type SdkResult<T> = std::result::Result<T, SdkError>;
51
52/// SDK-specific errors
53#[derive(Debug, thiserror::Error)]
54pub enum SdkError {
55 /// Plugin configuration error
56 #[error("Plugin configuration error: {0}")]
57 ConfigError(String),
58
59 /// Manifest generation error
60 #[error("Manifest generation error: {0}")]
61 ManifestError(String),
62
63 /// Build error
64 #[error("Build error: {0}")]
65 BuildError(String),
66
67 /// Template error
68 #[error("Template error: {0}")]
69 TemplateError(String),
70
71 /// IO error
72 #[error("IO error: {0}")]
73 IoError(#[from] std::io::Error),
74
75 /// Serialization error
76 #[error("Serialization error: {0}")]
77 SerializationError(String),
78}
79
80impl SdkError {
81 /// Create a configuration error
82 pub fn config<S: Into<String>>(msg: S) -> Self {
83 Self::ConfigError(msg.into())
84 }
85
86 /// Create a manifest error
87 pub fn manifest<S: Into<String>>(msg: S) -> Self {
88 Self::ManifestError(msg.into())
89 }
90
91 /// Create a build error
92 pub fn build<S: Into<String>>(msg: S) -> Self {
93 Self::BuildError(msg.into())
94 }
95}