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//! - `spark` - 妙搭平台相关 API (1 API)
18//!
19//! ## 使用示例
20//!
21//! ```rust,no_run
22//! use openlark_platform::PlatformService;
23//! use openlark_core::prelude::Config;
24//!
25//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
26//! // 使用 builder 模式创建配置
27//! let config = Config::builder()
28//!     .app_id("app_id")
29//!     .app_secret("app_secret")
30//!     .build();
31//!
32//! let platform_service = PlatformService::new(config)?;
33//!
34//! // 具体功能请参考各个子模块的文档
35//! # Ok(())
36//! # }
37//! ```
38
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#[cfg(feature = "spark")]
66pub mod spark;
67
68// Prelude 模块
69pub mod prelude;
70
71// 重新导出核心服务
72pub use service::PlatformService;
73
74/// 平台服务客户端类型别名(统一命名为 `XxxClient`)。
75pub type PlatformClient = PlatformService;
76pub use openlark_core::config::Config;
77
78/// 平台服务模块版本信息
79pub const VERSION: &str = env!("CARGO_PKG_VERSION");
80
81/// 平台服务配置别名
82pub type PlatformConfig = Config;
83
84#[cfg(test)]
85mod tests {
86    use crate::VERSION;
87
88    #[test]
89    fn test_version() {
90        assert_ne!(VERSION, "");
91    }
92
93    #[test]
94    fn test_module_composition() {
95        // 验证模块组织正确
96        assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
97    }
98}
99
100#[cfg(test)]
101mod service_tests {
102    use super::*;
103    use openlark_core::constants::AppType;
104
105    fn create_test_config() -> Config {
106        Config::builder()
107            .app_id("test_app")
108            .app_secret("test_secret")
109            .app_type(AppType::SelfBuild)
110            .build()
111    }
112
113    #[test]
114    fn test_platform_service_creation() {
115        let config = create_test_config();
116        let service = PlatformService::new(config).unwrap();
117        assert!(service.config().app_id() == "test_app");
118    }
119
120    #[test]
121    fn test_platform_service_clone() {
122        let config = create_test_config();
123        let service = PlatformService::new(config).unwrap();
124        let cloned = service.clone();
125        assert!(cloned.config().app_id() == "test_app");
126    }
127
128    #[test]
129    fn test_platform_config_alias() {
130        let config: PlatformConfig = Config::builder()
131            .app_id("test_app")
132            .app_secret("test_secret")
133            .build();
134        assert!(config.app_id() == "test_app");
135    }
136
137    #[cfg(feature = "app-engine")]
138    #[test]
139    fn test_platform_service_app_engine() {
140        let config = create_test_config();
141        let service = PlatformService::new(config).unwrap();
142        let _app_engine = service.app_engine();
143    }
144
145    #[cfg(feature = "directory")]
146    #[test]
147    fn test_platform_service_directory() {
148        let config = create_test_config();
149        let service = PlatformService::new(config).unwrap();
150        let _directory = service.directory();
151    }
152
153    #[cfg(feature = "admin")]
154    #[test]
155    fn test_platform_service_admin() {
156        let config = create_test_config();
157        let service = PlatformService::new(config).unwrap();
158        let _admin = service.admin();
159    }
160
161    #[cfg(all(feature = "spark", feature = "v1"))]
162    #[test]
163    fn test_platform_service_spark() {
164        let config = create_test_config();
165        let service = PlatformService::new(config).unwrap();
166        let _request = service.spark().v1().directory().user().id_convert();
167    }
168}