use std::path::PathBuf;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct Config {
pub api_base_url: String,
pub api_key: String,
pub product_slug: String,
pub storage_prefix: String,
pub storage_path: Option<PathBuf>,
pub device_identifier: Option<String>,
pub signing_public_key: Option<String>,
pub signing_key_id: Option<String>,
pub auto_validate_interval: Duration,
pub heartbeat_interval: Duration,
pub network_recheck_interval: Duration,
pub request_timeout: Duration,
pub verify_ssl: bool,
pub max_retries: u32,
pub retry_delay: Duration,
pub offline_fallback_mode: OfflineFallbackMode,
pub offline_token_refresh_interval: Duration,
pub enable_legacy_offline_tokens: bool,
pub max_offline_days: u32,
pub max_clock_skew: Duration,
pub telemetry_enabled: bool,
pub debug: bool,
pub app_version: Option<String>,
pub app_build: Option<String>,
}
impl Default for Config {
fn default() -> Self {
Self {
api_base_url: "https://licenseseat.com/api/v1".into(),
api_key: String::new(),
product_slug: String::new(),
storage_prefix: "licenseseat_".into(),
storage_path: None,
device_identifier: None,
signing_public_key: None,
signing_key_id: None,
auto_validate_interval: Duration::from_secs(3600), heartbeat_interval: Duration::from_secs(300), network_recheck_interval: Duration::from_secs(30),
request_timeout: Duration::from_secs(30),
verify_ssl: true,
max_retries: 3,
retry_delay: Duration::from_secs(1),
offline_fallback_mode: OfflineFallbackMode::NetworkOnly,
offline_token_refresh_interval: Duration::from_secs(72 * 3600), enable_legacy_offline_tokens: false,
max_offline_days: 0,
max_clock_skew: Duration::from_secs(300), telemetry_enabled: true,
debug: false,
app_version: None,
app_build: None,
}
}
}
impl Config {
pub fn new(api_key: impl Into<String>, product_slug: impl Into<String>) -> Self {
Self {
api_key: api_key.into(),
product_slug: product_slug.into(),
..Default::default()
}
}
pub fn with_debug(mut self, debug: bool) -> Self {
self.debug = debug;
self
}
pub fn with_storage_path(mut self, path: impl Into<PathBuf>) -> Self {
self.storage_path = Some(path.into());
self
}
pub fn with_auto_validate_interval(mut self, interval: Duration) -> Self {
self.auto_validate_interval = interval;
self
}
pub fn with_request_timeout(mut self, timeout: Duration) -> Self {
self.request_timeout = timeout;
self
}
pub fn with_verify_ssl(mut self, verify_ssl: bool) -> Self {
self.verify_ssl = verify_ssl;
self
}
pub fn with_offline_fallback(mut self, mode: OfflineFallbackMode) -> Self {
self.offline_fallback_mode = mode;
self
}
pub fn with_max_offline_days(mut self, days: u32) -> Self {
self.max_offline_days = days;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum OfflineFallbackMode {
#[default]
NetworkOnly,
Always,
}