A lightweight MoonBit WebHook processing framework for event driven automation.
Dependencies
pub(all) struct HookContext {
provider : HookProvider
delivery_id : String
middleware_index : Int
} derive(Eq, Debug)pub(all) struct HookDiagnostic {
provider : String
event_type : String
delivery_id : String
route_name : String
status : HookStatus
verification : VerificationStatus
retry_delay_ms : Int
notes : Array[String]
} derive(Eq, Debug)fn HookDiagnostic::HookDiagnostic(event : HookEvent, route_name : StringView, result : HookResult, verification : VerificationResult, retry_delay_ms? : Int, notes? : ArrayView[String]) -> HookDiagnosticpub(all) struct HookEvent {
provider : HookProvider
event_type : String
delivery_id : String
idempotency_key : String
body : String
attributes : Map[String, String]
} derive(Eq, Debug)fn HookMiddleware::HookMiddleware(name : StringView, callback : (HookEvent, HookContext) -> MiddlewareOutcome) -> HookMiddlewarepub struct HookPipeline {
middlewares : Array[HookMiddleware]
handler : (HookEvent, HookContext) -> HookResult
}fn HookPipeline::use_middleware(self : HookPipeline, name : StringView, callback : (HookEvent, HookContext) -> MiddlewareOutcome) -> HookPipelinepub(all) struct HookRequest {
provider : HookProvider
event_type : String
delivery_id : String
timestamp : String?
headers : Map[String, String]
body : String
} derive(Eq, Debug)fn HookRequest::HookRequest(provider : HookProvider, event_type : StringView, delivery_id : StringView, body : StringView, timestamp? : StringView, headers? : Map[String, String]) -> HookRequestpub(all) struct HookResult {
status : HookStatus
message : String
retryable : Bool
attempts : Int
} derive(Eq, Debug)fn HookResult::HookResult(status : HookStatus, message : StringView, retryable? : Bool, attempts? : Int) -> HookResultfn HookRouter::on(self : HookRouter, provider : HookProvider, event_type : StringView, name? : StringView) -> HookRouterfn HookRouter::on_event(self : HookRouter, event_type : StringView, name? : StringView) -> HookRouterfn HookRouter::on_provider(self : HookRouter, provider : HookProvider, name? : StringView) -> HookRouterpub(all) struct IdempotencyRecord {
key : String
status : HookStatus
note : String
first_seen_at : String
expires_at : String
} derive(Eq, Debug)fn IdempotencyRecord::IdempotencyRecord(key : StringView, status : HookStatus, note : StringView, first_seen_at? : StringView, expires_at? : StringView) -> IdempotencyRecordfn InMemoryDeduper::remember_event(self : InMemoryDeduper, event : HookEvent, now : StringView) -> InMemoryDeduperpub(all) struct PipelineResult {
event : HookEvent
result : HookResult
executed : Array[String]
} derive(Debug)pub(all) struct ProviderAdapter {
provider : HookProvider
event_header : String
delivery_header : String
signature_header : String?
} derive(Eq, Debug)fn ProviderAdapter::ProviderAdapter(provider : HookProvider, event_header : StringView, delivery_header : StringView, signature_header? : StringView) -> ProviderAdapterfn ProviderAdapter::parse_event(self : ProviderAdapter, headers : Map[String, String], body : StringView) -> HookEventfn ProviderAdapter::parse_request(self : ProviderAdapter, headers : Map[String, String], body : StringView) -> HookRequestfn ProviderAdapter::verify_presence(self : ProviderAdapter, request : HookRequest) -> VerificationResultpub(all) struct ProviderCapability {
provider : HookProvider
supports_signature : Bool
supports_delivery_id : Bool
supports_retry : Bool
common_events : Array[String]
} derive(Eq, Debug)fn ProviderCapability::ProviderCapability(provider : HookProvider, supports_signature? : Bool, supports_delivery_id? : Bool, supports_retry? : Bool, common_events? : ArrayView[String]) -> ProviderCapabilitypub(all) struct RetryPolicy {
max_attempts : Int
base_delay_ms : Int
max_delay_ms : Int
jitter_ms : Int
backoff : RetryBackoff
} derive(Eq, Debug)fn RetryPolicy::RetryPolicy(max_attempts? : Int, base_delay_ms? : Int, max_delay_ms? : Int, jitter_ms? : Int, backoff? : RetryBackoff) -> RetryPolicyfn SignatureVerifier::SignatureVerifier(algorithm : StringView, header_name : StringView, secret_hint : StringView) -> SignatureVerifierfn SignatureVerifier::verify_hmac_sha256(self : SignatureVerifier, request : HookRequest, secret : String) -> VerificationResultfn SignatureVerifier::verify_presence(self : SignatureVerifier, request : HookRequest) -> VerificationResultfn VerificationResult::VerificationResult(status : VerificationStatus, reason : StringView) -> VerificationResultpub struct WebhookEndpoint {
path : String
adapter : ProviderAdapter
secret : String
router : HookRouter
middlewares : Array[HookMiddleware]
deduper : InMemoryDeduper
max_body_bytes : Int
}fn WebhookEndpoint::handle_http(self : WebhookEndpoint, http : HttpRequest) -> (WebhookEndpoint, HttpResponse)fn WebhookEndpoint::handle_raw(self : WebhookEndpoint, raw : String) -> (WebhookEndpoint, HttpResponse)fn WebhookEndpoint::use_middleware(self : WebhookEndpoint, name : StringView, callback : (HookEvent, HookContext) -> MiddlewareOutcome) -> WebhookEndpointfn WebhookEndpoint::with_max_body_bytes(self : WebhookEndpoint, max_body_bytes : Int) -> WebhookEndpointfn attribute_middleware(key : String, value : String) -> ((HookEvent, HookContext) -> MiddlewareOutcome)fn constant_time_equal(left : String, right : String) -> Boolfn exponential_retry_policy(attempts? : Int, base_delay_ms? : Int, max_delay_ms? : Int) -> RetryPolicyfn hmac_sha256_hex(secret : String, message : String) -> Stringfn report_matched_delivery(event : HookEvent, route : HookRoute, verification : VerificationResult) -> HookDiagnosticfn report_unmatched_delivery(event : HookEvent, verification : VerificationResult) -> HookDiagnosticfn sha256_hex(message : String) -> Stringfn sign_github_body(secret : String, body : String) -> StringInstall
Download zipA lightweight MoonBit WebHook processing framework for event driven automation.
Dependencies