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
//! # CekUnit Client Library
//!
//! A comprehensive Rust client for interacting with the CekUnit web application.
//! This library provides a type-safe, ergonomic API for authentication and all
//! major features of the CekUnit platform, including dashboard management,
//! input data (nasabah) operations, PIC (Person In Charge) management,
//! user management, and export functionality.
//!
//! ## Overview
//!
//! The library is structured around a main client [`CekUnitClient`] that manages
//! a shared session cache and provides access to specialized sub‑clients for
//! different parts of the application. All network operations are performed via
//! a blocking `reqwest` client with configurable timeouts, retries, and connection
//! pooling.
//!
//! ## Features
//!
//! - **Authentication**: Login with email/password, automatic CSRF token handling,
//! session persistence via filesystem cache.
//! - **Dashboard**: Fetch paginated CekUnit lists, export data (Excel, PDF, CSV),
//! get unique column values, delete records (single, by category, or all).
//! - **Input Data (Nasabah)**: Submit new customer records.
//! - **Input User**: List and export user‑input data with search, sort, and date filters.
//! - **PIC Management**: Create, update, delete, and list Persons In Charge.
//! - **User Management**: List and update application users.
//!
//! ## Caching
//!
//! Upon successful login, session cookies and the current CSRF token are stored
//! in a JSON file inside the system’s cache directory (e.g., `~/.cache/cekunit/` on Linux).
//! All subsequent requests automatically attach these cookies, so you only need
//! to log in once per session.
//!
//! ## Environment Configuration
//!
//! The library reads configuration from environment variables (or a `.env` file).
//! Required variables include:
//!
//! - `USER_EMAIL` – login email
//! - `USER_PASSWORD` – login password
//! - `BASE_URL` – base URL of the CekUnit installation (e.g., `https://example.com`)
//! - Various endpoint variables (see [`EnvConfig`] documentation for the full list)
//!
//! ## Example
//!
//! ```no_run
//! use cekunit_client::CekUnitClient;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create the main client – loads configuration from environment
//! let mut client = CekUnitClient::new()?;
//!
//! // Log in (if no valid session exists, this will perform a new login)
//! let session = client.login()?;
//! println!("Logged in at: {}", session.timestamp);
//!
//! // Access the dashboard client
//! let dashboard = client.dashboard()?;
//! let html = dashboard.get_dashboard(Some(1), None, Some("created_at"), Some("desc"))?;
//!
//! // Export data as Excel
//! let excel_data = dashboard.export_cekunit("excel", "created_at", "desc")?;
//! std::fs::write("export.xlsx", excel_data)?;
//!
//! // Log out when done
//! client.logout()?;
//!
//! Ok(())
//! }
//! ```
// Re‑export public API for easy access
pub use crateLoginClient;
pub use crateLogoutClient;
pub use crate;
pub use crate;
pub use crateCekUnitClient;
pub use crateEnvConfig;
pub use crateApiError;
/// Utility functions and types for internal use, but exposed for advanced scenarios.
///
/// This module re‑exports lower‑level components from `api::auth::utils` that may be
/// useful for custom integrations or testing.
/// Returns the current crate version as defined in `Cargo.toml`.
///
/// # Example
/// ```
/// use cekunit_client::version;
/// println!("Client version: {}", version());
/// ```
/// Returns the current crate name as defined in `Cargo.toml`.
///
/// # Example
/// ```
/// use cekunit_client::name;
/// println!("Crate name: {}", name());
/// ```
/// Returns a [`BuildInfo`] struct containing metadata about the crate.
///
/// # Example
/// ```
/// use cekunit_client::build_info;
/// let info = build_info();
/// println!("{}", info);
/// ```
/// Build metadata for the CekUnit client crate.
///
/// This struct holds static strings obtained from Cargo environment variables
/// at compile time. It can be used for logging, diagnostics, or display purposes.