openlark 0.16.0

飞书开放平台 Rust SDK - 企业级高覆盖率 API 客户端,极简依赖一条命令
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
//! OpenLark 官方入口 crate。
//!
//! 普通用户应优先使用 `openlark`,通过业务 feature 开启所需能力:
//!
//! ```toml
//! [dependencies]
//! openlark = { version = "0.16.0", default-features = false, features = ["auth", "docs-drive", "docs-bitable", "webhook-signature"] }
//! ```
//!
//! - 统一客户端入口:[`Client`]
//! - 高级业务模块入口:[`auth`]、[`communication`]、[`docs`]、[`workflow`] 等
//! - 统一预导出:[`prelude`]
//!
//! 若只想要单一业务域的最小依赖,再直接使用 `openlark-{domain}` 子 crate。
//!
//! Canonical public API 入口规则见 `docs/PUBLIC_REEXPORT_POLICY.md`。
//!
//! 推荐顺序:
//!
//! - 运行时入口:[`Client`] / [`ClientBuilder`]
//! - 导入入口:[`prelude`]
//! - 业务命名空间:`open_lark::auth`、`open_lark::communication`、`open_lark::docs`
//! - 最小依赖场景:直接依赖对应 `openlark-{domain}` crate
//!
//! 顶层 `AuthClient`、`DocsClient`、`HrClient` 等类型 re-export 会继续保留,
//! 但它们的定位是 compatibility alias,而不是普通用户的主入口。
//!
//! 根 crate `prelude` 有意不暴露客户端实现层细节:
//!
//! ```rust,compile_fail
//! use open_lark::prelude::*;
//!
//! let _registry: ServiceRegistry;
//! ```

// 允许测试模块中的未使用导入(测试桩代码常见模式)
#![allow(unused_imports)]

// 原始 crate-name passthrough re-export 仅用于兼容历史路径,
// 不再作为根 crate 的推荐公开入口出现在文档中。
#[deprecated(
    since = "0.15.0",
    note = "Use open_lark::{Client, ClientBuilder, prelude} or depend on openlark-client directly; open_lark::openlark_client is a legacy compatibility entrypoint."
)]
#[doc(hidden)]
pub use openlark_client;
pub use openlark_client::{Client, ClientBuilder, Config, Error, Result};
#[deprecated(
    since = "0.15.0",
    note = "Use the root common types (CoreConfig, CoreError, RequestOption, SDKResult) or depend on openlark-core directly; open_lark::openlark_core is a legacy compatibility entrypoint."
)]
#[doc(hidden)]
pub use openlark_core;
#[deprecated(
    since = "0.15.0",
    note = "Use the root common types (CoreConfig, CoreError, RequestOption, SDKResult) or depend on openlark-core directly; open_lark::core is a legacy compatibility entrypoint."
)]
#[doc(hidden)]
pub use openlark_core as core;
pub use openlark_core::SDKResult;
pub use openlark_core::config::Config as CoreConfig;
pub use openlark_core::error::{CoreError, ErrorCode, ErrorSeverity, ErrorTrait, ErrorType};
pub use openlark_core::req_option::RequestOption;

#[cfg(feature = "websocket")]
/// WebSocket 客户端相关类型导出。
pub mod ws_client {
    pub use openlark_client::ws_client::*;
}

#[cfg(feature = "auth")]
#[deprecated(
    since = "0.15.0",
    note = "Use open_lark::auth or Client.auth for runtime access, or depend on the auth crate directly; open_lark::openlark_auth is a legacy compatibility entrypoint."
)]
#[doc(hidden)]
pub use openlark_auth;

#[cfg(feature = "auth")]
pub use openlark_auth as auth;

#[cfg(feature = "communication")]
#[deprecated(
    since = "0.15.0",
    note = "Use open_lark::communication or Client.communication for runtime access, or depend on the communication crate directly; open_lark::openlark_communication is a legacy compatibility entrypoint."
)]
#[doc(hidden)]
pub use openlark_communication;

#[cfg(feature = "communication")]
pub use openlark_communication as communication;

#[cfg(any(
    feature = "docs",
    feature = "docs-ccm",
    feature = "docs-base",
    feature = "docs-bitable",
    feature = "docs-drive",
    feature = "docs-explorer",
    feature = "docs-sheets",
    feature = "docs-sheets-v2",
    feature = "docs-sheets-v3",
    feature = "docs-full"
))]
#[deprecated(
    since = "0.15.0",
    note = "Use open_lark::docs or Client.docs for runtime access, or depend on the docs crate directly; open_lark::openlark_docs is a legacy compatibility entrypoint."
)]
#[doc(hidden)]
pub use openlark_docs;

#[cfg(any(
    feature = "docs",
    feature = "docs-ccm",
    feature = "docs-base",
    feature = "docs-bitable",
    feature = "docs-drive",
    feature = "docs-explorer",
    feature = "docs-sheets",
    feature = "docs-sheets-v2",
    feature = "docs-sheets-v3",
    feature = "docs-full"
))]
pub use openlark_docs as docs;

#[cfg(feature = "hr")]
pub use openlark_hr as hr;

#[cfg(feature = "ai")]
pub use openlark_ai as ai;

#[cfg(feature = "helpdesk")]
pub use openlark_helpdesk as helpdesk;

#[cfg(feature = "mail")]
pub use openlark_mail as mail;

#[cfg(feature = "meeting")]
pub use openlark_meeting as meeting;

#[cfg(feature = "application")]
pub use openlark_application as application;

#[cfg(feature = "security")]
pub use openlark_security as security;

#[cfg(feature = "workflow")]
pub use openlark_workflow as workflow;

#[cfg(feature = "platform")]
pub use openlark_platform as platform;

#[cfg(feature = "analytics")]
pub use openlark_analytics as analytics;

#[cfg(feature = "user")]
pub use openlark_user as user;

#[cfg(feature = "webhook")]
#[deprecated(
    since = "0.15.0",
    note = "Use open_lark::webhook or depend on openlark-webhook directly; open_lark::openlark_webhook is a legacy compatibility entrypoint."
)]
#[doc(hidden)]
pub use openlark_webhook;

#[cfg(feature = "webhook")]
pub use openlark_webhook as webhook;

#[cfg(feature = "cardkit")]
pub use openlark_cardkit as cardkit;

// 顶层 meta client 类型 re-export 保留为兼容层;
// 普通 `openlark` 用户优先通过 `Client` 字段访问业务能力。
#[cfg(feature = "auth")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.auth for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::AuthClient;

#[cfg(any(
    feature = "docs",
    feature = "docs-ccm",
    feature = "docs-base",
    feature = "docs-bitable",
    feature = "docs-drive",
    feature = "docs-explorer",
    feature = "docs-sheets",
    feature = "docs-sheets-v2",
    feature = "docs-sheets-v3",
    feature = "docs-full"
))]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.docs for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::DocsClient;

#[cfg(feature = "communication")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.communication for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::CommunicationClient;

#[cfg(feature = "hr")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.hr for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::HrClient;

#[cfg(feature = "meeting")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.meeting for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::MeetingClient;

#[cfg(feature = "cardkit")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.cardkit for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::CardkitClient;

#[cfg(feature = "ai")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.ai for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::AiClient;

#[cfg(feature = "workflow")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.workflow for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::WorkflowClient;

#[cfg(feature = "platform")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.platform for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::PlatformClient;

#[cfg(feature = "application")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.application for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::ApplicationClient;

#[cfg(feature = "helpdesk")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.helpdesk for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::HelpdeskClient;

#[cfg(feature = "mail")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.mail for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::MailClient;

#[cfg(feature = "analytics")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.analytics for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::AnalyticsClient;

#[cfg(feature = "user")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.user for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::UserClient;

#[cfg(feature = "security")]
#[deprecated(
    since = "0.15.0",
    note = "Use Client.security for runtime access, or use openlark-client / business-crate paths for explicit types; root-level *Client aliases are legacy compatibility entrypoints."
)]
#[doc(hidden)]
pub use openlark_client::SecurityClient;

/// 面向 `openlark` 用户的统一预导出。
///
/// 该模块只导出“创建客户端 + 顶层业务入口”所需的稳定公共类型。
/// registry / feature loader / traits 等高级客户端层能力保留在 `openlark-client`。
#[allow(deprecated)]
pub mod prelude {
    #[cfg(feature = "ai")]
    #[doc(hidden)]
    pub use crate::AiClient;
    #[cfg(feature = "analytics")]
    #[doc(hidden)]
    pub use crate::AnalyticsClient;
    #[cfg(feature = "application")]
    #[doc(hidden)]
    pub use crate::ApplicationClient;
    #[cfg(feature = "auth")]
    #[doc(hidden)]
    pub use crate::AuthClient;
    #[cfg(feature = "communication")]
    #[doc(hidden)]
    pub use crate::CommunicationClient;
    #[cfg(any(
        feature = "docs",
        feature = "docs-ccm",
        feature = "docs-base",
        feature = "docs-bitable",
        feature = "docs-drive",
        feature = "docs-explorer",
        feature = "docs-sheets",
        feature = "docs-sheets-v2",
        feature = "docs-sheets-v3",
        feature = "docs-full"
    ))]
    #[doc(hidden)]
    pub use crate::DocsClient;
    #[cfg(feature = "helpdesk")]
    #[doc(hidden)]
    pub use crate::HelpdeskClient;
    #[cfg(feature = "hr")]
    #[doc(hidden)]
    pub use crate::HrClient;
    #[cfg(feature = "mail")]
    #[doc(hidden)]
    pub use crate::MailClient;
    #[cfg(feature = "meeting")]
    #[doc(hidden)]
    pub use crate::MeetingClient;
    #[cfg(feature = "platform")]
    #[doc(hidden)]
    pub use crate::PlatformClient;
    pub use crate::SDKResult;
    #[cfg(feature = "security")]
    #[doc(hidden)]
    pub use crate::SecurityClient;
    #[cfg(feature = "user")]
    #[doc(hidden)]
    pub use crate::UserClient;
    #[cfg(feature = "workflow")]
    #[doc(hidden)]
    pub use crate::WorkflowClient;
    pub use crate::{Client, ClientBuilder, Config, CoreConfig, Error, Result};
    pub use crate::{CoreError, ErrorCode, ErrorSeverity, ErrorTrait, ErrorType, RequestOption};
    pub use openlark_core::prelude::*;
}

#[cfg(test)]
mod tests {
    use super::*;

    fn build_test_client() -> Result<Client> {
        Client::builder()
            .app_id("test_app")
            .app_secret("test_secret")
            .build()
    }

    #[test]
    fn root_prelude_exposes_canonical_core_entrypoints() {
        use crate::prelude::*;

        let _builder: ClientBuilder = Client::builder();
        let _config: Config = Config::builder()
            .app_id("test_app")
            .app_secret("test_secret")
            .build()
            .expect("test config should build");
        let _request_option: Option<RequestOption> = None;
    }

    #[test]
    fn root_minimal_builder_works_without_service_features() {
        let client = build_test_client().expect("client should build with minimal features");
        assert_eq!(client.config().app_id, "test_app");
    }

    #[cfg(feature = "auth")]
    #[test]
    #[allow(deprecated)]
    fn root_client_exposes_auth_entrypoint() {
        let client = build_test_client().expect("client should build with auth feature");

        let _auth = &client.auth;
        let alias = std::any::type_name::<crate::AuthClient>();
        let compat = std::any::type_name::<openlark_client::AuthClient>();

        assert_eq!(alias, compat);
    }

    #[cfg(feature = "communication")]
    #[test]
    fn root_client_exposes_communication_namespace() {
        let client = build_test_client().expect("client should build with communication feature");

        let _communication = &client.communication;
        let _endpoint = crate::communication::endpoints::IM_V1_MESSAGES;
    }

    #[cfg(any(
        feature = "docs",
        feature = "docs-ccm",
        feature = "docs-base",
        feature = "docs-bitable",
        feature = "docs-drive",
        feature = "docs-explorer",
        feature = "docs-sheets",
        feature = "docs-sheets-v2",
        feature = "docs-sheets-v3",
        feature = "docs-full"
    ))]
    #[test]
    #[allow(deprecated)]
    fn root_client_exposes_docs_namespace() {
        let client = build_test_client().expect("client should build with docs feature");

        let _docs = &client.docs;
        let alias = std::any::type_name::<crate::DocsClient>();
        let compat = std::any::type_name::<openlark_client::DocsClient>();

        assert_eq!(alias, compat);
    }

    #[cfg(feature = "hr")]
    #[test]
    #[allow(deprecated)]
    fn root_client_exposes_hr_entrypoint() {
        let client = build_test_client().expect("client should build with hr feature");

        let _hr = &client.hr;
        let alias = std::any::type_name::<crate::HrClient>();
        let compat = std::any::type_name::<openlark_client::HrClient>();

        assert_eq!(alias, compat);
    }

    #[cfg(feature = "security")]
    #[test]
    #[allow(deprecated)]
    fn root_client_exposes_security_entrypoint() {
        let client = build_test_client().expect("client should build with security feature");

        let _security = &client.security;
        let alias = std::any::type_name::<crate::SecurityClient>();
        let compat = std::any::type_name::<openlark_client::SecurityClient>();

        assert_eq!(alias, compat);
    }

    #[cfg(feature = "docs-bitable")]
    #[test]
    fn root_docs_bitable_feature_exposes_query_helper() {
        let query = crate::docs::BitableRecordQuery::new("app_token", "table_id")
            .where_equals("状态", "进行中");

        assert_eq!(query.app_token, "app_token");
        assert_eq!(query.table_id, "table_id");
    }

    #[cfg(feature = "docs-drive")]
    #[test]
    fn root_docs_drive_feature_exposes_drive_helpers() {
        let upload = crate::docs::DriveUploadFile::new("demo.txt", vec![1, 2, 3]);
        let range = crate::docs::DriveDownloadRange::from_start(0).with_end(9);

        assert_eq!(upload.file_name, "demo.txt");
        assert_eq!(upload.size(), 3);
        assert_eq!(range.to_header_value(), "bytes=0-9");
    }

    #[cfg(feature = "essential")]
    #[test]
    fn root_essential_feature_combines_docs_and_communication_paths() {
        let client = build_test_client().expect("client should build with essential feature");

        let _communication = &client.communication;
        let _docs = &client.docs;
        let recipient = crate::communication::MessageRecipient::open_id("ou_xxx");
        let query = crate::docs::BitableRecordQuery::new("app_token", "table_id");

        assert_eq!(recipient.receive_id, "ou_xxx");
        assert_eq!(query.table_id, "table_id");
    }

    #[cfg(feature = "enterprise")]
    #[test]
    fn root_enterprise_feature_combines_quality_critical_domains() {
        let client = build_test_client().expect("client should build with enterprise feature");

        let _security = &client.security;
        let _hr = &client.hr;
        let _workflow = &client.workflow;
        let action = crate::workflow::ApprovalTaskAction::new(
            "approval_code",
            "instance_code",
            "ou_xxx",
            "task_123",
        )
        .comment("同意");

        assert_eq!(action.task_id, "task_123");
        assert_eq!(action.comment.as_deref(), Some("同意"));
    }

    #[cfg(feature = "webhook-full")]
    #[test]
    fn root_webhook_full_feature_exposes_signature_and_robot_client() {
        let client = crate::webhook::WebhookClient::new();
        let signature = crate::webhook::common::signature::sign(1_700_000_000, "secret");

        let _ = client;
        assert!(!signature.is_empty());
    }
}