webhooks

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWebhookWorkspaceLimit = 10
	MaxWebhookURLLength          = 2048
)

Variables

View Source
var (
	ErrWebhookWorkspaceRequired = errors.New("goncho: workspace_id is required")
	ErrWebhookInvalidURL        = errors.New("goncho: invalid webhook url")
	ErrWebhookLimitReached      = errors.New("goncho: maximum webhook endpoints reached for workspace")
	ErrWebhookNotFound          = errors.New("goncho: webhook endpoint not found")
	ErrWebhookSecretMissing     = errors.New("goncho: webhook secret is required")
)

Functions

func DeleteEndpoint

func DeleteEndpoint(ctx context.Context, db *sql.DB, defaultWorkspaceID, workspaceID, endpointID string) error

func SignWebhookPayload

func SignWebhookPayload(payload, secret string) (string, error)

Types

type QueueEmptyWebhookEventParams

type QueueEmptyWebhookEventParams struct {
	WorkspaceID string
	QueueType   string
	SessionID   string
	Observer    string
	Observed    string
}

type WebhookClock

type WebhookClock interface {
	Now() time.Time
}

type WebhookDeliveryAttempt

type WebhookDeliveryAttempt struct {
	EndpointID  string
	WorkspaceID string
	EventType   WebhookEventType
	Attempt     int
	Status      WebhookDeliveryStatus
	StatusCode  int
	ErrorClass  WebhookDeliveryErrorClass
	Error       string
	Retry       bool
	NextRetryAt *time.Time
	Evidence    WebhookDeliveryEvidence
	RecordedAt  time.Time
}

type WebhookDeliveryEndpoint

type WebhookDeliveryEndpoint struct {
	ID             string
	WorkspaceID    string
	URL            string
	Disabled       bool
	DisabledReason string
}

type WebhookDeliveryErrorClass

type WebhookDeliveryErrorClass string
const (
	WebhookDeliveryErrorNone       WebhookDeliveryErrorClass = ""
	WebhookDeliveryErrorHTTPStatus WebhookDeliveryErrorClass = "http_status"
	WebhookDeliveryErrorNetwork    WebhookDeliveryErrorClass = "network"
	WebhookDeliveryErrorSigning    WebhookDeliveryErrorClass = "signing"
	WebhookDeliveryErrorStore      WebhookDeliveryErrorClass = "store"
	WebhookDeliveryErrorDisabled   WebhookDeliveryErrorClass = "endpoint_disabled"
)

type WebhookDeliveryEvidence

type WebhookDeliveryEvidence struct {
	EndpointID  string
	EndpointURL string
	WorkspaceID string
	EventType   WebhookEventType
	Status      WebhookDeliveryStatus
	StatusCode  int
	ErrorClass  WebhookDeliveryErrorClass
	Attempt     int
	NextRetryAt *time.Time
}

type WebhookDeliveryRequest

type WebhookDeliveryRequest struct {
	WorkspaceID string
	Event       WebhookEvent
	Attempt     int
}

type WebhookDeliveryResult

type WebhookDeliveryResult struct {
	EndpointID  string
	WorkspaceID string
	EventType   WebhookEventType
	Attempt     int
	Status      WebhookDeliveryStatus
	StatusCode  int
	ErrorClass  WebhookDeliveryErrorClass
	Error       string
	Retry       bool
	NextRetryAt *time.Time
	Evidence    WebhookDeliveryEvidence
}

type WebhookDeliveryStatus

type WebhookDeliveryStatus string
const (
	WebhookDeliveryDelivered        WebhookDeliveryStatus = "delivered"
	WebhookDeliveryRetryable        WebhookDeliveryStatus = "retryable"
	WebhookDeliveryFailed           WebhookDeliveryStatus = "failed"
	WebhookDeliveryEndpointDisabled WebhookDeliveryStatus = "endpoint_disabled"
	WebhookDeliverySkipped          WebhookDeliveryStatus = "skipped"
)

type WebhookDeliveryStore

type WebhookDeliveryStore interface {
	ListWebhookDeliveryEndpoints(ctx context.Context, workspaceID string) ([]WebhookDeliveryEndpoint, error)
	RecordWebhookDelivery(ctx context.Context, attempt WebhookDeliveryAttempt) error
	DisableWebhookDeliveryEndpoint(ctx context.Context, endpoint WebhookDeliveryEndpoint, reason string, now time.Time) error
}

type WebhookDeliveryWorker

type WebhookDeliveryWorker struct {
	Store       WebhookDeliveryStore
	Client      WebhookHTTPClient
	Clock       WebhookClock
	Secret      string
	MaxAttempts int
	Backoff     func(attempt int) time.Duration
}

func (WebhookDeliveryWorker) Deliver

type WebhookEndpoint

type WebhookEndpoint struct {
	ID          string    `json:"id"`
	WorkspaceID string    `json:"workspace_id"`
	URL         string    `json:"url"`
	CreatedAt   time.Time `json:"created_at"`
}

func ListEndpoints

func ListEndpoints(ctx context.Context, db *sql.DB, defaultWorkspaceID, workspaceID string) ([]WebhookEndpoint, error)

type WebhookEndpointCreateParams

type WebhookEndpointCreateParams struct {
	WorkspaceID string
	URL         string
	Limit       int
	Now         time.Time
}

type WebhookEndpointCreateResult

type WebhookEndpointCreateResult struct {
	Endpoint WebhookEndpoint `json:"endpoint"`
	Created  bool            `json:"created"`
}

func GetOrCreateEndpoint

func GetOrCreateEndpoint(ctx context.Context, db *sql.DB, defaultWorkspaceID string, params WebhookEndpointCreateParams) (WebhookEndpointCreateResult, error)

type WebhookEvent

type WebhookEvent struct {
	Type        WebhookEventType `json:"type"`
	WorkspaceID string           `json:"workspace_id"`
	Data        map[string]any   `json:"data,omitempty"`
}

func NewQueueEmptyWebhookEvent

func NewQueueEmptyWebhookEvent(params QueueEmptyWebhookEventParams) (WebhookEvent, error)

func NewTestWebhookEvent

func NewTestWebhookEvent(workspaceID string) (WebhookEvent, error)

type WebhookEventType

type WebhookEventType string
const (
	WebhookEventQueueEmpty WebhookEventType = "queue.empty"
	WebhookEventTest       WebhookEventType = "test.event"
)

type WebhookHTTPClient

type WebhookHTTPClient interface {
	PostWebhook(ctx context.Context, req WebhookHTTPRequest) (WebhookHTTPResponse, error)
}

type WebhookHTTPRequest

type WebhookHTTPRequest struct {
	URL     string
	Body    string
	Headers map[string]string
}

type WebhookHTTPResponse

type WebhookHTTPResponse struct {
	StatusCode int
}

Jump to

Keyboard shortcuts

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