Skip to main content

ascend_tools/
lib.rs

1// When jsts feature is enabled, napi-derive macros may generate code with
2// #[allow(unsafe_code)] internally, so we use deny instead of forbid.
3// No unsafe code exists in this crate; all FFI is isolated to ascend-tools-js.
4#![cfg_attr(not(feature = "jsts"), forbid(unsafe_code))]
5#![cfg_attr(feature = "jsts", deny(unsafe_code))]
6
7pub(crate) mod auth;
8pub mod client;
9pub mod config;
10pub mod error;
11pub mod models;
12pub(crate) mod sse;
13
14use ureq::Agent;
15
16pub use error::{Error, Result};
17
18fn tls_config() -> ureq::tls::TlsConfig {
19    ureq::tls::TlsConfig::builder()
20        .root_certs(ureq::tls::RootCerts::PlatformVerifier)
21        .build()
22}
23
24fn user_agent() -> &'static str {
25    concat!("ascend-tools/", env!("CARGO_PKG_VERSION"))
26}
27
28/// Agent for normal API requests (30-second global timeout).
29pub(crate) fn new_agent() -> Agent {
30    Agent::new_with_config(
31        ureq::config::Config::builder()
32            .tls_config(tls_config())
33            .http_status_as_error(false)
34            .timeout_global(Some(std::time::Duration::from_secs(30)))
35            .user_agent(user_agent())
36            .build(),
37    )
38}
39
40/// Agent for SSE streaming requests (no global timeout, 30s connect timeout).
41pub(crate) fn new_streaming_agent() -> Agent {
42    Agent::new_with_config(
43        ureq::config::Config::builder()
44            .tls_config(tls_config())
45            .http_status_as_error(false)
46            .timeout_connect(Some(std::time::Duration::from_secs(30)))
47            .user_agent(user_agent())
48            .build(),
49    )
50}