supabase_client_rs/
config.rs1use std::time::Duration;
4
5#[derive(Debug, Clone)]
7pub struct SupabaseConfig {
8 pub url: String,
10
11 pub api_key: String,
13
14 pub jwt: Option<String>,
16
17 pub schema: String,
19
20 pub timeout: Duration,
22
23 pub headers: Vec<(String, String)>,
25
26 pub auto_refresh_token: bool,
28
29 pub persist_session: bool,
31}
32
33impl SupabaseConfig {
34 pub fn new(url: impl Into<String>, api_key: impl Into<String>) -> Self {
36 Self {
37 url: url.into(),
38 api_key: api_key.into(),
39 jwt: None,
40 schema: "public".to_string(),
41 timeout: Duration::from_secs(30),
42 headers: Vec::new(),
43 auto_refresh_token: true,
44 persist_session: true,
45 }
46 }
47
48 pub fn schema(mut self, schema: impl Into<String>) -> Self {
50 self.schema = schema.into();
51 self
52 }
53
54 pub fn timeout(mut self, timeout: Duration) -> Self {
56 self.timeout = timeout;
57 self
58 }
59
60 pub fn jwt(mut self, jwt: impl Into<String>) -> Self {
62 self.jwt = Some(jwt.into());
63 self
64 }
65
66 pub fn header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
68 self.headers.push((key.into(), value.into()));
69 self
70 }
71
72 pub fn auto_refresh_token(mut self, enabled: bool) -> Self {
74 self.auto_refresh_token = enabled;
75 self
76 }
77
78 pub fn persist_session(mut self, enabled: bool) -> Self {
80 self.persist_session = enabled;
81 self
82 }
83
84 pub fn rest_url(&self) -> String {
86 format!("{}/rest/v1", self.url.trim_end_matches('/'))
87 }
88
89 pub fn auth_url(&self) -> String {
91 format!("{}/auth/v1", self.url.trim_end_matches('/'))
92 }
93
94 pub fn storage_url(&self) -> String {
96 format!("{}/storage/v1", self.url.trim_end_matches('/'))
97 }
98
99 pub fn realtime_url(&self) -> String {
101 let base = self.url.trim_end_matches('/');
102 let ws_url = base
103 .replace("https://", "wss://")
104 .replace("http://", "ws://");
105 format!("{}/realtime/v1", ws_url)
106 }
107
108 pub fn functions_url(&self) -> String {
110 format!("{}/functions/v1", self.url.trim_end_matches('/'))
111 }
112}