jacquard_api/tools_ozone/
safelink.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: tools.ozone.safelink.defs
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8pub mod add_rule;
9pub mod query_events;
10pub mod query_rules;
11pub mod remove_rule;
12pub mod update_rule;
13
14#[derive(Debug, Clone, PartialEq, Eq, Hash)]
15pub enum ActionType<'a> {
16    Block,
17    Warn,
18    Whitelist,
19    Other(jacquard_common::CowStr<'a>),
20}
21
22impl<'a> ActionType<'a> {
23    pub fn as_str(&self) -> &str {
24        match self {
25            Self::Block => "block",
26            Self::Warn => "warn",
27            Self::Whitelist => "whitelist",
28            Self::Other(s) => s.as_ref(),
29        }
30    }
31}
32
33impl<'a> From<&'a str> for ActionType<'a> {
34    fn from(s: &'a str) -> Self {
35        match s {
36            "block" => Self::Block,
37            "warn" => Self::Warn,
38            "whitelist" => Self::Whitelist,
39            _ => Self::Other(jacquard_common::CowStr::from(s)),
40        }
41    }
42}
43
44impl<'a> From<String> for ActionType<'a> {
45    fn from(s: String) -> Self {
46        match s.as_str() {
47            "block" => Self::Block,
48            "warn" => Self::Warn,
49            "whitelist" => Self::Whitelist,
50            _ => Self::Other(jacquard_common::CowStr::from(s)),
51        }
52    }
53}
54
55impl<'a> AsRef<str> for ActionType<'a> {
56    fn as_ref(&self) -> &str {
57        self.as_str()
58    }
59}
60
61impl<'a> serde::Serialize for ActionType<'a> {
62    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
63    where
64        S: serde::Serializer,
65    {
66        serializer.serialize_str(self.as_str())
67    }
68}
69
70impl<'de, 'a> serde::Deserialize<'de> for ActionType<'a>
71where
72    'de: 'a,
73{
74    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
75    where
76        D: serde::Deserializer<'de>,
77    {
78        let s = <&'de str>::deserialize(deserializer)?;
79        Ok(Self::from(s))
80    }
81}
82
83impl jacquard_common::IntoStatic for ActionType<'_> {
84    type Output = ActionType<'static>;
85    fn into_static(self) -> Self::Output {
86        match self {
87            ActionType::Block => ActionType::Block,
88            ActionType::Warn => ActionType::Warn,
89            ActionType::Whitelist => ActionType::Whitelist,
90            ActionType::Other(v) => ActionType::Other(v.into_static()),
91        }
92    }
93}
94
95///An event for URL safety decisions
96#[jacquard_derive::lexicon]
97#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
98#[serde(rename_all = "camelCase")]
99pub struct Event<'a> {
100    #[serde(borrow)]
101    pub action: crate::tools_ozone::safelink::ActionType<'a>,
102    ///Optional comment about the decision
103    #[serde(skip_serializing_if = "std::option::Option::is_none")]
104    #[serde(borrow)]
105    pub comment: std::option::Option<jacquard_common::CowStr<'a>>,
106    pub created_at: jacquard_common::types::string::Datetime,
107    ///DID of the user who created this rule
108    #[serde(borrow)]
109    pub created_by: jacquard_common::types::string::Did<'a>,
110    #[serde(borrow)]
111    pub event_type: crate::tools_ozone::safelink::EventType<'a>,
112    ///Auto-incrementing row ID
113    pub id: i64,
114    #[serde(borrow)]
115    pub pattern: crate::tools_ozone::safelink::PatternType<'a>,
116    #[serde(borrow)]
117    pub reason: crate::tools_ozone::safelink::ReasonType<'a>,
118    ///The URL that this rule applies to
119    #[serde(borrow)]
120    pub url: jacquard_common::CowStr<'a>,
121}
122
123impl jacquard_common::IntoStatic for Event<'_> {
124    type Output = Event<'static>;
125    fn into_static(self) -> Self::Output {
126        Event {
127            action: self.action.into_static(),
128            comment: self.comment.into_static(),
129            created_at: self.created_at.into_static(),
130            created_by: self.created_by.into_static(),
131            event_type: self.event_type.into_static(),
132            id: self.id.into_static(),
133            pattern: self.pattern.into_static(),
134            reason: self.reason.into_static(),
135            url: self.url.into_static(),
136            extra_data: self.extra_data.into_static(),
137        }
138    }
139}
140
141#[derive(Debug, Clone, PartialEq, Eq, Hash)]
142pub enum EventType<'a> {
143    AddRule,
144    UpdateRule,
145    RemoveRule,
146    Other(jacquard_common::CowStr<'a>),
147}
148
149impl<'a> EventType<'a> {
150    pub fn as_str(&self) -> &str {
151        match self {
152            Self::AddRule => "addRule",
153            Self::UpdateRule => "updateRule",
154            Self::RemoveRule => "removeRule",
155            Self::Other(s) => s.as_ref(),
156        }
157    }
158}
159
160impl<'a> From<&'a str> for EventType<'a> {
161    fn from(s: &'a str) -> Self {
162        match s {
163            "addRule" => Self::AddRule,
164            "updateRule" => Self::UpdateRule,
165            "removeRule" => Self::RemoveRule,
166            _ => Self::Other(jacquard_common::CowStr::from(s)),
167        }
168    }
169}
170
171impl<'a> From<String> for EventType<'a> {
172    fn from(s: String) -> Self {
173        match s.as_str() {
174            "addRule" => Self::AddRule,
175            "updateRule" => Self::UpdateRule,
176            "removeRule" => Self::RemoveRule,
177            _ => Self::Other(jacquard_common::CowStr::from(s)),
178        }
179    }
180}
181
182impl<'a> AsRef<str> for EventType<'a> {
183    fn as_ref(&self) -> &str {
184        self.as_str()
185    }
186}
187
188impl<'a> serde::Serialize for EventType<'a> {
189    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
190    where
191        S: serde::Serializer,
192    {
193        serializer.serialize_str(self.as_str())
194    }
195}
196
197impl<'de, 'a> serde::Deserialize<'de> for EventType<'a>
198where
199    'de: 'a,
200{
201    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
202    where
203        D: serde::Deserializer<'de>,
204    {
205        let s = <&'de str>::deserialize(deserializer)?;
206        Ok(Self::from(s))
207    }
208}
209
210impl jacquard_common::IntoStatic for EventType<'_> {
211    type Output = EventType<'static>;
212    fn into_static(self) -> Self::Output {
213        match self {
214            EventType::AddRule => EventType::AddRule,
215            EventType::UpdateRule => EventType::UpdateRule,
216            EventType::RemoveRule => EventType::RemoveRule,
217            EventType::Other(v) => EventType::Other(v.into_static()),
218        }
219    }
220}
221
222#[derive(Debug, Clone, PartialEq, Eq, Hash)]
223pub enum PatternType<'a> {
224    Domain,
225    Url,
226    Other(jacquard_common::CowStr<'a>),
227}
228
229impl<'a> PatternType<'a> {
230    pub fn as_str(&self) -> &str {
231        match self {
232            Self::Domain => "domain",
233            Self::Url => "url",
234            Self::Other(s) => s.as_ref(),
235        }
236    }
237}
238
239impl<'a> From<&'a str> for PatternType<'a> {
240    fn from(s: &'a str) -> Self {
241        match s {
242            "domain" => Self::Domain,
243            "url" => Self::Url,
244            _ => Self::Other(jacquard_common::CowStr::from(s)),
245        }
246    }
247}
248
249impl<'a> From<String> for PatternType<'a> {
250    fn from(s: String) -> Self {
251        match s.as_str() {
252            "domain" => Self::Domain,
253            "url" => Self::Url,
254            _ => Self::Other(jacquard_common::CowStr::from(s)),
255        }
256    }
257}
258
259impl<'a> AsRef<str> for PatternType<'a> {
260    fn as_ref(&self) -> &str {
261        self.as_str()
262    }
263}
264
265impl<'a> serde::Serialize for PatternType<'a> {
266    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
267    where
268        S: serde::Serializer,
269    {
270        serializer.serialize_str(self.as_str())
271    }
272}
273
274impl<'de, 'a> serde::Deserialize<'de> for PatternType<'a>
275where
276    'de: 'a,
277{
278    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
279    where
280        D: serde::Deserializer<'de>,
281    {
282        let s = <&'de str>::deserialize(deserializer)?;
283        Ok(Self::from(s))
284    }
285}
286
287impl jacquard_common::IntoStatic for PatternType<'_> {
288    type Output = PatternType<'static>;
289    fn into_static(self) -> Self::Output {
290        match self {
291            PatternType::Domain => PatternType::Domain,
292            PatternType::Url => PatternType::Url,
293            PatternType::Other(v) => PatternType::Other(v.into_static()),
294        }
295    }
296}
297
298#[derive(Debug, Clone, PartialEq, Eq, Hash)]
299pub enum ReasonType<'a> {
300    Csam,
301    Spam,
302    Phishing,
303    None,
304    Other(jacquard_common::CowStr<'a>),
305}
306
307impl<'a> ReasonType<'a> {
308    pub fn as_str(&self) -> &str {
309        match self {
310            Self::Csam => "csam",
311            Self::Spam => "spam",
312            Self::Phishing => "phishing",
313            Self::None => "none",
314            Self::Other(s) => s.as_ref(),
315        }
316    }
317}
318
319impl<'a> From<&'a str> for ReasonType<'a> {
320    fn from(s: &'a str) -> Self {
321        match s {
322            "csam" => Self::Csam,
323            "spam" => Self::Spam,
324            "phishing" => Self::Phishing,
325            "none" => Self::None,
326            _ => Self::Other(jacquard_common::CowStr::from(s)),
327        }
328    }
329}
330
331impl<'a> From<String> for ReasonType<'a> {
332    fn from(s: String) -> Self {
333        match s.as_str() {
334            "csam" => Self::Csam,
335            "spam" => Self::Spam,
336            "phishing" => Self::Phishing,
337            "none" => Self::None,
338            _ => Self::Other(jacquard_common::CowStr::from(s)),
339        }
340    }
341}
342
343impl<'a> AsRef<str> for ReasonType<'a> {
344    fn as_ref(&self) -> &str {
345        self.as_str()
346    }
347}
348
349impl<'a> serde::Serialize for ReasonType<'a> {
350    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
351    where
352        S: serde::Serializer,
353    {
354        serializer.serialize_str(self.as_str())
355    }
356}
357
358impl<'de, 'a> serde::Deserialize<'de> for ReasonType<'a>
359where
360    'de: 'a,
361{
362    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
363    where
364        D: serde::Deserializer<'de>,
365    {
366        let s = <&'de str>::deserialize(deserializer)?;
367        Ok(Self::from(s))
368    }
369}
370
371impl jacquard_common::IntoStatic for ReasonType<'_> {
372    type Output = ReasonType<'static>;
373    fn into_static(self) -> Self::Output {
374        match self {
375            ReasonType::Csam => ReasonType::Csam,
376            ReasonType::Spam => ReasonType::Spam,
377            ReasonType::Phishing => ReasonType::Phishing,
378            ReasonType::None => ReasonType::None,
379            ReasonType::Other(v) => ReasonType::Other(v.into_static()),
380        }
381    }
382}
383
384///Input for creating a URL safety rule
385#[jacquard_derive::lexicon]
386#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
387#[serde(rename_all = "camelCase")]
388pub struct UrlRule<'a> {
389    #[serde(borrow)]
390    pub action: crate::tools_ozone::safelink::ActionType<'a>,
391    ///Optional comment about the decision
392    #[serde(skip_serializing_if = "std::option::Option::is_none")]
393    #[serde(borrow)]
394    pub comment: std::option::Option<jacquard_common::CowStr<'a>>,
395    ///Timestamp when the rule was created
396    pub created_at: jacquard_common::types::string::Datetime,
397    ///DID of the user added the rule.
398    #[serde(borrow)]
399    pub created_by: jacquard_common::types::string::Did<'a>,
400    #[serde(borrow)]
401    pub pattern: crate::tools_ozone::safelink::PatternType<'a>,
402    #[serde(borrow)]
403    pub reason: crate::tools_ozone::safelink::ReasonType<'a>,
404    ///Timestamp when the rule was last updated
405    pub updated_at: jacquard_common::types::string::Datetime,
406    ///The URL or domain to apply the rule to
407    #[serde(borrow)]
408    pub url: jacquard_common::CowStr<'a>,
409}
410
411impl jacquard_common::IntoStatic for UrlRule<'_> {
412    type Output = UrlRule<'static>;
413    fn into_static(self) -> Self::Output {
414        UrlRule {
415            action: self.action.into_static(),
416            comment: self.comment.into_static(),
417            created_at: self.created_at.into_static(),
418            created_by: self.created_by.into_static(),
419            pattern: self.pattern.into_static(),
420            reason: self.reason.into_static(),
421            updated_at: self.updated_at.into_static(),
422            url: self.url.into_static(),
423            extra_data: self.extra_data.into_static(),
424        }
425    }
426}