From 5ef9bddcb8c31d3b82bf6570a28e71ea7c8a36c5 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 31 Mar 2026 21:49:33 -0400 Subject: [PATCH] new struct for webhooks --- crates/api_clients/fal_client/src/lib.rs | 1 + .../fal_client/src/webhook_api/mod.rs | 1 + .../src/webhook_api/raw_webhook_payload.rs | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 crates/api_clients/fal_client/src/webhook_api/mod.rs create mode 100644 crates/api_clients/fal_client/src/webhook_api/raw_webhook_payload.rs diff --git a/crates/api_clients/fal_client/src/lib.rs b/crates/api_clients/fal_client/src/lib.rs index 55ebd9a579..fd1bbfa3be 100644 --- a/crates/api_clients/fal_client/src/lib.rs +++ b/crates/api_clients/fal_client/src/lib.rs @@ -5,3 +5,4 @@ pub mod error; pub mod model; pub mod requests; pub mod utils; +pub mod webhook_api; diff --git a/crates/api_clients/fal_client/src/webhook_api/mod.rs b/crates/api_clients/fal_client/src/webhook_api/mod.rs new file mode 100644 index 0000000000..71e3a2ae06 --- /dev/null +++ b/crates/api_clients/fal_client/src/webhook_api/mod.rs @@ -0,0 +1 @@ +pub mod raw_webhook_payload; \ No newline at end of file diff --git a/crates/api_clients/fal_client/src/webhook_api/raw_webhook_payload.rs b/crates/api_clients/fal_client/src/webhook_api/raw_webhook_payload.rs new file mode 100644 index 0000000000..6b9f8946b3 --- /dev/null +++ b/crates/api_clients/fal_client/src/webhook_api/raw_webhook_payload.rs @@ -0,0 +1,43 @@ +use serde::Deserialize; +use serde_json::Value; + +/// The value FAL sends to webhook endpoints. +#[derive(Deserialize, Debug, Clone)] +struct RawWebhookPayload { + /// Value originally used in the queue API + pub request_id: String, + + /// Mostly the same as `request_id`, but if the request failed and was retried, + /// then gateway_request_id will have the value of the last tried request, + /// while request_id will be the value used in the queue API. + pub gateway_request_id: String, + + /// Status of the request: OK or ERROR. + pub status: WebhookStatus, + + /// When an error happens, the status will be ERROR. + /// The error property will contain a message and payload will contain the error details. + /// eg. ""Invalid status code: 422" + pub error: Option, + + /// Payload of the webhook (typically present) + /// THIS FIELD IS HIGHLY VARIABLE JSON. + /// This is present for both *success* and *failure* cases, + /// though the payload differs. Sometimes it is absent. + pub payload: Option, + + /// In rare instances, if there was an error encoding the payload, + /// this may be set. This can seemingly be set on "OK" responses. + pub payload_error: Option, +} + +#[derive(Deserialize, Debug, Clone, Copy)] +pub enum WebhookStatus { + /// Success case + #[serde(alias = "OK")] + Ok, + + /// Failure case + #[serde(alias = "ERROR")] + Error +}