Skip to main content

openlark_platform/
lib.rs

1//! # OpenLark 平台服务模块
2//!
3//! OpenLark SDK 的平台服务模块,提供飞书平台管理相关 API 的完整访问。
4//!
5//! ## 功能特性
6//!
7//! - **应用引擎**: 应用管理、多租户、应用市场集成
8//! - **目录服务**: 用户搜索、组织目录、人员查找
9//! - **系统管理**: 系统配置、后台管理、平台工具
10//!
11//! ## 模块组织
12//!
13//! 本模块按业务域(bizTag)组织:
14//! - `app_engine` - 应用引擎相关 API (37 APIs)
15//! - `directory` - 目录服务相关 API (21 APIs)
16//! - `admin` - 系统管理相关 API (14 APIs)
17//!
18//! ## 使用示例
19//!
20//! ```rust,no_run
21//! use openlark_platform::PlatformService;
22//! use openlark_core::prelude::Config;
23//!
24//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
25//! // 使用 builder 模式创建配置
26//! let config = Config::builder()
27//!     .app_id("app_id")
28//!     .app_secret("app_secret")
29//!     .build();
30//!
31//! let platform_service = PlatformService::new(config)?;
32//!
33//! // 具体功能请参考各个子模块的文档
34//! # Ok(())
35//! # }
36//! ```
37
38#![allow(missing_docs)]
39#![allow(clippy::module_inception)]
40
41mod service;
42
43// 通用模块
44pub mod common;
45
46// 业务域模块
47#[cfg(feature = "app-engine")]
48pub mod app_engine;
49
50#[cfg(feature = "directory")]
51pub mod directory;
52
53#[cfg(feature = "admin")]
54pub mod admin;
55
56#[cfg(feature = "mdm")]
57pub mod mdm;
58
59#[cfg(feature = "tenant")]
60pub mod tenant;
61
62#[cfg(feature = "trust_party")]
63pub mod trust_party;
64
65// Prelude 模块
66pub mod prelude;
67
68// 重新导出核心服务
69pub use service::PlatformService;
70
71// 配置类型
72pub use openlark_core::config::Config;
73
74/// 平台服务模块版本信息
75pub const VERSION: &str = env!("CARGO_PKG_VERSION");
76
77/// 平台服务配置别名
78pub type PlatformConfig = Config;
79
80#[cfg(test)]
81mod tests {
82    use crate::VERSION;
83
84    #[test]
85    fn test_version() {
86        assert!(!VERSION.is_empty());
87    }
88
89    #[test]
90    fn test_module_composition() {
91        // 验证模块组织正确
92        assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
93    }
94}
95
96#[cfg(test)]
97mod service_tests {
98    use super::*;
99    use openlark_core::constants::AppType;
100
101    fn create_test_config() -> Config {
102        Config::builder()
103            .app_id("test_app")
104            .app_secret("test_secret")
105            .app_type(AppType::SelfBuild)
106            .build()
107    }
108
109    #[test]
110    fn test_platform_service_creation() {
111        let config = create_test_config();
112        let service = PlatformService::new(config).unwrap();
113        assert!(service.config().app_id() == "test_app");
114    }
115
116    #[test]
117    fn test_platform_service_clone() {
118        let config = create_test_config();
119        let service = PlatformService::new(config).unwrap();
120        let cloned = service.clone();
121        assert!(cloned.config().app_id() == "test_app");
122    }
123
124    #[test]
125    fn test_platform_config_alias() {
126        let config: PlatformConfig = Config::builder()
127            .app_id("test_app")
128            .app_secret("test_secret")
129            .build();
130        assert!(config.app_id() == "test_app");
131    }
132
133    #[cfg(feature = "app-engine")]
134    #[test]
135    fn test_platform_service_app_engine() {
136        let config = create_test_config();
137        let service = PlatformService::new(config).unwrap();
138        let _app_engine = service.app_engine();
139    }
140
141    #[cfg(feature = "directory")]
142    #[test]
143    fn test_platform_service_directory() {
144        let config = create_test_config();
145        let service = PlatformService::new(config).unwrap();
146        let _directory = service.directory();
147    }
148
149    #[cfg(feature = "admin")]
150    #[test]
151    fn test_platform_service_admin() {
152        let config = create_test_config();
153        let service = PlatformService::new(config).unwrap();
154        let _admin = service.admin();
155    }
156}