jacquard_api/place_stream/server/
update_webhook.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::UriValue;
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17use crate::place_stream::server::RewriteRule;
18use crate::place_stream::server::Webhook;
19
20#[lexicon]
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
22#[serde(rename_all = "camelCase")]
23pub struct UpdateWebhook<'a> {
24 #[serde(skip_serializing_if = "Option::is_none")]
26 pub active: Option<bool>,
27 #[serde(skip_serializing_if = "Option::is_none")]
29 #[serde(borrow)]
30 pub description: Option<CowStr<'a>>,
31 #[serde(skip_serializing_if = "Option::is_none")]
33 #[serde(borrow)]
34 pub events: Option<Vec<CowStr<'a>>>,
35 #[serde(borrow)]
37 pub id: CowStr<'a>,
38 #[serde(skip_serializing_if = "Option::is_none")]
40 #[serde(borrow)]
41 pub mute_words: Option<Vec<CowStr<'a>>>,
42 #[serde(skip_serializing_if = "Option::is_none")]
44 #[serde(borrow)]
45 pub name: Option<CowStr<'a>>,
46 #[serde(skip_serializing_if = "Option::is_none")]
48 #[serde(borrow)]
49 pub prefix: Option<CowStr<'a>>,
50 #[serde(skip_serializing_if = "Option::is_none")]
52 #[serde(borrow)]
53 pub rewrite: Option<Vec<RewriteRule<'a>>>,
54 #[serde(skip_serializing_if = "Option::is_none")]
56 #[serde(borrow)]
57 pub suffix: Option<CowStr<'a>>,
58 #[serde(skip_serializing_if = "Option::is_none")]
60 #[serde(borrow)]
61 pub url: Option<UriValue<'a>>,
62}
63
64
65#[lexicon]
66#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
67#[serde(rename_all = "camelCase")]
68pub struct UpdateWebhookOutput<'a> {
69 #[serde(borrow)]
70 pub webhook: Webhook<'a>,
71}
72
73
74#[open_union]
75#[derive(
76 Serialize,
77 Deserialize,
78 Debug,
79 Clone,
80 PartialEq,
81 Eq,
82 thiserror::Error,
83 miette::Diagnostic,
84 IntoStatic
85)]
86
87#[serde(tag = "error", content = "message")]
88#[serde(bound(deserialize = "'de: 'a"))]
89pub enum UpdateWebhookError<'a> {
90 #[serde(rename = "WebhookNotFound")]
92 WebhookNotFound(Option<CowStr<'a>>),
93 #[serde(rename = "Unauthorized")]
95 Unauthorized(Option<CowStr<'a>>),
96 #[serde(rename = "InvalidUrl")]
98 InvalidUrl(Option<CowStr<'a>>),
99 #[serde(rename = "DuplicateWebhook")]
101 DuplicateWebhook(Option<CowStr<'a>>),
102}
103
104impl core::fmt::Display for UpdateWebhookError<'_> {
105 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
106 match self {
107 Self::WebhookNotFound(msg) => {
108 write!(f, "WebhookNotFound")?;
109 if let Some(msg) = msg {
110 write!(f, ": {}", msg)?;
111 }
112 Ok(())
113 }
114 Self::Unauthorized(msg) => {
115 write!(f, "Unauthorized")?;
116 if let Some(msg) = msg {
117 write!(f, ": {}", msg)?;
118 }
119 Ok(())
120 }
121 Self::InvalidUrl(msg) => {
122 write!(f, "InvalidUrl")?;
123 if let Some(msg) = msg {
124 write!(f, ": {}", msg)?;
125 }
126 Ok(())
127 }
128 Self::DuplicateWebhook(msg) => {
129 write!(f, "DuplicateWebhook")?;
130 if let Some(msg) = msg {
131 write!(f, ": {}", msg)?;
132 }
133 Ok(())
134 }
135 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
136 }
137 }
138}
139
140pub struct UpdateWebhookResponse;
142impl jacquard_common::xrpc::XrpcResp for UpdateWebhookResponse {
143 const NSID: &'static str = "place.stream.server.updateWebhook";
144 const ENCODING: &'static str = "application/json";
145 type Output<'de> = UpdateWebhookOutput<'de>;
146 type Err<'de> = UpdateWebhookError<'de>;
147}
148
149impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateWebhook<'a> {
150 const NSID: &'static str = "place.stream.server.updateWebhook";
151 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
152 "application/json",
153 );
154 type Response = UpdateWebhookResponse;
155}
156
157pub struct UpdateWebhookRequest;
159impl jacquard_common::xrpc::XrpcEndpoint for UpdateWebhookRequest {
160 const PATH: &'static str = "/xrpc/place.stream.server.updateWebhook";
161 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
162 "application/json",
163 );
164 type Request<'de> = UpdateWebhook<'de>;
165 type Response = UpdateWebhookResponse;
166}