From 4edda6a46bdd8445fc5b64c58e1e86c8b87253fc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 20 Dec 2024 16:03:02 +0100 Subject: [PATCH] rust: Regenerate high-level API Reverting parts of the changes to avoid unnecessary breakage. --- ChangeLog.md | 3 + rust/src/api/authentication.rs | 20 ++++ rust/src/api/endpoint.rs | 179 ++++++++++++++++---------------- rust/src/api/event_type.rs | 76 +++++++------- rust/src/api/message.rs | 20 ++-- rust/src/api/message_attempt.rs | 76 ++++++++------ rust/src/api/mod.rs | 22 ++-- 7 files changed, 219 insertions(+), 177 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index f607489a2..6f12d0129 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,9 +7,12 @@ * Libs/JavaScript **(Breaking)**: Add more precise type annotations for `options` parameters on `MessageAttempt.list`, `MessageAttempt.listByMsg`, `MessageAttempt.listAttemptedMessages` and `MessageAttempt.listAttemptedDestinations` ([#1571]) +* Libs/Rust: Add `api::Authentication::expire_all` ([#1584]) +* Libs/Rust: Rename some `Options` types. The old names remain as deprecated type aliases ([#1584]) [#1568]: https://github.com/svix/svix-webhooks/pull/1568 [#1571]: https://github.com/svix/svix-webhooks/pull/1571 +[#1584]: https://github.com/svix/svix-webhooks/pull/1584 ## Version 1.44.0 * Libs/JavaScript: Revert packaging-related change because it broke for some users ([#1556]) diff --git a/rust/src/api/authentication.rs b/rust/src/api/authentication.rs index 332fb4fe9..9899df2e0 100644 --- a/rust/src/api/authentication.rs +++ b/rust/src/api/authentication.rs @@ -47,6 +47,26 @@ impl<'a> Authentication<'a> { .await } + /// Expire all of the tokens associated with a specific application. + pub async fn expire_all( + &self, + app_id: String, + application_token_expire_in: ApplicationTokenExpireIn, + options: Option, + ) -> Result<()> { + let PostOptions { idempotency_key } = options.unwrap_or_default(); + + authentication_api::v1_period_authentication_period_expire_all( + self.cfg, + authentication_api::V1PeriodAuthenticationPeriodExpireAllParams { + app_id, + application_token_expire_in, + idempotency_key, + }, + ) + .await + } + /// Logout an app token. /// /// Trying to log out other tokens will fail. diff --git a/rust/src/api/endpoint.rs b/rust/src/api/endpoint.rs index 4d9c7cba5..58f943185 100644 --- a/rust/src/api/endpoint.rs +++ b/rust/src/api/endpoint.rs @@ -14,13 +14,13 @@ pub struct EndpointListOptions { } #[derive(Default)] -pub struct EndpointStatsOptions { - /// Filter the range to data starting from this date +pub struct EndpointGetStatsOptions { + /// Filter the range to data starting from this date. /// /// RFC3339 date string. pub since: Option, - /// Filter the range to data ending by this date + /// Filter the range to data ending by this date. /// /// RFC3339 date string. pub until: Option, @@ -62,7 +62,7 @@ impl<'a> Endpoint<'a> { /// Create a new endpoint for the application. /// /// When `secret` is `null` the secret is automatically generated - /// (recommended) + /// (recommended). pub async fn create( &self, app_id: String, @@ -142,19 +142,15 @@ impl<'a> Endpoint<'a> { .await } - /// Get the endpoint's signing secret. - /// - /// This is used to verify the authenticity of the webhook. - /// For more information please refer to - /// [the consuming webhooks docs](https://docs.svix.com/consuming-webhooks/). - pub async fn get_secret( + /// Get the additional headers to be sent with the webhook. + pub async fn get_headers( &self, app_id: String, endpoint_id: String, - ) -> Result { - endpoint_api::v1_period_endpoint_period_get_secret( + ) -> Result { + endpoint_api::v1_period_endpoint_period_get_headers( self.cfg, - endpoint_api::V1PeriodEndpointPeriodGetSecretParams { + endpoint_api::V1PeriodEndpointPeriodGetHeadersParams { app_id, endpoint_id, }, @@ -162,22 +158,37 @@ impl<'a> Endpoint<'a> { .await } - /// Rotates the endpoint's signing secret. - /// - /// The previous secret will remain valid for the next 24 hours. - pub async fn rotate_secret( + /// Set the additional headers to be sent with the webhook. + pub async fn update_headers( &self, app_id: String, endpoint_id: String, - endpoint_secret_rotate_in: EndpointSecretRotateIn, + endpoint_headers_in: EndpointHeadersIn, ) -> Result<()> { - endpoint_api::v1_period_endpoint_period_rotate_secret( + endpoint_api::v1_period_endpoint_period_update_headers( self.cfg, - endpoint_api::V1PeriodEndpointPeriodRotateSecretParams { + endpoint_api::V1PeriodEndpointPeriodUpdateHeadersParams { app_id, endpoint_id, - endpoint_secret_rotate_in, - idempotency_key: None, + endpoint_headers_in, + }, + ) + .await + } + + /// Partially set the additional headers to be sent with the webhook. + pub async fn patch_headers( + &self, + app_id: String, + endpoint_id: String, + endpoint_headers_patch_in: EndpointHeadersPatchIn, + ) -> Result<()> { + endpoint_api::v1_period_endpoint_period_patch_headers( + self.cfg, + endpoint_api::V1PeriodEndpointPeriodPatchHeadersParams { + app_id, + endpoint_id, + endpoint_headers_patch_in, }, ) .await @@ -192,7 +203,7 @@ impl<'a> Endpoint<'a> { app_id: String, endpoint_id: String, recover_in: RecoverIn, - ) -> Result<()> { + ) -> Result { endpoint_api::v1_period_endpoint_period_recover( self.cfg, endpoint_api::V1PeriodEndpointPeriodRecoverParams { @@ -202,109 +213,118 @@ impl<'a> Endpoint<'a> { idempotency_key: None, }, ) - .await?; - Ok(()) + .await } - /// Get the additional headers to be sent with the webhook - pub async fn get_headers( + /// Replays messages to the endpoint. + /// + /// Only messages that were created after `since` will be sent. + /// Messages that were previously sent to the endpoint are not resent. + pub async fn replay_missing( &self, app_id: String, endpoint_id: String, - ) -> Result { - endpoint_api::v1_period_endpoint_period_get_headers( + replay_in: ReplayIn, + options: Option, + ) -> Result { + let PostOptions { idempotency_key } = options.unwrap_or_default(); + + endpoint_api::v1_period_endpoint_period_replay_missing( self.cfg, - endpoint_api::V1PeriodEndpointPeriodGetHeadersParams { + endpoint_api::V1PeriodEndpointPeriodReplayMissingParams { app_id, endpoint_id, + replay_in, + idempotency_key, }, ) .await } - /// Set the additional headers to be sent with the webhook - pub async fn update_headers( + /// Get the endpoint's signing secret. + /// + /// This is used to verify the authenticity of the webhook. + /// For more information please refer to [the consuming webhooks docs](https://docs.svix.com/consuming-webhooks/). + pub async fn get_secret( &self, app_id: String, endpoint_id: String, - endpoint_headers_in: EndpointHeadersIn, - ) -> Result<()> { - endpoint_api::v1_period_endpoint_period_update_headers( + ) -> Result { + endpoint_api::v1_period_endpoint_period_get_secret( self.cfg, - endpoint_api::V1PeriodEndpointPeriodUpdateHeadersParams { + endpoint_api::V1PeriodEndpointPeriodGetSecretParams { app_id, endpoint_id, - endpoint_headers_in, }, ) .await } - /// Partially set the additional headers to be sent with the webhook - pub async fn patch_headers( + /// Rotates the endpoint's signing secret. + /// + /// The previous secret will remain valid for the next 24 hours. + pub async fn rotate_secret( &self, app_id: String, endpoint_id: String, - endpoint_headers_patch_in: EndpointHeadersPatchIn, + endpoint_secret_rotate_in: EndpointSecretRotateIn, ) -> Result<()> { - endpoint_api::v1_period_endpoint_period_patch_headers( + endpoint_api::v1_period_endpoint_period_rotate_secret( self.cfg, - endpoint_api::V1PeriodEndpointPeriodPatchHeadersParams { + endpoint_api::V1PeriodEndpointPeriodRotateSecretParams { app_id, endpoint_id, - endpoint_headers_patch_in, + endpoint_secret_rotate_in, + idempotency_key: None, }, ) .await } - /// Get basic statistics for the endpoint. - pub async fn get_stats( + /// Send an example message for an event. + pub async fn send_example( &self, app_id: String, endpoint_id: String, - options: Option, - ) -> Result { - let EndpointStatsOptions { since, until } = options.unwrap_or_default(); + event_example_in: EventExampleIn, + options: Option, + ) -> Result { + let PostOptions { idempotency_key } = options.unwrap_or_default(); - endpoint_api::v1_period_endpoint_period_get_stats( + endpoint_api::v1_period_endpoint_period_send_example( self.cfg, - endpoint_api::V1PeriodEndpointPeriodGetStatsParams { + endpoint_api::V1PeriodEndpointPeriodSendExampleParams { app_id, endpoint_id, - since, - until, + event_example_in, + idempotency_key, }, ) .await } - /// Replays messages to the endpoint. - /// - /// Only messages that were created after `since` will be sent. Messages - /// that were previously sent to the endpoint are not resent. - pub async fn replay_missing( + /// Get basic statistics for the endpoint. + pub async fn get_stats( &self, app_id: String, endpoint_id: String, - replay_in: ReplayIn, - options: Option, - ) -> Result<()> { - let PostOptions { idempotency_key } = options.unwrap_or_default(); - endpoint_api::v1_period_endpoint_period_replay_missing( + options: Option, + ) -> Result { + let EndpointGetStatsOptions { since, until } = options.unwrap_or_default(); + + endpoint_api::v1_period_endpoint_period_get_stats( self.cfg, - endpoint_api::V1PeriodEndpointPeriodReplayMissingParams { + endpoint_api::V1PeriodEndpointPeriodGetStatsParams { app_id, endpoint_id, - replay_in, - idempotency_key, + since, + until, }, ) - .await?; - Ok(()) + .await } - /// Get the transformation code associated with this endpoint + /// Get the transformation code associated with this endpoint. pub async fn transformation_get( &self, app_id: String, @@ -320,7 +340,7 @@ impl<'a> Endpoint<'a> { .await } - /// Set or unset the transformation code associated with this endpoint + /// Set or unset the transformation code associated with this endpoint. pub async fn transformation_partial_update( &self, app_id: String, @@ -337,25 +357,4 @@ impl<'a> Endpoint<'a> { ) .await } - - /// Send an example message for an event - pub async fn send_example( - &self, - app_id: String, - endpoint_id: String, - event_example_in: EventExampleIn, - options: Option, - ) -> Result { - let PostOptions { idempotency_key } = options.unwrap_or_default(); - endpoint_api::v1_period_endpoint_period_send_example( - self.cfg, - endpoint_api::V1PeriodEndpointPeriodSendExampleParams { - app_id, - endpoint_id, - event_example_in, - idempotency_key, - }, - ) - .await - } } diff --git a/rust/src/api/event_type.rs b/rust/src/api/event_type.rs index f450f3dc2..7032b0117 100644 --- a/rust/src/api/event_type.rs +++ b/rust/src/api/event_type.rs @@ -9,12 +9,15 @@ pub struct EventTypeListOptions { /// The iterator returned from a prior invocation pub iterator: Option, + /// The sorting order of the returned items + pub order: Option, + /// When `true` archived (deleted but not expunged) items are included in - /// the response + /// the response. pub include_archived: Option, /// When `true` the full item (including the schema) is included in the - /// response + /// response. pub with_content: Option, } @@ -35,6 +38,7 @@ impl<'a> EventType<'a> { let EventTypeListOptions { limit, iterator, + order, include_archived, with_content, } = options.unwrap_or_default(); @@ -44,8 +48,7 @@ impl<'a> EventType<'a> { event_type_api::V1PeriodEventTypePeriodListParams { limit, iterator, - // FIXME: not included for backwards compatibility, for now - order: None, + order, include_archived, with_content, }, @@ -76,6 +79,28 @@ impl<'a> EventType<'a> { .await } + /// Given an OpenAPI spec, create new or update existing event types. + /// If an existing `archived` event type is updated, it will be unarchived. + /// + /// The importer will convert all webhooks found in the either the + /// `webhooks` or `x-webhooks` top-level. + pub async fn import_openapi( + &self, + event_type_import_open_api_in: EventTypeImportOpenApiIn, + options: Option, + ) -> Result { + let PostOptions { idempotency_key } = options.unwrap_or_default(); + + event_type_api::v1_period_event_type_period_import_openapi( + self.cfg, + event_type_api::V1PeriodEventTypePeriodImportOpenapiParams { + event_type_import_open_api_in, + idempotency_key, + }, + ) + .await + } + /// Get an event type. pub async fn get(&self, event_type_name: String) -> Result { event_type_api::v1_period_event_type_period_get( @@ -101,28 +126,12 @@ impl<'a> EventType<'a> { .await } - /// Partially update an event type. - pub async fn patch( - &self, - event_type_name: String, - event_type_patch: EventTypePatch, - ) -> Result { - event_type_api::v1_period_event_type_period_patch( - self.cfg, - event_type_api::V1PeriodEventTypePeriodPatchParams { - event_type_name, - event_type_patch, - }, - ) - .await - } - /// Archive an event type. /// /// Endpoints already configured to filter on an event type will continue to /// do so after archival. However, new messages can not be sent with it /// and endpoints can not filter on it. An event type can be unarchived - /// with the create operation. + /// with the [create operation][Self::create]. pub async fn delete(&self, event_type_name: String) -> Result<()> { event_type_api::v1_period_event_type_period_delete( self.cfg, @@ -134,24 +143,17 @@ impl<'a> EventType<'a> { .await } - /// Given an OpenAPI spec, create new or update existing event types. - /// - /// If an existing `archived` event type is updated, it will be unarchived. - /// - /// The importer will convert all webhooks found in the either the - /// `webhooks` or `x-webhooks` top-level. - pub async fn import_openapi( + /// Partially update an event type. + pub async fn patch( &self, - event_type_import_open_api_in: EventTypeImportOpenApiIn, - options: Option, - ) -> Result { - let PostOptions { idempotency_key } = options.unwrap_or_default(); - - event_type_api::v1_period_event_type_period_import_openapi( + event_type_name: String, + event_type_patch: EventTypePatch, + ) -> Result { + event_type_api::v1_period_event_type_period_patch( self.cfg, - event_type_api::V1PeriodEventTypePeriodImportOpenapiParams { - event_type_import_open_api_in, - idempotency_key, + event_type_api::V1PeriodEventTypePeriodPatchParams { + event_type_name, + event_type_patch, }, ) .await diff --git a/rust/src/api/message.rs b/rust/src/api/message.rs index 40c4af8dc..256a9f414 100644 --- a/rust/src/api/message.rs +++ b/rust/src/api/message.rs @@ -9,23 +9,23 @@ pub struct MessageListOptions { /// The iterator returned from a prior invocation pub iterator: Option, - /// Filter response based on the channel + /// Filter response based on the channel. pub channel: Option, - /// Only include items created before a certain date + /// Only include items created before a certain date. /// /// RFC3339 date string. pub before: Option, - /// Only include items created after a certain date + /// Only include items created after a certain date. /// /// RFC3339 date string. pub after: Option, - /// When `true` message payloads are included in the response + /// When `true` message payloads are included in the response. pub with_content: Option, - /// Filter messages matching the provided tag + /// Filter messages matching the provided tag. pub tag: Option, /// Filter response based on the event type @@ -117,8 +117,8 @@ impl<'a> Message<'a> { message_api::V1PeriodMessagePeriodCreateParams { app_id, message_in, - idempotency_key, with_content: None, + idempotency_key, }, ) .await @@ -137,11 +137,11 @@ impl<'a> Message<'a> { .await } - /// Delete the given message's payload. Useful in cases when a message was - /// accidentally sent with sensitive content. + /// Delete the given message's payload. /// - /// The message can't be replayed or resent once its payload has been - /// deleted or expired. + /// Useful in cases when a message was accidentally sent with sensitive + /// content. The message can't be replayed or resent once its payload + /// has been deleted or expired. pub async fn expunge_content(&self, app_id: String, msg_id: String) -> Result<()> { message_api::v1_period_message_period_expunge_content( self.cfg, diff --git a/rust/src/api/message_attempt.rs b/rust/src/api/message_attempt.rs index a9f2646ba..821705dd6 100644 --- a/rust/src/api/message_attempt.rs +++ b/rust/src/api/message_attempt.rs @@ -1,4 +1,3 @@ -use super::ListOptions; use crate::{apis::message_attempt_api, error::Result, models::*, Configuration}; #[derive(Default)] @@ -43,7 +42,7 @@ pub struct MessageAttemptListByEndpointOptions { } #[derive(Default)] -pub struct MessageAttemptListOptions { +pub struct MessageAttemptListByMsgOptions { /// Limit the number of returned items pub limit: Option, @@ -118,6 +117,15 @@ pub struct MessageAttemptListAttemptedMessagesOptions { pub event_types: Option>, } +#[derive(Default)] +pub struct MessageAttemptListAttemptedDestinationsOptions { + /// Limit the number of returned items + pub limit: Option, + + /// The iterator returned from a prior invocation + pub iterator: Option, +} + pub struct MessageAttempt<'a> { cfg: &'a Configuration, } @@ -175,7 +183,7 @@ impl<'a> MessageAttempt<'a> { .await } - /// List attempts by message id + /// List attempts by message ID. /// /// Note that by default this endpoint is limited to retrieving 90 days' /// worth of data relative to now or, if an iterator is provided, 90 @@ -186,9 +194,9 @@ impl<'a> MessageAttempt<'a> { &self, app_id: String, msg_id: String, - options: Option, + options: Option, ) -> Result { - let MessageAttemptListOptions { + let MessageAttemptListByMsgOptions { limit, iterator, status, @@ -271,37 +279,15 @@ impl<'a> MessageAttempt<'a> { .await } - /// List endpoints attempted by a given message. Additionally includes - /// metadata about the latest message attempt. By default, endpoints are - /// listed in ascending order by ID. - pub async fn list_attempted_destinations( - &self, - app_id: String, - msg_id: String, - options: Option, - ) -> Result { - let ListOptions { iterator, limit } = options.unwrap_or_default(); - message_attempt_api::v1_period_message_attempt_period_list_attempted_destinations( - self.cfg, - message_attempt_api::V1PeriodMessageAttemptPeriodListAttemptedDestinationsParams { - app_id, - msg_id, - iterator, - limit, - }, - ) - .await - } - #[deprecated = "Use `list_by_msg` instead, setting the `endpoint_id` in `options`."] pub async fn list_attempts_for_endpoint( &self, app_id: String, msg_id: String, endpoint_id: String, - options: Option, + options: Option, ) -> Result { - let MessageAttemptListOptions { + let MessageAttemptListByMsgOptions { iterator, limit, event_types, @@ -351,8 +337,11 @@ impl<'a> MessageAttempt<'a> { .await } - /// Deletes the given attempt's response body. Useful when an endpoint - /// accidentally returned sensitive content. + /// Deletes the given attempt's response body. + /// + /// Useful when an endpoint accidentally returned sensitive content. + /// The message can't be replayed or resent once its payload has been + /// deleted or expired. pub async fn expunge_content( &self, app_id: String, @@ -370,6 +359,31 @@ impl<'a> MessageAttempt<'a> { .await } + /// List endpoints attempted by a given message. + /// + /// Additionally includes metadata about the latest message attempt. + /// By default, endpoints are listed in ascending order by ID. + pub async fn list_attempted_destinations( + &self, + app_id: String, + msg_id: String, + options: Option, + ) -> Result { + let MessageAttemptListAttemptedDestinationsOptions { limit, iterator } = + options.unwrap_or_default(); + + message_attempt_api::v1_period_message_attempt_period_list_attempted_destinations( + self.cfg, + message_attempt_api::V1PeriodMessageAttemptPeriodListAttemptedDestinationsParams { + app_id, + msg_id, + limit, + iterator, + }, + ) + .await + } + /// Resend a message to the specified endpoint. pub async fn resend(&self, app_id: String, msg_id: String, endpoint_id: String) -> Result<()> { message_attempt_api::v1_period_message_attempt_period_resend( diff --git a/rust/src/api/mod.rs b/rust/src/api/mod.rs index 39cbf65fb..df39ed0f3 100644 --- a/rust/src/api/mod.rs +++ b/rust/src/api/mod.rs @@ -1,3 +1,5 @@ +#![warn(unreachable_pub)] + use std::sync::Arc; use hyper_util::{client::legacy::Client as HyperClient, rt::TokioExecutor}; @@ -39,13 +41,14 @@ pub use self::{ application::{Application, ApplicationListOptions}, authentication::Authentication, background_task::{BackgroundTask, BackgroundTaskListOptions}, - endpoint::{Endpoint, EndpointListOptions, EndpointStatsOptions}, + endpoint::{Endpoint, EndpointGetStatsOptions, EndpointListOptions}, event_type::{EventType, EventTypeListOptions}, integration::{Integration, IntegrationListOptions}, message::{Message, MessageListOptions}, message_attempt::{ - MessageAttempt, MessageAttemptListAttemptedMessagesOptions, - MessageAttemptListByEndpointOptions, MessageAttemptListOptions, + MessageAttempt, MessageAttemptListAttemptedDestinationsOptions, + MessageAttemptListAttemptedMessagesOptions, MessageAttemptListByEndpointOptions, + MessageAttemptListByMsgOptions, }, operational_webhook_endpoint::{ OperationalWebhookEndpoint, OperationalWebhookEndpointListOptions, @@ -53,6 +56,13 @@ pub use self::{ statistics::{AggregateAppStatsOptions, Statistics}, }; +#[deprecated = "Use EndpointGetStatusOptions instead"] +pub type EndpointStatsOptions = EndpointGetStatsOptions; +#[deprecated = "Use MessageAttemptListByMsgOptions instead"] +pub type MessageAttemptListOptions = MessageAttemptListByMsgOptions; +#[deprecated = "Use MessageAttemptListAttemptedDestinationsOptions instead"] +pub type ListOptions = MessageAttemptListAttemptedDestinationsOptions; + pub struct SvixOptions { pub debug: bool, pub server_url: Option, @@ -183,12 +193,6 @@ pub struct PostOptions { pub idempotency_key: Option, } -#[derive(Default)] -pub struct ListOptions { - pub iterator: Option, - pub limit: Option, -} - #[cfg(test)] mod tests { use crate::api::Svix;