Skip to main content

Webhooks

Struct Webhooks 

Source
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

Source

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.

Source

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.

Source

pub fn on_any<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn api_key_created<F, Fut, Output>(self, handler: F) -> Self
where 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.

Source

pub fn api_key_revoked<F, Fut, Output>(self, handler: F) -> Self
where 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.

Source

pub fn connection_created<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<ConnectionCreatedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for connection.created.

Source

pub fn connection_deleted<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<ConnectionDeletedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for connection.deleted.

Source

pub fn connection_oauth_created<F, Fut, Output>(self, handler: F) -> Self
where 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.

Source

pub fn connection_updated<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<ConnectionUpdatedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for connection.updated.

Source

pub fn grant_created<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<GrantCreatedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for grant.created.

Source

pub fn grant_revoked<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<GrantRevokedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for grant.revoked.

Source

pub fn grant_updated<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<GrantUpdatedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for grant.updated.

Source

pub fn member_added<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<MemberAddedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for member.added.

Source

pub fn member_removed<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<MemberRemovedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for member.removed.

Source

pub fn member_role_updated<F, Fut, Output>(self, handler: F) -> Self
where 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.

Source

pub fn oauth_failed<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<OAuthFailedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for oauth.failed.

Source

pub fn oauth_refreshed<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<OAuthRefreshedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for oauth.refreshed.

Source

pub fn organization_created<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<OrganizationCreatedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for organization.created.

Source

pub fn organization_deleted<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<OrganizationDeletedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for organization.deleted.

Source

pub fn organization_updated<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<OrganizationUpdatedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for organization.updated.

Source

pub fn passthrough_executed<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<PassthroughExecutedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for passthrough.executed.

Source

pub fn project_created<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<ProjectCreatedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for project.created.

Source

pub fn project_deleted<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<ProjectDeletedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for project.deleted.

Source

pub fn project_updated<F, Fut, Output>(self, handler: F) -> Self
where F: Fn(Delivery<ProjectUpdatedPayload>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Output> + Send + 'static, Output: WebhookHandlerOutput + Send + 'static,

Registers a handler for project.updated.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Webhooks

§

impl !UnwindSafe for Webhooks

§

impl Forget for Webhooks

§

impl Freeze for Webhooks
where *const ArcInner<ClientRef> is !null: Freeze, PhantomData<ArcInner<ClientRef>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<SecretBox<String>> is !null: Freeze, PhantomData<ArcInner<SecretBox<String>>>: Freeze, *const ArcInner<dyn Fn(&CallResponse) + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&CallResponse) + Sync + Send>>: Freeze, *const ArcInner<dyn Fn(&Error) + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&Error) + Sync + Send>>: Freeze, *const str is !null: Freeze, PhantomData<str>: Freeze, PhantomData<(WebhookEventType, Vec<Registered>)>: Freeze, PhantomData<Registered>: Freeze,

§

impl Move for Webhooks

§

impl Send for Webhooks
where Arc<ClientRef>: Send, RawVecInner: Send, Arc<SecretBox<String>>: Send, Arc<dyn Fn(&CallResponse) + Sync + Send>: Send, Arc<dyn Fn(&Error) + Sync + Send>: Send, BoxRaw<str>: Send, RawTable<(WebhookEventType, Vec<Registered>)>: Send, BoxRaw<dyn Fn(Delivery) -> Pin<Box<dyn Future<Output = Result<(), WebhookError>> + Send>> + Sync + Send>: Send,

§

impl Sync for Webhooks
where Arc<ClientRef>: Sync, RawVecInner: Sync, Arc<SecretBox<String>>: Sync, Arc<dyn Fn(&CallResponse) + Sync + Send>: Sync, Arc<dyn Fn(&Error) + Sync + Send>: Sync, BoxRaw<str>: Sync, RawTable<(WebhookEventType, Vec<Registered>)>: Sync, BoxRaw<dyn Fn(Delivery) -> Pin<Box<dyn Future<Output = Result<(), WebhookError>> + Send>> + Sync + Send>: Sync,

§

impl Unpin for Webhooks
where Arc<ClientRef>: Unpin, *const u8 is !null: Unpin, Arc<SecretBox<String>>: Unpin, Arc<dyn Fn(&CallResponse) + Sync + Send>: Unpin, Arc<dyn Fn(&Error) + Sync + Send>: Unpin, Box<str>: Unpin, Box<dyn Fn(Delivery) -> Pin<Box<dyn Future<Output = Result<(), WebhookError>> + Send>> + Sync + Send>: Unpin,

§

impl UnsafeUnpin for Webhooks
where *const ArcInner<ClientRef> is !null: UnsafeUnpin, PhantomData<ArcInner<ClientRef>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<SecretBox<String>> is !null: UnsafeUnpin, PhantomData<ArcInner<SecretBox<String>>>: UnsafeUnpin, *const ArcInner<dyn Fn(&CallResponse) + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&CallResponse) + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(&Error) + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&Error) + Sync + Send>>: UnsafeUnpin, *const str is !null: UnsafeUnpin, PhantomData<str>: UnsafeUnpin, PhantomData<(WebhookEventType, Vec<Registered>)>: UnsafeUnpin, PhantomData<Registered>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more