viewpoint_cdp/protocol/storage/
mod.rs

1//! Storage domain types.
2//!
3//! The Storage domain exposes storage-related operations at the browser level.
4
5use serde::{Deserialize, Serialize};
6
7// Re-use cookie types from network_cookies module
8pub use super::network_cookies::{Cookie, CookieParam, CookieSameSite};
9
10/// Parameters for Storage.setCookies.
11#[derive(Debug, Clone, Serialize)]
12#[serde(rename_all = "camelCase")]
13pub struct SetCookiesParams {
14    /// Cookies to be set.
15    pub cookies: Vec<CookieParam>,
16    /// Browser context to use when called on the browser endpoint.
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub browser_context_id: Option<String>,
19}
20
21impl SetCookiesParams {
22    /// Create new set cookies params.
23    pub fn new(cookies: Vec<CookieParam>) -> Self {
24        Self {
25            cookies,
26            browser_context_id: None,
27        }
28    }
29
30    /// Set the browser context ID.
31    #[must_use]
32    pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
33        self.browser_context_id = Some(id.into());
34        self
35    }
36}
37
38/// Parameters for Storage.getCookies.
39#[derive(Debug, Clone, Serialize, Default)]
40#[serde(rename_all = "camelCase")]
41pub struct GetCookiesParams {
42    /// Browser context to use when called on the browser endpoint.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub browser_context_id: Option<String>,
45}
46
47impl GetCookiesParams {
48    /// Create new get cookies params.
49    pub fn new() -> Self {
50        Self::default()
51    }
52
53    /// Set the browser context ID.
54    #[must_use]
55    pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
56        self.browser_context_id = Some(id.into());
57        self
58    }
59}
60
61/// Result for Storage.getCookies.
62#[derive(Debug, Clone, Deserialize)]
63#[serde(rename_all = "camelCase")]
64pub struct GetCookiesResult {
65    /// Array of cookie objects.
66    pub cookies: Vec<Cookie>,
67}
68
69/// Parameters for Storage.deleteCookies.
70#[derive(Debug, Clone, Serialize)]
71#[serde(rename_all = "camelCase")]
72pub struct DeleteCookiesParams {
73    /// Name of the cookies to remove.
74    pub name: String,
75    /// URL to match cookie domain and path.
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub url: Option<String>,
78    /// Cookie domain.
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub domain: Option<String>,
81    /// Cookie path.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub path: Option<String>,
84    /// Cookie partition key.
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub partition_key: Option<String>,
87    /// Browser context to use when called on the browser endpoint.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub browser_context_id: Option<String>,
90}
91
92impl DeleteCookiesParams {
93    /// Create new delete cookies params.
94    pub fn new(name: impl Into<String>) -> Self {
95        Self {
96            name: name.into(),
97            url: None,
98            domain: None,
99            path: None,
100            partition_key: None,
101            browser_context_id: None,
102        }
103    }
104
105    /// Set the URL.
106    #[must_use]
107    pub fn url(mut self, url: impl Into<String>) -> Self {
108        self.url = Some(url.into());
109        self
110    }
111
112    /// Set the domain.
113    #[must_use]
114    pub fn domain(mut self, domain: impl Into<String>) -> Self {
115        self.domain = Some(domain.into());
116        self
117    }
118
119    /// Set the path.
120    #[must_use]
121    pub fn path(mut self, path: impl Into<String>) -> Self {
122        self.path = Some(path.into());
123        self
124    }
125
126    /// Set the browser context ID.
127    #[must_use]
128    pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
129        self.browser_context_id = Some(id.into());
130        self
131    }
132}
133
134/// Parameters for Storage.clearCookies.
135#[derive(Debug, Clone, Serialize, Default)]
136#[serde(rename_all = "camelCase")]
137pub struct ClearCookiesParams {
138    /// Browser context to use when called on the browser endpoint.
139    #[serde(skip_serializing_if = "Option::is_none")]
140    pub browser_context_id: Option<String>,
141}
142
143impl ClearCookiesParams {
144    /// Create new clear cookies params.
145    pub fn new() -> Self {
146        Self::default()
147    }
148
149    /// Set the browser context ID.
150    #[must_use]
151    pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
152        self.browser_context_id = Some(id.into());
153        self
154    }
155}