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)组织,分两类入口(ADR 0001):
14//! - **Service accessor 入口**(含路径参数绑定层,经 `PlatformService::xxx()`):
15//!   `app_engine`(37 APIs)、`directory`(21 APIs)、`admin`(14 APIs)、`spark`(1 API)
16//! - **flat-by-design 直路径**(叶子 `new(Config)` 无路径参数,无 Service 壳,同 analytics 裁决):
17//!   `mdm`、`tenant`、`trust_party`
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
39mod service;
40
41// 通用模块
42pub mod common;
43
44// 业务域模块
45#[cfg(feature = "app-engine")]
46pub mod app_engine;
47
48#[cfg(feature = "directory")]
49pub mod directory;
50
51#[cfg(feature = "admin")]
52pub mod admin;
53
54// flat-by-design 域(无 Service 壳,直路径访问,ADR 0001)
55#[cfg(feature = "mdm")]
56pub mod mdm;
57
58#[cfg(feature = "tenant")]
59pub mod tenant;
60
61#[cfg(feature = "trust_party")]
62pub mod trust_party;
63
64#[cfg(feature = "spark")]
65pub mod spark;
66
67// Prelude 模块
68pub mod prelude;
69
70// 重新导出核心服务
71pub use service::PlatformService;
72
73/// 平台服务客户端类型别名(统一命名为 `XxxClient`)。
74pub type PlatformClient = PlatformService;
75pub use openlark_core::config::Config;
76
77/// 平台服务模块版本信息
78pub const VERSION: &str = env!("CARGO_PKG_VERSION");
79
80/// 平台服务配置别名
81pub type PlatformConfig = Config;
82
83#[cfg(test)]
84mod tests {
85    use crate::VERSION;
86
87    #[test]
88    fn test_version() {
89        assert_ne!(VERSION, "");
90    }
91
92    #[test]
93    fn test_module_composition() {
94        // 验证模块组织正确
95        assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
96    }
97}
98
99#[cfg(test)]
100mod service_tests {
101    use super::*;
102    use openlark_core::constants::AppType;
103
104    fn create_test_config() -> Config {
105        Config::builder()
106            .app_id("test_app")
107            .app_secret("test_secret")
108            .app_type(AppType::SelfBuild)
109            .build()
110    }
111
112    #[test]
113    fn test_platform_service_creation() {
114        let config = create_test_config();
115        let service = PlatformService::new(config);
116        assert!(service.config().app_id() == "test_app");
117    }
118
119    #[test]
120    fn test_platform_service_clone() {
121        let config = create_test_config();
122        let service = PlatformService::new(config);
123        let cloned = service.clone();
124        assert!(cloned.config().app_id() == "test_app");
125    }
126
127    #[test]
128    fn test_platform_config_alias() {
129        let config: PlatformConfig = Config::builder()
130            .app_id("test_app")
131            .app_secret("test_secret")
132            .build();
133        assert!(config.app_id() == "test_app");
134    }
135
136    #[cfg(feature = "app-engine")]
137    #[test]
138    fn test_platform_service_app_engine() {
139        let config = create_test_config();
140        let service = PlatformService::new(config);
141        let _app_engine = service.app_engine();
142    }
143
144    #[cfg(feature = "directory")]
145    #[test]
146    fn test_platform_service_directory() {
147        let config = create_test_config();
148        let service = PlatformService::new(config);
149        let _directory = service.directory();
150    }
151
152    #[cfg(feature = "admin")]
153    #[test]
154    fn test_platform_service_admin() {
155        let config = create_test_config();
156        let service = PlatformService::new(config);
157        let _admin = service.admin();
158    }
159
160    #[cfg(feature = "spark")]
161    #[test]
162    fn test_platform_service_spark() {
163        let config = create_test_config();
164        let service = PlatformService::new(config);
165        let _request = service.spark().v1().directory().user().id_convert();
166    }
167}