pub struct Webhooks { /* private fields */ }Expand description
A registry of typed webhook handlers plus the listener registration that makes One send them.
Built fluently; every per-event method is generated from the SDK spec’s event catalog.
Implementations§
Source§impl Webhooks
impl Webhooks
Sourcepub fn max_event_age(self, max_age: Duration) -> Self
pub fn max_event_age(self, max_age: Duration) -> Self
Rejects deliveries whose event is older than max_age.
Off by default, and not replay protection. The signed timestamp is
when the event occurred, not when this attempt was sent: the server
retries on a 30 * (2^n - 1) second backoff over five attempts, and a
backed-up delivery queue can push an authentic first attempt arbitrarily
far past the event. Any window therefore rejects genuine deliveries once
the server is behind, which is exactly when you least want to drop them.
Deduplicate on Delivery::id instead - it is stable across retries.
Real replay protection needs a per-attempt signed timestamp, which is a
server-side signing change.
Sourcepub fn connection<F>(self, key: impl Into<String>, block: F) -> Self
pub fn connection<F>(self, key: impl Into<String>, block: F) -> Self
Registers handlers scoped to one connection: they fire only for deliveries carrying that connection’s key.
The block form keeps the scope lexical, so a reader never has to scan backwards to work out which connection a handler belongs to, and only the connection-carrying events are offered inside it.
Sourcepub fn on_any<F, Fut, Output>(self, handler: F) -> Self
pub fn on_any<F, Fut, Output>(self, handler: F) -> Self
Registers a handler fired for every verified delivery, whatever its event type. Runs after event-specific handlers.
“Every” means every event in this SDK build’s catalog, which is what
Webhooks::listen subscribes to. An event the server adds after this
build was released is not in that list and will not be delivered, so
regenerate the SDK to pick up new events. A delivery for an unrecognized
type still verifies and reaches this handler with
Delivery::event_type as None - that path exists for a subscription
edited outside the SDK, not as forward compatibility.
Sourcepub fn events(&self) -> Vec<WebhookEventType>
pub fn events(&self) -> Vec<WebhookEventType>
The event types Webhooks::listen subscribes to.
An unscoped catch-all subscribes to this build’s whole catalog. The
server matches exact event strings, so an event added after this build
was released is not covered - see Webhooks::on_any.
A catch-all scoped to a connection adds only the connection-carrying
events. The server cannot filter by connection, so subscribing to
account-level events would just ship deliveries accepts discards.
Sourcepub fn verify(
&self,
raw_body: &[u8],
signature: &str,
) -> Result<Delivery, WebhookError>
pub fn verify( &self, raw_body: &[u8], signature: &str, ) -> Result<Delivery, WebhookError>
Verifies the signature and parses the body without dispatching. Use it when you want to route deliveries yourself.
Sourcepub fn verify_with(
secret: &SecretString,
tolerance: Option<Duration>,
raw_body: &[u8],
signature: &str,
) -> Result<Delivery, WebhookError>
pub fn verify_with( secret: &SecretString, tolerance: Option<Duration>, raw_body: &[u8], signature: &str, ) -> Result<Delivery, WebhookError>
Verifies a delivery without a registry, for callers that hold only the signing secret. The language bindings route through this so signature checking, the replay window, and its default all have exactly one implementation.
tolerance of None performs no age check, which is the default - see
Webhooks::max_event_age for why.
Sourcepub async fn handle(
&self,
raw_body: &[u8],
signature: &str,
) -> Result<Delivery, WebhookError>
pub async fn handle( &self, raw_body: &[u8], signature: &str, ) -> Result<Delivery, WebhookError>
Verifies, parses, and dispatches a delivery to every handler registered for its event type, then to the catch-all handlers.
Handlers run sequentially, so one that panics or hangs blocks the rest. Returns the delivery so callers can log it after dispatch.
Sourcepub async fn listen(
&self,
key: impl AsRef<str>,
url: impl AsRef<str>,
) -> Result<WebhookSubscriptionView, WebhookError>
pub async fn listen( &self, key: impl AsRef<str>, url: impl AsRef<str>, ) -> Result<WebhookSubscriptionView, WebhookError>
Registers this listener with One under the stable name key, pointing
at url and subscribing to exactly the events handlers were attached
for.
Idempotent: calling it on every boot reconciles the one listener named
key rather than accumulating duplicates, so url and the event set
can change freely between runs.
Sourcepub async fn register_listener(
client: &One,
key: &str,
url: &str,
events: &[&str],
secret: &SecretString,
) -> Result<CallResponse<WebhookSubscriptionView>, WebhookError>
pub async fn register_listener( client: &One, key: &str, url: &str, events: &[&str], secret: &SecretString, ) -> Result<CallResponse<WebhookSubscriptionView>, WebhookError>
Performs the listener upsert against the API.
The route, the request shape, and the percent-encoding of key live
here only - the language bindings call this rather than rebuilding the
request, so there is one definition of what registering a listener
means. The raw response metadata is retained for language bindings.
Source§impl Webhooks
impl Webhooks
Sourcepub fn api_key_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ApiKeyCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn api_key_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ApiKeyCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for api_key.created.
Sourcepub fn api_key_revoked<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ApiKeyRevokedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn api_key_revoked<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ApiKeyRevokedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for api_key.revoked.
Sourcepub fn connection_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ConnectionCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn connection_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ConnectionCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for connection.created.
Sourcepub fn connection_deleted<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ConnectionDeletedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn connection_deleted<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ConnectionDeletedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for connection.deleted.
Sourcepub fn connection_oauth_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ConnectionOAuthCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn connection_oauth_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ConnectionOAuthCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for connection.oauth.created.
Sourcepub fn connection_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ConnectionUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn connection_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ConnectionUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for connection.updated.
Sourcepub fn grant_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<GrantCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn grant_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<GrantCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for grant.created.
Sourcepub fn grant_revoked<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<GrantRevokedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn grant_revoked<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<GrantRevokedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for grant.revoked.
Sourcepub fn grant_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<GrantUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn grant_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<GrantUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for grant.updated.
Sourcepub fn member_added<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<MemberAddedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn member_added<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<MemberAddedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for member.added.
Sourcepub fn member_removed<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<MemberRemovedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn member_removed<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<MemberRemovedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for member.removed.
Sourcepub fn member_role_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<MemberRoleUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn member_role_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<MemberRoleUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for member.role_updated.
Sourcepub fn oauth_failed<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OAuthFailedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn oauth_failed<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OAuthFailedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for oauth.failed.
Sourcepub fn oauth_refreshed<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OAuthRefreshedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn oauth_refreshed<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OAuthRefreshedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for oauth.refreshed.
Sourcepub fn organization_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OrganizationCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn organization_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OrganizationCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for organization.created.
Sourcepub fn organization_deleted<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OrganizationDeletedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn organization_deleted<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OrganizationDeletedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for organization.deleted.
Sourcepub fn organization_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OrganizationUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn organization_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<OrganizationUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for organization.updated.
Sourcepub fn passthrough_executed<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<PassthroughExecutedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn passthrough_executed<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<PassthroughExecutedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for passthrough.executed.
Sourcepub fn project_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ProjectCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn project_created<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ProjectCreatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for project.created.
Sourcepub fn project_deleted<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ProjectDeletedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn project_deleted<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ProjectDeletedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for project.deleted.
Sourcepub fn project_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ProjectUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
pub fn project_updated<F, Fut, Output>(self, handler: F) -> Selfwhere
F: Fn(Delivery<ProjectUpdatedPayload>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Output> + Send + 'static,
Output: WebhookHandlerOutput + Send + 'static,
Registers a handler for project.updated.