webhooks

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeRequired      = "REQUIRED"
	ErrorCodeInvalidFormat = "INVALID_FORMAT"
	ErrorCodeTooLong       = "TOO_LONG"
	ErrorCodeTooShort      = "TOO_SHORT"
	ErrorCodeInvalid       = "INVALID"
	ErrorCodeNotFound      = "NOT_FOUND"
	ErrorCodeDuplicate     = "DUPLICATE"
	ErrorCodeForbidden     = "FORBIDDEN"
)

Validation error codes

View Source
const (
	MsgRequired           = "field is required"
	MsgInvalidNamespace   = "namespace must be a valid identifier (alphanumeric, hyphens, underscores)"
	MsgInvalidURL         = "must be a valid HTTP or HTTPS URL"
	MsgInvalidTimeout     = "timeout must be between 1 and 300 seconds"
	MsgInvalidEvent       = "event name must be a valid identifier"
	MsgTooManyEvents      = "maximum 50 events allowed per webhook"
	MsgHeadersTooLarge    = "headers total size must not exceed 8KB"
	MsgPayloadTooLarge    = "payload size must not exceed 1MB"
	MsgInvalidJSON        = "must be valid JSON"
	MsgNamespaceTooLong   = "namespace must not exceed 64 characters"
	MsgDescriptionTooLong = "description must not exceed 500 characters"
)

Common validation messages

Variables

This section is empty.

Functions

func ValidateJSONSchema

func ValidateJSONSchema(schema map[string]any, payload map[string]any) error

ValidateJSONSchema validates a payload against a JSON schema string

Types

type HealthSummaryData

type HealthSummaryData struct {
	HealthyCount   int `json:"healthy_count"`
	DegradedCount  int `json:"degraded_count"`
	UnhealthyCount int `json:"unhealthy_count"`
	UnknownCount   int `json:"unknown_count"`
	TotalCount     int `json:"total_count"`
}

HealthSummaryData represents health summary information

type NamespaceStatsData

type NamespaceStatsData struct {
	TotalWebhooks        int     `json:"total_webhooks"`
	ActiveWebhooks       int     `json:"active_webhooks"`
	TotalDeliveries      int     `json:"total_deliveries"`
	SuccessfulDeliveries int     `json:"successful_deliveries"`
	FailedDeliveries     int     `json:"failed_deliveries"`
	PendingDeliveries    int     `json:"pending_deliveries"`
	SuccessRate          float64 `json:"success_rate"`
}

NamespaceStatsData represents namespace statistics

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
	Code    string `json:"code"`
}

ValidationError represents a validation error with structured details

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface

type ValidationErrors

type ValidationErrors struct {
	Errors []ValidationError `json:"errors"`
}

ValidationErrors represents multiple validation errors

func (*ValidationErrors) Add

func (e *ValidationErrors) Add(field, message, code string)

Add adds a validation error

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

Error implements the error interface

func (ValidationErrors) HasErrors

func (e ValidationErrors) HasErrors() bool

HasErrors returns true if there are validation errors

type WebhookHealthData

type WebhookHealthData struct {
	WebhookID            string              `json:"webhook_id"`
	Health               store.WebhookHealth `json:"health"`
	TotalDeliveries      int                 `json:"total_deliveries"`
	SuccessfulDeliveries int                 `json:"successful_deliveries"`
	FailedDeliveries     int                 `json:"failed_deliveries"`
	ConsecutiveFailures  int                 `json:"consecutive_failures"`
	LastSuccessAt        *time.Time          `json:"last_success_at"`
	LastFailureAt        *time.Time          `json:"last_failure_at"`
	SuccessRate          float64             `json:"success_rate"`
	AvgResponseTime      int                 `json:"avg_response_time"` // milliseconds
	CreatedAt            time.Time           `json:"created_at"`
	UpdatedAt            time.Time           `json:"updated_at"`
}

WebhookHealthData represents webhook health information

type WebhookService

type WebhookService struct {
	// contains filtered or unexported fields
}

func NewWebhookService

func NewWebhookService(queueManager queue.JobInserter, webhookRepo store.RepositoryInterface) *WebhookService

NewWebhookService creates a new WebhookService instance

func (*WebhookService) DeleteEvent

func (s *WebhookService) DeleteEvent(ctx context.Context, name string) error

DeleteEvent deletes an event registration

func (*WebhookService) GetHealthSummary

func (s *WebhookService) GetHealthSummary(ctx context.Context) (*HealthSummaryData, error)

GetHealthSummary retrieves a summary of webhook health across all namespaces

func (*WebhookService) GetNamespaceStats

func (s *WebhookService) GetNamespaceStats(ctx context.Context, namespace string) (*NamespaceStatsData, error)

GetNamespaceStats retrieves statistics for a namespace

func (*WebhookService) GetRegisteredWebhooks

func (s *WebhookService) GetRegisteredWebhooks(ctx context.Context, namespace string, webhookID string, activeOnly bool) ([]*store.WebhookRegistration, error)

GetRegisteredWebhooks gets registered webhooks by namespace and optional webhook ID

func (*WebhookService) GetWebhookDeliveryHistory

func (s *WebhookService) GetWebhookDeliveryHistory(ctx context.Context, webhookID string, namespace string, limit int32, offset int32) ([]*store.WebhookDelivery, int32, error)

GetWebhookDeliveryHistory gets delivery history for a webhook

func (*WebhookService) GetWebhookDeliveryStatus

func (s *WebhookService) GetWebhookDeliveryStatus(ctx context.Context, deliveryID string, namespace string) (*store.WebhookDelivery, error)

GetWebhookDeliveryStatus gets the status of a webhook delivery

func (*WebhookService) GetWebhookHealth

func (s *WebhookService) GetWebhookHealth(ctx context.Context, webhookID string, namespace string) (*WebhookHealthData, error)

GetWebhookHealth retrieves health metrics for a webhook

func (*WebhookService) GetWebhookStatus

func (s *WebhookService) GetWebhookStatus(ctx context.Context, webhookID string, eventID string) ([]*store.WebhookDelivery, int32, error)

GetWebhookStatus gets the status of webhook deliveries

func (*WebhookService) ListEventReports

func (s *WebhookService) ListEventReports(ctx context.Context, namespace string, eventName *string, limit, offset int32) ([]*store.EventReportWithStats, int32, error)

ListEventReports lists event records with delivery statistics in descending order by creation time

func (*WebhookService) ListEvents

func (s *WebhookService) ListEvents(ctx context.Context, activeOnly bool) ([]*store.EventRegistration, error)

ListEvents lists all registered events

func (*WebhookService) ListRegisteredWebhooksByEvent

func (s *WebhookService) ListRegisteredWebhooksByEvent(ctx context.Context, namespace string, event string, activeOnly bool) ([]*store.WebhookRegistration, error)

ListRegisteredWebhooksByEvent lists webhooks registered for a specific event

func (*WebhookService) ListWebhooks

func (s *WebhookService) ListWebhooks(ctx context.Context, namespace string, event string, activeOnly bool) ([]*store.WebhookRegistration, error)

ListWebhooks lists all registered webhooks for a namespace

func (*WebhookService) ListWebhooksByHealth

func (s *WebhookService) ListWebhooksByHealth(ctx context.Context, health store.WebhookHealth) ([]*store.WebhookRegistration, error)

ListWebhooksByHealth retrieves webhooks filtered by health status

func (*WebhookService) PauseWebhook

func (s *WebhookService) PauseWebhook(ctx context.Context, webhookID string, namespace string, reason string) error

PauseWebhook temporarily disables webhook deliveries

func (*WebhookService) PushEvent

func (s *WebhookService) PushEvent(ctx context.Context, namespace string, event string, payload map[string]any, ttlSeconds int64, metadata map[string]string) (string, error)

PushEvent pushes an event to a webhook service, given the namespace and event name. It returns the event ID if successful, otherwise an error. The payload is optional and should match the event schema if present. The TTL is optional and defaults to 1 day if not provided. The metadata is optional and is used to store additional information about the event.

func (*WebhookService) RegisterEvent

func (s *WebhookService) RegisterEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) (string, int64, error)

RegisterEvent registers a new event type

func (*WebhookService) RegisterWebhook

func (s *WebhookService) RegisterWebhook(ctx context.Context, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string) (string, int64, error)

func (*WebhookService) ResendWebhook

func (s *WebhookService) ResendWebhook(ctx context.Context, deliveryID string, namespace string, forceResend bool) (string, error)

ResendWebhook resends a failed webhook delivery

func (*WebhookService) ResubmitWebhook

func (s *WebhookService) ResubmitWebhook(ctx context.Context, deliveryID string, webhookID string, namespace string, force bool) ([]string, int32, error)

ResubmitWebhook manually retries failed or pending webhook deliveries

func (*WebhookService) ResumeWebhook

func (s *WebhookService) ResumeWebhook(ctx context.Context, webhookID string, namespace string) error

ResumeWebhook re-enables webhook deliveries

func (*WebhookService) UnregisterWebhook

func (s *WebhookService) UnregisterWebhook(ctx context.Context, webhookID string) error

UnregisterWebhook removes a webhook registration

func (*WebhookService) UpdateEvent

func (s *WebhookService) UpdateEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) error

UpdateEvent updates an event registration

func (*WebhookService) UpdateWebhookConfig

func (s *WebhookService) UpdateWebhookConfig(ctx context.Context, webhookID string, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string) error

UpdateWebhookConfig updates webhook configuration

type WebhookServiceInterface

type WebhookServiceInterface interface {
	RegisterWebhook(ctx context.Context, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string) (string, int64, error)
	UnregisterWebhook(ctx context.Context, webhookID string) error
	PushEvent(ctx context.Context, namespace string, event string, payload map[string]any, ttlSeconds int64, metadata map[string]string) (string, error)
	GetWebhookStatus(ctx context.Context, namespace string, webhookID string) ([]*store.WebhookDelivery, int32, error)
	ListWebhooks(ctx context.Context, namespace string, event string, activeOnly bool) ([]*store.WebhookRegistration, error)
	GetRegisteredWebhooks(ctx context.Context, namespace string, webhookID string, activeOnly bool) ([]*store.WebhookRegistration, error)
	ListRegisteredWebhooksByEvent(ctx context.Context, namespace string, event string, activeOnly bool) ([]*store.WebhookRegistration, error)
	GetWebhookDeliveryStatus(ctx context.Context, deliveryID string, namespace string) (*store.WebhookDelivery, error)
	ResendWebhook(ctx context.Context, deliveryID string, namespace string, forceResend bool) (string, error)
	PauseWebhook(ctx context.Context, webhookID string, namespace string, reason string) error
	ResumeWebhook(ctx context.Context, webhookID string, namespace string) error
	GetWebhookDeliveryHistory(ctx context.Context, webhookID string, namespace string, limit int32, offset int32) ([]*store.WebhookDelivery, int32, error)
	RegisterEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) (string, int64, error)
	GetNamespaceStats(ctx context.Context, namespace string) (*NamespaceStatsData, error)
	UpdateWebhookConfig(ctx context.Context, webhookID string, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string) error
	UpdateEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) error
	DeleteEvent(ctx context.Context, name string) error
	GetWebhookHealth(ctx context.Context, webhookID string, namespace string) (*WebhookHealthData, error)
	GetHealthSummary(ctx context.Context) (*HealthSummaryData, error)
	ListEvents(ctx context.Context, activeOnly bool) ([]*store.EventRegistration, error)
	ListWebhooksByHealth(ctx context.Context, health store.WebhookHealth) ([]*store.WebhookRegistration, error)
	ResubmitWebhook(ctx context.Context, deliveryID string, webhookID string, namespace string, force bool) ([]string, int32, error)
	ListEventReports(ctx context.Context, namespace string, eventName *string, limit, offset int32) ([]*store.EventReportWithStats, int32, error)
}

type WebhookServiceInterfaceWithTracing

type WebhookServiceInterfaceWithTracing struct {
	WebhookServiceInterface
	// contains filtered or unexported fields
}

WebhookServiceInterfaceWithTracing implements WebhookServiceInterface interface instrumented with open telemetry spans

func NewWebhookServiceInterfaceWithTracing

func NewWebhookServiceInterfaceWithTracing(base WebhookServiceInterface, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) WebhookServiceInterfaceWithTracing

NewWebhookServiceInterfaceWithTracing returns WebhookServiceInterfaceWithTracing

func (WebhookServiceInterfaceWithTracing) DeleteEvent

func (_d WebhookServiceInterfaceWithTracing) DeleteEvent(ctx context.Context, name string) (err error)

DeleteEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetHealthSummary

func (_d WebhookServiceInterfaceWithTracing) GetHealthSummary(ctx context.Context) (hp1 *HealthSummaryData, err error)

GetHealthSummary implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetNamespaceStats

func (_d WebhookServiceInterfaceWithTracing) GetNamespaceStats(ctx context.Context, namespace string) (np1 *NamespaceStatsData, err error)

GetNamespaceStats implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetRegisteredWebhooks

func (_d WebhookServiceInterfaceWithTracing) GetRegisteredWebhooks(ctx context.Context, namespace string, webhookID string, activeOnly bool) (wpa1 []*store.WebhookRegistration, err error)

GetRegisteredWebhooks implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetWebhookDeliveryHistory

func (_d WebhookServiceInterfaceWithTracing) GetWebhookDeliveryHistory(ctx context.Context, webhookID string, namespace string, limit int32, offset int32) (wpa1 []*store.WebhookDelivery, i1 int32, err error)

GetWebhookDeliveryHistory implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetWebhookDeliveryStatus

func (_d WebhookServiceInterfaceWithTracing) GetWebhookDeliveryStatus(ctx context.Context, deliveryID string, namespace string) (wp1 *store.WebhookDelivery, err error)

GetWebhookDeliveryStatus implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetWebhookHealth

func (_d WebhookServiceInterfaceWithTracing) GetWebhookHealth(ctx context.Context, webhookID string, namespace string) (wp1 *WebhookHealthData, err error)

GetWebhookHealth implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) GetWebhookStatus

func (_d WebhookServiceInterfaceWithTracing) GetWebhookStatus(ctx context.Context, namespace string, webhookID string) (wpa1 []*store.WebhookDelivery, i1 int32, err error)

GetWebhookStatus implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListEventReports

func (_d WebhookServiceInterfaceWithTracing) ListEventReports(ctx context.Context, namespace string, eventName *string, limit int32, offset int32) (epa1 []*store.EventReportWithStats, i1 int32, err error)

ListEventReports implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListEvents

func (_d WebhookServiceInterfaceWithTracing) ListEvents(ctx context.Context, activeOnly bool) (epa1 []*store.EventRegistration, err error)

ListEvents implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListRegisteredWebhooksByEvent

func (_d WebhookServiceInterfaceWithTracing) ListRegisteredWebhooksByEvent(ctx context.Context, namespace string, event string, activeOnly bool) (wpa1 []*store.WebhookRegistration, err error)

ListRegisteredWebhooksByEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListWebhooks

func (_d WebhookServiceInterfaceWithTracing) ListWebhooks(ctx context.Context, namespace string, event string, activeOnly bool) (wpa1 []*store.WebhookRegistration, err error)

ListWebhooks implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ListWebhooksByHealth

func (_d WebhookServiceInterfaceWithTracing) ListWebhooksByHealth(ctx context.Context, health store.WebhookHealth) (wpa1 []*store.WebhookRegistration, err error)

ListWebhooksByHealth implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) PauseWebhook

func (_d WebhookServiceInterfaceWithTracing) PauseWebhook(ctx context.Context, webhookID string, namespace string, reason string) (err error)

PauseWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) PushEvent

func (_d WebhookServiceInterfaceWithTracing) PushEvent(ctx context.Context, namespace string, event string, payload map[string]any, ttlSeconds int64, metadata map[string]string) (s1 string, err error)

PushEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) RegisterEvent

func (_d WebhookServiceInterfaceWithTracing) RegisterEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) (s1 string, i1 int64, err error)

RegisterEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) RegisterWebhook

func (_d WebhookServiceInterfaceWithTracing) RegisterWebhook(ctx context.Context, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string) (s1 string, i1 int64, err error)

RegisterWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ResendWebhook

func (_d WebhookServiceInterfaceWithTracing) ResendWebhook(ctx context.Context, deliveryID string, namespace string, forceResend bool) (s1 string, err error)

ResendWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ResubmitWebhook

func (_d WebhookServiceInterfaceWithTracing) ResubmitWebhook(ctx context.Context, deliveryID string, webhookID string, namespace string, force bool) (sa1 []string, i1 int32, err error)

ResubmitWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) ResumeWebhook

func (_d WebhookServiceInterfaceWithTracing) ResumeWebhook(ctx context.Context, webhookID string, namespace string) (err error)

ResumeWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) UnregisterWebhook

func (_d WebhookServiceInterfaceWithTracing) UnregisterWebhook(ctx context.Context, webhookID string) (err error)

UnregisterWebhook implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) UpdateEvent

func (_d WebhookServiceInterfaceWithTracing) UpdateEvent(ctx context.Context, name string, description string, schema map[string]any, metadata map[string]string, active bool) (err error)

UpdateEvent implements WebhookServiceInterface

func (WebhookServiceInterfaceWithTracing) UpdateWebhookConfig

func (_d WebhookServiceInterfaceWithTracing) UpdateWebhookConfig(ctx context.Context, webhookID string, namespace string, events []string, url string, headers map[string]string, timeout int, active bool, description string) (err error)

UpdateWebhookConfig implements WebhookServiceInterface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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