Skip to content

Commit

Permalink
rust: Regenerate high-level API
Browse files Browse the repository at this point in the history
Reverting parts of the changes to avoid unnecessary breakage.
  • Loading branch information
svix-jplatte committed Dec 20, 2024
1 parent becab77 commit 4edda6a
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 177 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
20 changes: 20 additions & 0 deletions rust/src/api/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostOptions>,
) -> 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.
Expand Down
179 changes: 89 additions & 90 deletions rust/src/api/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// Filter the range to data ending by this date
/// Filter the range to data ending by this date.
///
/// RFC3339 date string.
pub until: Option<String>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -142,42 +142,53 @@ 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<EndpointSecretOut> {
endpoint_api::v1_period_endpoint_period_get_secret(
) -> Result<EndpointHeadersOut> {
endpoint_api::v1_period_endpoint_period_get_headers(
self.cfg,
endpoint_api::V1PeriodEndpointPeriodGetSecretParams {
endpoint_api::V1PeriodEndpointPeriodGetHeadersParams {
app_id,
endpoint_id,
},
)
.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
Expand All @@ -192,7 +203,7 @@ impl<'a> Endpoint<'a> {
app_id: String,
endpoint_id: String,
recover_in: RecoverIn,
) -> Result<()> {
) -> Result<RecoverOut> {
endpoint_api::v1_period_endpoint_period_recover(
self.cfg,
endpoint_api::V1PeriodEndpointPeriodRecoverParams {
Expand All @@ -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<EndpointHeadersOut> {
endpoint_api::v1_period_endpoint_period_get_headers(
replay_in: ReplayIn,
options: Option<PostOptions>,
) -> Result<ReplayOut> {
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<EndpointSecretOut> {
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<EndpointStatsOptions>,
) -> Result<EndpointStats> {
let EndpointStatsOptions { since, until } = options.unwrap_or_default();
event_example_in: EventExampleIn,
options: Option<PostOptions>,
) -> Result<MessageOut> {
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<PostOptions>,
) -> Result<()> {
let PostOptions { idempotency_key } = options.unwrap_or_default();
endpoint_api::v1_period_endpoint_period_replay_missing(
options: Option<EndpointGetStatsOptions>,
) -> Result<EndpointStats> {
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,
Expand All @@ -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,
Expand All @@ -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<PostOptions>,
) -> Result<MessageOut> {
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
}
}
Loading

0 comments on commit 4edda6a

Please sign in to comment.