webhook

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webhook provides the webhook delivery system for Kigae extensions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRetrySchedule

func DefaultRetrySchedule() []time.Duration

DefaultRetrySchedule returns the standard 8-attempt retry schedule.

func GenerateSecret

func GenerateSecret() (string, error)

GenerateSecret creates a new cryptographically random webhook signing secret.

func NewOutboxDispatcher

func NewOutboxDispatcher(database *sql.DB, dialect db.QueryDialect, worker *Worker) (*outbox.Dispatcher, error)

NewOutboxDispatcher registers the webhook worker for canonical document lifecycle events. The outbox receipt is written only after every matching extension accepted the delivery or produced a permanent 4xx result.

func Sign

func Sign(secret string, body []byte, timestamp int64) string

Sign computes an HMAC-SHA256 signature for a webhook payload. Format: X-Kora-Signature: t={unix_timestamp},v1={hex_signature}

func Verify

func Verify(body []byte, header string, secrets []string, tolerance time.Duration) error

Verify checks a webhook signature against one or more secrets. Supports multi-secret verification for zero-downtime rotation. tolerance is the maximum age of the timestamp (default: 5 minutes).

Types

type Extension

type Extension struct {
	Name                string
	EndpointURL         string
	Secret              string
	TimeoutSec          int
	ConsecutiveFailures int
}

Extension represents a registered webhook extension.

type Subscription

type Subscription struct {
	Event  string             `json:"event"`
	Filter SubscriptionFilter `json:"filter,omitempty"`
}

Subscription defines an event filter for an extension.

type SubscriptionFilter

type SubscriptionFilter struct {
	DocType      string   `json:"doctype,omitempty"`
	ToState      []string `json:"to_state,omitempty"`
	FieldChanged []string `json:"field_changed,omitempty"`
}

SubscriptionFilter narrows which events are delivered.

type Worker

type Worker struct {
	DB      *sql.DB
	Dialect db.QueryDialect
	Bus     interface {
		AddListener(chan eventstream.ChangeEvent)
		RemoveListener(chan eventstream.ChangeEvent)
	}
	Site          string
	WorkAdmission interface {
		Acquire(context.Context) (func(), error)
	}

	// RetrySchedule defines the backoff for failed deliveries.
	RetrySchedule []time.Duration
	// MaxConsecutiveFailures before auto-disabling an extension.
	MaxConsecutiveFailures int
	// contains filtered or unexported fields
}

Worker delivers webhooks to extension endpoints. It subscribes to the analytics event bus and dispatches matching events.

func NewWorker

func NewWorker(database *sql.DB, bus interface {
	AddListener(chan eventstream.ChangeEvent)
	RemoveListener(chan eventstream.ChangeEvent)
}, site string, dialects ...db.QueryDialect) *Worker

NewWorker creates a webhook delivery worker.

func (*Worker) ProcessOutboxEvent

func (w *Worker) ProcessOutboxEvent(ctx context.Context, envelope contract.EventEnvelope) error

ProcessOutboxEvent delivers one durable document event. The dispatcher records its event-level receipt after success; a failed external delivery leaves the event retryable. Idempotency-Key is stable per event and extension.

func (*Worker) RetryDeadLetters

func (w *Worker) RetryDeadLetters() error

RetryDeadLetters reattempts delivery of dead-lettered webhooks. Called by the scheduler's JobWebhook handler.

func (*Worker) RetryDeadLettersContext

func (w *Worker) RetryDeadLettersContext(ctx context.Context) error

RetryDeadLettersContext schedules due retries without holding the source result set open while writes execute, and stops promptly when its owner drains.

func (*Worker) Start

func (w *Worker) Start()

Start begins listening for events and delivering webhooks.

func (*Worker) StartContext

func (w *Worker) StartContext(parent context.Context)

StartContext begins listening under a tenant-owned context. Stop cancels in-flight database and HTTP operations and waits for the worker to exit.

func (*Worker) Stop

func (w *Worker) Stop()

Stop shuts down the worker and removes its listener from the event bus.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL