jacquard_api/place_stream/server/
create_webhook.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.server.createWebhook
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[jacquard_derive::lexicon]
9#[derive(
10    serde::Serialize,
11    serde::Deserialize,
12    Debug,
13    Clone,
14    PartialEq,
15    Eq,
16    bon::Builder,
17    jacquard_derive::IntoStatic
18)]
19#[serde(rename_all = "camelCase")]
20#[builder(start_fn = new)]
21pub struct CreateWebhook<'a> {
22    ///Whether this webhook should be active upon creation.
23    #[serde(skip_serializing_if = "std::option::Option::is_none")]
24    pub active: std::option::Option<bool>,
25    ///A description of what this webhook is used for.
26    #[serde(skip_serializing_if = "std::option::Option::is_none")]
27    #[serde(borrow)]
28    #[builder(into)]
29    pub description: std::option::Option<jacquard_common::CowStr<'a>>,
30    ///The types of events this webhook should receive.
31    #[serde(borrow)]
32    pub events: Vec<jacquard_common::CowStr<'a>>,
33    ///A user-friendly name for this webhook.
34    #[serde(skip_serializing_if = "std::option::Option::is_none")]
35    #[serde(borrow)]
36    #[builder(into)]
37    pub name: std::option::Option<jacquard_common::CowStr<'a>>,
38    ///Text to prepend to webhook messages.
39    #[serde(skip_serializing_if = "std::option::Option::is_none")]
40    #[serde(borrow)]
41    #[builder(into)]
42    pub prefix: std::option::Option<jacquard_common::CowStr<'a>>,
43    ///Text replacement rules for webhook messages.
44    #[serde(skip_serializing_if = "std::option::Option::is_none")]
45    #[serde(borrow)]
46    pub rewrite: std::option::Option<Vec<crate::place_stream::server::RewriteRule<'a>>>,
47    ///Text to append to webhook messages.
48    #[serde(skip_serializing_if = "std::option::Option::is_none")]
49    #[serde(borrow)]
50    #[builder(into)]
51    pub suffix: std::option::Option<jacquard_common::CowStr<'a>>,
52    ///The webhook URL where events will be sent.
53    #[serde(borrow)]
54    pub url: jacquard_common::types::string::Uri<'a>,
55    #[serde(flatten)]
56    #[serde(borrow)]
57    #[builder(default)]
58    pub extra_data: ::std::collections::BTreeMap<
59        ::jacquard_common::smol_str::SmolStr,
60        ::jacquard_common::types::value::Data<'a>,
61    >,
62}
63
64#[jacquard_derive::lexicon]
65#[derive(
66    serde::Serialize,
67    serde::Deserialize,
68    Debug,
69    Clone,
70    PartialEq,
71    Eq,
72    jacquard_derive::IntoStatic
73)]
74#[serde(rename_all = "camelCase")]
75pub struct CreateWebhookOutput<'a> {
76    #[serde(borrow)]
77    pub webhook: crate::place_stream::server::Webhook<'a>,
78}
79
80#[jacquard_derive::open_union]
81#[derive(
82    serde::Serialize,
83    serde::Deserialize,
84    Debug,
85    Clone,
86    PartialEq,
87    Eq,
88    thiserror::Error,
89    miette::Diagnostic,
90    jacquard_derive::IntoStatic
91)]
92#[serde(tag = "error", content = "message")]
93#[serde(bound(deserialize = "'de: 'a"))]
94pub enum CreateWebhookError<'a> {
95    ///The provided webhook URL is invalid or unreachable.
96    #[serde(rename = "InvalidUrl")]
97    InvalidUrl(std::option::Option<String>),
98    ///A webhook with this URL already exists for this user.
99    #[serde(rename = "DuplicateWebhook")]
100    DuplicateWebhook(std::option::Option<String>),
101    ///The user has reached their maximum number of webhooks.
102    #[serde(rename = "TooManyWebhooks")]
103    TooManyWebhooks(std::option::Option<String>),
104}
105
106impl std::fmt::Display for CreateWebhookError<'_> {
107    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
108        match self {
109            Self::InvalidUrl(msg) => {
110                write!(f, "InvalidUrl")?;
111                if let Some(msg) = msg {
112                    write!(f, ": {}", msg)?;
113                }
114                Ok(())
115            }
116            Self::DuplicateWebhook(msg) => {
117                write!(f, "DuplicateWebhook")?;
118                if let Some(msg) = msg {
119                    write!(f, ": {}", msg)?;
120                }
121                Ok(())
122            }
123            Self::TooManyWebhooks(msg) => {
124                write!(f, "TooManyWebhooks")?;
125                if let Some(msg) = msg {
126                    write!(f, ": {}", msg)?;
127                }
128                Ok(())
129            }
130            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
131        }
132    }
133}
134
135///Response type for
136///place.stream.server.createWebhook
137pub struct CreateWebhookResponse;
138impl jacquard_common::xrpc::XrpcResp for CreateWebhookResponse {
139    const NSID: &'static str = "place.stream.server.createWebhook";
140    const ENCODING: &'static str = "application/json";
141    type Output<'de> = CreateWebhookOutput<'de>;
142    type Err<'de> = CreateWebhookError<'de>;
143}
144
145impl<'de> jacquard_common::xrpc::XrpcRequest<'de> for CreateWebhook<'de> {
146    const NSID: &'static str = "place.stream.server.createWebhook";
147    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
148        "application/json",
149    );
150    type Response = CreateWebhookResponse;
151}
152
153///Endpoint type for
154///place.stream.server.createWebhook
155pub struct CreateWebhookRequest;
156impl jacquard_common::xrpc::XrpcEndpoint for CreateWebhookRequest {
157    const PATH: &'static str = "/xrpc/place.stream.server.createWebhook";
158    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
159        "application/json",
160    );
161    type Request<'de> = CreateWebhook<'de>;
162    type Response = CreateWebhookResponse;
163}