Skip to main content

Module webhook

Module webhook 

Source
Expand description

Fixture-safe Gingr webhook parsing and acknowledgement contracts.

Webhooks are parsed into a quarantined envelope first. Verification is explicit, uses a caller-provided secret, and failure maps to an acknowledgement without mutating provider state or sending customer messages.

use gingr::{response, webhook};

let raw = r#"{
  "webhook_type": "animal_edited",
  "entity_id": 812,
  "entity_type": "animal",
  "entity_data": {"name": "Miso"}
}"#;
let envelope = webhook::Envelope::from_json(raw)?;
assert_eq!(envelope.event_type_input(), Some("animal_edited"));

let missing_signature = envelope.verify(&webhook::SignatureKey::from_secret("fixture-only"));
assert!(matches!(
    missing_signature,
    Err(webhook::VerificationError::MissingField { field: "signature" })
));
assert_eq!(
    webhook::Ack::RejectedPermanently.http_status(),
    response::HttpStatus::FORBIDDEN
);

Structs§

EntityId
Normalized Gingr entity identifier preserved as text across numeric and string webhook inputs.
Envelope
Raw Gingr webhook envelope before signature verification and required-field promotion.
Payload
Provider-specific webhook payload body retained for downstream DTO mapping.
SignatureKey
Secret used to validate Gingr webhook signatures before payloads cross the provider boundary.
Verified
Webhook payload that passed signature validation and required entity/event checks.

Enums§

Ack
HTTP acknowledgement categories returned to Gingr after webhook handling.
EntityType
Gingr webhook entity classes normalized from provider strings while retaining unknown entities.
EventType
Gingr webhook event names normalized from provider strings while retaining unknown events.
ParseError
Failures while reading the raw Gingr webhook JSON envelope.
VerificationError
Reasons a Gingr webhook cannot be trusted or promoted.

Type Aliases§

ParseResult
Shared parse result type used across the webhook boundary.
VerificationResult
Shared verification result type used across the webhook boundary.