files_sdk/
lib.rs

1//! Files.com Rust SDK
2//!
3//! A comprehensive Rust client for the [Files.com](https://files.com) REST API, providing full access to
4//! file operations, user management, sharing, automation, and administrative features.
5//!
6//! ## Features
7//!
8//! - **File Operations**: Upload, download, copy, move, delete files and folders
9//! - **User & Access Management**: Users, groups, permissions, API keys, sessions
10//! - **Sharing**: Bundles (share links), file requests, inbox uploads
11//! - **Automation**: Webhooks, behaviors, remote servers, automations
12//! - **Administration**: Site settings, history, notifications, billing
13//!
14//! ## Quick Start
15//!
16//! ```rust,no_run
17//! use files_sdk::{FilesClient, files::FileHandler};
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//!     // Create client with API key
22//!     let client = FilesClient::builder()
23//!         .api_key("your-api-key")
24//!         .build()?;
25//!
26//!     // Use handlers for typed operations
27//!     let file_handler = FileHandler::new(client.clone());
28//!
29//!     // Upload a file
30//!     let data = b"Hello, Files.com!";
31//!     file_handler.upload_file("/path/to/file.txt", data).await?;
32//!
33//!     Ok(())
34//! }
35//! ```
36//!
37//! ## Core Usage Patterns
38//!
39//! ### Client Creation
40//!
41//! The client uses a builder pattern for flexible configuration:
42//!
43//! ```rust,no_run
44//! use files_sdk::FilesClient;
45//!
46//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
47//! // Basic client with default settings
48//! let client = FilesClient::builder()
49//!     .api_key("your-api-key")
50//!     .build()?;
51//!
52//! // Custom configuration
53//! let client = FilesClient::builder()
54//!     .api_key("your-api-key")
55//!     .base_url("https://app.files.com/api/rest/v1".to_string())
56//!     .timeout(std::time::Duration::from_secs(60))
57//!     .build()?;
58//! # Ok(())
59//! # }
60//! ```
61//!
62//! ### Middleware with Tower (Optional)
63//!
64//! For retry logic, rate limiting, and observability, use the optional `tower` feature:
65//!
66//! ```toml
67//! [dependencies]
68//! files-sdk = { version = "0.3", features = ["tower"] }
69//! tower = "0.5"
70//! tower-http = { version = "0.6", features = ["retry", "trace"] }
71//! ```
72//!
73//! See the `tower_*` examples in the examples directory for complete working code.
74//!
75//! **Benefits of Tower middleware:**
76//! - **Composable**: Mix and match middleware layers
77//! - **Battle-tested**: Use proven crates from the tower ecosystem
78//! - **Customizable**: Full control over retry, rate limiting, tracing
79//! - **Reusable**: Share middleware across different HTTP clients
80//!
81//! ### File Upload (Two-Stage Process)
82//!
83//! Files.com uses a two-stage upload process:
84//!
85//! ```rust,no_run
86//! use files_sdk::{FilesClient, files::{FileActionHandler, FileHandler}};
87//!
88//! # #[tokio::main]
89//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
90//! let client = FilesClient::builder()
91//!     .api_key("your-api-key")
92//!     .build()?;
93//!
94//! // Stage 1: Begin upload to get upload URLs
95//! let file_action = FileActionHandler::new(client.clone());
96//! let upload_info = file_action
97//!     .begin_upload("/uploads/myfile.txt", Some(1024), true)
98//!     .await?;
99//!
100//! // Stage 2: Upload file data (simplified - see FileHandler for complete implementation)
101//! let file_handler = FileHandler::new(client.clone());
102//! let data = b"file contents";
103//! file_handler.upload_file("/uploads/myfile.txt", data).await?;
104//! # Ok(())
105//! # }
106//! ```
107//!
108//! ## Error Handling
109//!
110//! The SDK provides comprehensive error handling:
111//!
112//! ```rust,no_run
113//! use files_sdk::{FilesClient, FilesError, files::FileHandler};
114//!
115//! # #[tokio::main]
116//! # async fn main() {
117//! let client = FilesClient::builder()
118//!     .api_key("test-key")
119//!     .build()
120//!     .unwrap();
121//!
122//! let handler = FileHandler::new(client);
123//!
124//! match handler.download_file("/path/to/file.txt").await {
125//!     Ok(file) => println!("Downloaded: {:?}", file),
126//!     Err(FilesError::NotFound { message, .. }) => {
127//!         println!("File not found: {}", message);
128//!     }
129//!     Err(FilesError::AuthenticationFailed { message, .. }) => {
130//!         println!("Invalid API key: {}", message);
131//!     }
132//!     Err(e) => println!("Other error: {}", e),
133//! }
134//! # }
135//! ```
136//!
137//! ## Authentication
138//!
139//! Files.com uses API key authentication via the `X-FilesAPI-Key` header.
140//! API keys can be obtained from the Files.com web interface under Account Settings.
141
142// Core modules
143pub mod client;
144pub mod error;
145pub mod prelude;
146pub mod progress;
147pub mod types;
148pub mod utils;
149
150// Domain modules
151pub mod admin;
152pub mod as2;
153pub mod automation;
154pub mod developers;
155pub mod files;
156pub mod integrations;
157pub mod logs;
158pub mod messages;
159pub mod security;
160pub mod sharing;
161pub mod storage;
162pub mod users;
163
164// Misc (to be moved or removed)
165pub mod webhook_tests;
166
167// Re-export client types
168pub use client::{FilesClient, FilesClientBuilder};
169
170// Re-export error types
171pub use error::{FilesError, Result};
172
173// Re-export common types
174pub use types::{FileEntity, FileUploadPartEntity, FolderEntity, PaginationInfo};
175
176// Re-export all handlers for backward compatibility
177pub use admin::{
178    ActionNotificationExportHandler, ActionNotificationExportResultHandler,
179    ChildSiteManagementPolicyHandler, DnsRecordHandler, HistoryExportHandler2,
180    HistoryExportResultHandler2, HistoryHandler, HolidayRegionHandler, InvoiceHandler,
181    PaymentHandler, SiteHandler, StyleHandler,
182};
183pub use as2::{
184    As2IncomingMessageHandler, As2OutgoingMessageHandler, As2PartnerHandler, As2StationHandler,
185};
186pub use automation::{
187    AutomationHandler, AutomationRunHandler, BehaviorHandler, RemoteMountBackendHandler,
188    RemoteServerHandler, SyncHandler, SyncRunHandler,
189};
190pub use developers::AppHandler;
191pub use files::{
192    FileActionHandler, FileCommentHandler, FileCommentReactionHandler, FileHandler,
193    FileMigrationHandler, FileMigrationLogHandler, FolderHandler,
194};
195pub use integrations::SiemHttpDestinationHandler;
196pub use logs::{
197    ApiRequestLogHandler, AutomationLogHandler, EmailIncomingMessageHandler, EmailLogHandler,
198    ExavaultApiRequestLogHandler, ExternalEventHandler, FtpActionLogHandler,
199    OutboundConnectionLogHandler, PublicHostingRequestLogHandler, SettingsChangeHandler,
200    SftpActionLogHandler, SyncLogHandler, WebDavActionLogHandler,
201};
202pub use messages::{
203    MessageCommentHandler, MessageCommentReactionHandler, MessageHandler, MessageReactionHandler,
204    NotificationHandler,
205};
206pub use security::{ClickwrapHandler, GpgKeyHandler, IpAddressHandler, SftpHostKeyHandler};
207pub use sharing::{
208    BundleActionHandler, BundleDownloadHandler, BundleHandler, BundleNotificationHandler,
209    BundleRecipientHandler, BundleRegistrationHandler, FormFieldSetHandler, InboxRecipientHandler,
210    InboxRegistrationHandler2, InboxUploadHandler, RequestHandler, ShareGroupHandler,
211};
212pub use storage::{
213    BandwidthSnapshotHandler, LockHandler, PriorityHandler, ProjectHandler,
214    RemoteBandwidthSnapshotHandler, RestoreHandler, SnapshotHandler, UsageDailySnapshotHandler,
215    UsageSnapshotHandler,
216};
217pub use users::{
218    ApiKeyCurrentHandler, ApiKeyHandler, CurrentUserHandler, GroupHandler, GroupUserHandler,
219    PermissionHandler, PublicKeyHandler, SessionHandler, SsoStrategyHandler, UserCipherUseHandler,
220    UserHandler, UserLifecycleRuleHandler, UserRequestHandler, UserSftpClientUseHandler,
221};
222
223// Error types are now in the error module