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::{export_plugin, prelude::*, Result as PluginCoreResult};
15//! use std::collections::HashMap;
16//!
17//! #[derive(Debug, Default)]
18//! pub struct MyPlugin;
19//!
20//! #[async_trait]
21//! impl AuthPlugin for MyPlugin {
22//!     fn capabilities(&self) -> PluginCapabilities {
23//!         PluginCapabilities::default()
24//!     }
25//!
26//!     async fn initialize(&self, _config: &AuthPluginConfig) -> PluginCoreResult<()> {
27//!         Ok(())
28//!     }
29//!
30//!     async fn authenticate(
31//!         &self,
32//!         _context: &PluginContext,
33//!         _request: &AuthRequest,
34//!         _config: &AuthPluginConfig,
35//!     ) -> PluginCoreResult<PluginResult<AuthResponse>> {
36//!         let identity = UserIdentity::new("user123");
37//!         let response = AuthResponse::success(identity, HashMap::new());
38//!         Ok(PluginResult::success(response, 0))
39//!     }
40//!
41//!     fn validate_config(&self, _config: &AuthPluginConfig) -> PluginCoreResult<()> {
42//!         Ok(())
43//!     }
44//!
45//!     fn supported_schemes(&self) -> Vec<String> {
46//!         vec!["basic".to_string()]
47//!     }
48//!
49//!     async fn cleanup(&self) -> PluginCoreResult<()> {
50//!         Ok(())
51//!     }
52//! }
53//!
54//! export_plugin!(MyPlugin);
55//! ```
56
57pub mod builders;
58pub mod macros;
59pub mod prelude;
60
61#[cfg(feature = "testing")]
62pub mod testing;
63
64// Re-export core plugin types
65pub use mockforge_plugin_core::*;
66
67/// SDK version
68pub const SDK_VERSION: &str = env!("CARGO_PKG_VERSION");
69
70/// Recommended WASM target
71pub const WASM_TARGET: &str = "wasm32-wasi";
72
73/// Plugin SDK result type
74pub type SdkResult<T> = std::result::Result<T, SdkError>;
75
76/// SDK-specific errors
77#[derive(Debug, thiserror::Error)]
78pub enum SdkError {
79    /// Plugin configuration error
80    #[error("Plugin configuration error: {0}")]
81    ConfigError(String),
82
83    /// Manifest generation error
84    #[error("Manifest generation error: {0}")]
85    ManifestError(String),
86
87    /// Build error
88    #[error("Build error: {0}")]
89    BuildError(String),
90
91    /// Template error
92    #[error("Template error: {0}")]
93    TemplateError(String),
94
95    /// IO error
96    #[error("IO error: {0}")]
97    IoError(#[from] std::io::Error),
98
99    /// Serialization error
100    #[error("Serialization error: {0}")]
101    SerializationError(String),
102}
103
104impl SdkError {
105    /// Create a configuration error
106    pub fn config<S: Into<String>>(msg: S) -> Self {
107        Self::ConfigError(msg.into())
108    }
109
110    /// Create a manifest error
111    pub fn manifest<S: Into<String>>(msg: S) -> Self {
112        Self::ManifestError(msg.into())
113    }
114
115    /// Create a build error
116    pub fn build<S: Into<String>>(msg: S) -> Self {
117        Self::BuildError(msg.into())
118    }
119}