Skip to main content

uarp_sdk/generated/api/
webhooks.rs

1// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
2//!
3//! Webhook subscriptions
4
5#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::client::{Client, Request, NO_BODY, NO_QUERY};
11use crate::error::Result;
12use crate::generated::models;
13use crate::multipart::{field_text, FilePart};
14use crate::util::encode_path;
15
16/// Query and header parameters for `sensorWebhook`.
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
18pub struct SensorWebhookParams {
19    /// Hex-encoded HMAC-SHA256 of the request body using the subscription's signing secret.
20    #[serde(skip)]
21    pub x_sensor_signature: String,
22}
23
24/// Webhook subscriptions
25#[derive(Debug, Clone)]
26pub struct WebhooksApi {
27    pub(crate) client: Client,
28}
29
30impl Client {
31    /// Webhook subscriptions
32    pub fn webhooks(&self) -> WebhooksApi {
33        WebhooksApi { client: self.clone() }
34    }
35}
36
37impl WebhooksApi {
38    /// Create a webhook subscription
39    ///
40    /// `POST /api/v1/webhooks`
41    ///
42    /// Required scopes: `webhooks:write`.
43    pub async fn create(&self, body: &models::CreateWebhookRequest) -> Result<models::WebhookSubscription> {
44        self.client
45            .request_json(Request {
46                method: Method::POST,
47                path: "/api/v1/webhooks".to_string(),
48                query: NO_QUERY,
49                body: Some(body),
50                headers: Vec::new(),
51                idempotent: true,
52            })
53            .await
54    }
55
56    /// Delete a webhook subscription
57    ///
58    /// `DELETE /api/v1/webhooks/{webhookId}`
59    ///
60    /// Required scopes: `webhooks:write`.
61    pub async fn delete(&self, webhook_id: &str) -> Result<models::DeleteWebhookResponse> {
62        self.client
63            .request_json(Request {
64                method: Method::DELETE,
65                path: format!("/api/v1/webhooks/{}", encode_path(webhook_id)),
66                query: NO_QUERY,
67                body: NO_BODY,
68                headers: Vec::new(),
69                idempotent: true,
70            })
71            .await
72    }
73
74    /// Get a webhook subscription
75    ///
76    /// `GET /api/v1/webhooks/{webhookId}`
77    ///
78    /// Required scopes: `webhooks:read`.
79    pub async fn get(&self, webhook_id: &str) -> Result<models::WebhookSubscription> {
80        self.client
81            .request_json(Request {
82                method: Method::GET,
83                path: format!("/api/v1/webhooks/{}", encode_path(webhook_id)),
84                query: NO_QUERY,
85                body: NO_BODY,
86                headers: Vec::new(),
87                idempotent: false,
88            })
89            .await
90    }
91
92    /// List webhook subscriptions
93    ///
94    /// `GET /api/v1/webhooks`
95    ///
96    /// Required scopes: `webhooks:read`.
97    pub async fn list(&self) -> Result<models::ListWebhooksResponse> {
98        self.client
99            .request_json(Request {
100                method: Method::GET,
101                path: "/api/v1/webhooks".to_string(),
102                query: NO_QUERY,
103                body: NO_BODY,
104                headers: Vec::new(),
105                idempotent: false,
106            })
107            .await
108    }
109
110    /// List webhook deliveries
111    ///
112    /// `GET /api/v1/webhooks/{webhookId}/deliveries`
113    ///
114    /// Required scopes: `webhooks:read`.
115    pub async fn list_webhook_deliveries(&self, webhook_id: &str) -> Result<models::ListWebhookDeliveriesResponse> {
116        self.client
117            .request_json(Request {
118                method: Method::GET,
119                path: format!("/api/v1/webhooks/{}/deliveries", encode_path(webhook_id)),
120                query: NO_QUERY,
121                body: NO_BODY,
122                headers: Vec::new(),
123                idempotent: false,
124            })
125            .await
126    }
127
128    /// Sensor webhook (HMAC-authenticated, triggers an agent run)
129    ///
130    /// External-system webhook. Bypasses normal auth — `X-Sensor-Signature` header is HMAC-verified
131    /// against the per-subscription secret. On valid signature, fires an agent run with the request
132    /// body as input.
133    ///
134    /// `POST /api/v1/webhooks/sensor/{webhookId}`
135    pub async fn sensor_webhook(&self, webhook_id: &str, body: &serde_json::Map<String, serde_json::Value>, params: &SensorWebhookParams) -> Result<models::SensorWebhookResponse> {
136        let mut headers: Vec<(&'static str, String)> = Vec::new();
137        headers.push(("X-Sensor-Signature", params.x_sensor_signature.clone()));
138        self.client
139            .request_json(Request {
140                method: Method::POST,
141                path: format!("/api/v1/webhooks/sensor/{}", encode_path(webhook_id)),
142                query: NO_QUERY,
143                body: Some(body),
144                headers,
145                idempotent: true,
146            })
147            .await
148    }
149
150    /// Send test delivery
151    ///
152    /// Dispatch one synthetic event to this subscription's receiver, so an operator can confirm the
153    /// endpoint works before relying on it.
154    ///
155    /// Only an **active** subscription is delivered to — `WebhookManager.dispatch` filters on
156    /// status and silently matches nothing otherwise. A disabled subscription therefore answers
157    /// **422**, not 200: until 2026-08-20 it answered `{"test_sent": true}` with nothing sent, no
158    /// delivery row written and no dispatch line in the server log, which turns a misconfigured
159    /// integration into a confirmed one.
160    ///
161    /// `POST /api/v1/webhooks/{webhookId}/test`
162    ///
163    /// Required scopes: `webhooks:write`.
164    pub async fn test_webhook(&self, webhook_id: &str) -> Result<models::TestWebhookResponse> {
165        self.client
166            .request_json(Request {
167                method: Method::POST,
168                path: format!("/api/v1/webhooks/{}/test", encode_path(webhook_id)),
169                query: NO_QUERY,
170                body: NO_BODY,
171                headers: Vec::new(),
172                idempotent: true,
173            })
174            .await
175    }
176}