notificationsvc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDestinationNotFound        = reponotifications.ErrDestinationNotFound
	ErrDestinationSlugTaken       = reponotifications.ErrDestinationSlugTaken
	ErrDestinationDisabled        = xerror.New(xerror.KindInvalidInput, "ALERT_DESTINATION_DISABLED", "alert destination disabled")
	ErrDestinationTestUnsupported = xerror.New(
		xerror.KindUnsupported,
		"ALERT_DESTINATION_TEST_UNSUPPORTED",
		"alert destination test unsupported",
	)
	ErrAlertPolicyNotFound  = reponotifications.ErrAlertPolicyNotFound
	ErrAlertPolicySlugTaken = reponotifications.ErrAlertPolicySlugTaken
	ErrRecordNotFound       = reponotifications.ErrRecordNotFound
	ErrRecordSlugTaken      = reponotifications.ErrRecordSlugTaken
	ErrDeliveryNotFound     = reponotifications.ErrDeliveryNotFound
	ErrInvalidInput         = xerror.ValidationFailed()
)

Functions

func RunFailedCandidate

func RunFailedCandidate(org, project, environment, pipeline, run, root slug.Slug, at time.Time) model.NotificationCandidate

RunFailedCandidate is called only after the source owner rules out automatic retry.

func ValidateCandidate

func ValidateCandidate(params CreateCandidateParams) error

ValidateCandidate applies the same safe-evidence contract before queueing and persistence.

Types

type AlertDestinationTestJob

type AlertDestinationTestJob struct {
	Kind  string
	Queue string
	State string
}

type AlertDestinationTestResult

type AlertDestinationTestResult struct {
	DestinationSlug      slug.Slug
	DestinationType      model.AlertDestinationType
	RecipientCount       int
	DiagnosticsPersisted bool
	EnqueuedJobs         []AlertDestinationTestJob
}

type AlertManagementPrincipal

type AlertManagementPrincipal struct {
	UserSlug       slug.Slug
	APIKeySlug     slug.Slug
	APIKeyOrgSlug  slug.Slug
	APIKeyRoleSlug slug.Slug
}

AlertManagementPrincipal identifies the authenticated actor for user-facing alert management.

func (AlertManagementPrincipal) EventActor

func (p AlertManagementPrincipal) EventActor() model.EventActor

EventActor returns the durable-event actor represented by the alert management principal.

type CandidateProducer

type CandidateProducer interface {
	EnqueueCandidate(context.Context, postgres.DBTX, CreateCandidateParams) error
}

CandidateProducer durably hands any notification observation to the same candidate worker. It joins the source transaction; provider I/O stays downstream.

type ConnectionProvider

type ConnectionProvider interface {
	Send(context.Context, slug.Slug, slug.Slug, string) error
}

ConnectionProvider sends through a managed notification connection, without exposing its credentials.

type ContractFailureParams

type ContractFailureParams struct {
	OrgSlug, ProjectSlug, EnvironmentSlug, PipelineSlug  slug.Slug
	RunSlug, ValidationSlug                              slug.Slug
	StepSlug                                             slug.Slug
	CheckID, ContractName, ContractRevision, Field, Rule string
	ReasonCode                                           string
	ObservedAt                                           time.Time
}

ContractFailureParams identifies a durable enforced failure. Producers pass declaration identities and fixed diagnostic codes, never evaluated values.

type CreateAlertDestinationParams

type CreateAlertDestinationParams struct {
	OrgSlug         slug.Slug `validate:"required"`
	Slug            slug.Slug
	Name            string                     `validate:"required"`
	Type            model.AlertDestinationType `validate:"alertdestinationtype"`
	NonSecretConfig map[string]any
}

type CreateAlertPolicyParams

type CreateAlertPolicyParams struct {
	OrgSlug         slug.Slug `validate:"required"`
	Slug            slug.Slug
	Name            string                 `validate:"required"`
	Scope           model.AlertPolicyScope `validate:"alertpolicyscope"`
	ProjectSlug     *slug.Slug
	EnvironmentSlug *slug.Slug
	// NotificationType and Severity are optional individually; policy validation requires at least one.
	NotificationType *model.NotificationType           `validate:"omitempty,notificationtype"`
	Severity         *model.NotificationSeverity       `validate:"omitempty,notificationseverity"`
	LifecycleState   *model.NotificationLifecycleState `validate:"omitempty,notificationlifecyclestate"`
	SourceKind       *model.EventEntityType            `validate:"omitempty,evententitytype"`
	SourceAction     *model.EventAction                `validate:"omitempty,eventaction"`
	SourceRef        *slug.Slug
	DestinationSlugs []slug.Slug
}

type CreateCandidateParams

type CreateCandidateParams = model.NotificationCandidate

type CreateCandidateResult

type CreateCandidateResult struct {
	Record *model.NotificationRecord
}

type DeliverNotificationParams

type DeliverNotificationParams struct {
	Test            bool
	OrgSlug         slug.Slug `validate:"required"`
	RecordSlug      slug.Slug `validate:"required"`
	DestinationSlug slug.Slug `validate:"required"`
	AlertPolicySlug slug.Slug `validate:"required"`
}

type DeliveryError

type DeliveryError struct {
	Category   string
	Message    string
	Retryable  bool
	RetryAfter time.Duration
}

DeliveryError contains only safe diagnostics and the provider's retry instruction.

func (*DeliveryError) Error

func (e *DeliveryError) Error() string

type LifecycleEventProducer

type LifecycleEventProducer interface {
	EnqueueRecord(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug slug.Slug,
		actor model.EventActor,
		event eventrecorder.Event,
	)
	EnqueueRequired(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug slug.Slug,
		actor model.EventActor,
		event eventrecorder.Event,
	) error
}

LifecycleEventProducer avoids an import cycle with service/worker/producer: notificationsvc needs only this enqueue capability, while worker producer already imports notificationsvc for notification delivery jobs. Broader package refactoring would be disproportionate for this narrow lifecycle-audit path.

type LifecycleEventProducerFunc

type LifecycleEventProducerFunc func(
	ctx context.Context,
	tx postgres.DBTX,
	orgSlug slug.Slug,
	actor model.EventActor,
	event eventrecorder.Event,
)

LifecycleEventProducerFunc adapts a function to LifecycleEventProducer.

func (LifecycleEventProducerFunc) EnqueueRecord

func (f LifecycleEventProducerFunc) EnqueueRecord(
	ctx context.Context,
	tx postgres.DBTX,
	orgSlug slug.Slug,
	actor model.EventActor,
	event eventrecorder.Event,
)

EnqueueRecord calls the wrapped producer function.

func (LifecycleEventProducerFunc) EnqueueRequired

func (f LifecycleEventProducerFunc) EnqueueRequired(
	ctx context.Context,
	tx postgres.DBTX,
	orgSlug slug.Slug,
	actor model.EventActor,
	event eventrecorder.Event,
) error

EnqueueRequired preserves the legacy function adapter for call sites that intentionally cannot fail. Production adapters must provide their own fail-closed implementation.

type ListNotificationsFilters

type ListNotificationsFilters struct {
	LifecycleState   *model.NotificationLifecycleState
	NotificationType *model.NotificationType
	Severity         *model.NotificationSeverity
	SourceKind       *model.EventEntityType
	SourceAction     *model.EventAction
	SourceRef        *slug.Slug
	IncludeResolved  bool
}

type MarkAlertDeliveryAttemptFailedParams

type MarkAlertDeliveryAttemptFailedParams struct {
	OrgSlug                  slug.Slug `validate:"required"`
	AttemptSlug              slug.Slug `validate:"required"`
	ProviderAttempt          int       `validate:"required,min=1"`
	ProviderResponseMetadata map[string]any
	ErrorCategory            string
	ErrorMessage             string
}

type MarkAlertDeliveryAttemptSentParams

type MarkAlertDeliveryAttemptSentParams struct {
	OrgSlug                  slug.Slug `validate:"required"`
	AttemptSlug              slug.Slug `validate:"required"`
	ProviderAttempt          int       `validate:"required,min=1"`
	ProviderResponseMetadata map[string]any
}

type NotificationDeliveryJobParams

type NotificationDeliveryJobParams struct {
	Test            bool
	OrgSlug         slug.Slug `validate:"required"`
	RecordSlug      slug.Slug `validate:"required"`
	DestinationSlug slug.Slug `validate:"required"`
	AlertPolicySlug slug.Slug `validate:"required"`
}

type NotificationDeliveryProducer

type NotificationDeliveryProducer interface {
	EnqueueNotificationDelivery(
		ctx context.Context,
		tx postgres.DBTX,
		params NotificationDeliveryJobParams,
	) (queue.QueuedJob, error)
}

type NotificationEmailProducer

type NotificationEmailProducer interface {
	EnqueueNotification(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug slug.Slug,
		recipient model.NotificationEmailRecipient,
		notification model.NotificationEmail,
		alertDeliveryAttemptSlug slug.Slug,
	) (queue.QueuedJob, error)
}

type Service

type Service interface {
	CreateAlertDestination(
		ctx context.Context,
		principal AlertManagementPrincipal,
		params CreateAlertDestinationParams,
	) (*model.AlertDestination, error)
	ListAlertDestinations(
		ctx context.Context,
		principal AlertManagementPrincipal,
		orgSlug slug.Slug,
		req model.ListRequest,
	) (model.ListResponse[*model.AlertDestination], error)
	GetAlertDestination(
		ctx context.Context,
		principal AlertManagementPrincipal,
		orgSlug slug.Slug,
		destinationSlug slug.Slug,
	) (*model.AlertDestination, error)
	TestAlertDestination(
		ctx context.Context,
		principal AlertManagementPrincipal,
		params TestAlertDestinationParams,
	) (*AlertDestinationTestResult, error)
	UpdateAlertDestination(
		ctx context.Context,
		principal AlertManagementPrincipal,
		params UpdateAlertDestinationParams,
	) (*model.AlertDestination, error)
	DeleteAlertDestination(
		ctx context.Context,
		principal AlertManagementPrincipal,
		orgSlug slug.Slug,
		destinationSlug slug.Slug,
	) error
	CreateAlertPolicy(ctx context.Context, principal AlertManagementPrincipal, params CreateAlertPolicyParams) (*model.AlertPolicy, error)
	ListAlertPolicies(
		ctx context.Context,
		principal AlertManagementPrincipal,
		orgSlug slug.Slug,
		req model.ListRequest,
	) (model.ListResponse[*model.AlertPolicy], error)
	GetAlertPolicy(ctx context.Context, principal AlertManagementPrincipal, orgSlug, policySlug slug.Slug) (*model.AlertPolicy, error)
	UpdateAlertPolicy(ctx context.Context, principal AlertManagementPrincipal, params UpdateAlertPolicyParams) (*model.AlertPolicy, error)
	DeleteAlertPolicy(ctx context.Context, principal AlertManagementPrincipal, orgSlug, policySlug slug.Slug) error
	CreateCandidate(ctx context.Context, params CreateCandidateParams) (*CreateCandidateResult, error)
	UpsertRecord(ctx context.Context, params UpsertRecordParams) (*model.NotificationRecord, error)
	ListNotifications(
		ctx context.Context,
		orgSlug slug.Slug,
		filters ListNotificationsFilters,
		req model.ListRequest,
	) (model.ListResponse[*model.NotificationListItem], error)
	GetNotification(
		ctx context.Context,
		orgSlug slug.Slug,
		recordSlug slug.Slug,
	) (*model.NotificationListItem, error)
	AcknowledgeNotification(
		ctx context.Context,
		principal AlertManagementPrincipal,
		orgSlug slug.Slug,
		recordSlug slug.Slug,
	) (*model.NotificationListItem, error)
	ResolveNotification(
		ctx context.Context,
		principal AlertManagementPrincipal,
		orgSlug slug.Slug,
		recordSlug slug.Slug,
	) (*model.NotificationListItem, error)
	ListAlertDeliveryAttempts(
		ctx context.Context,
		orgSlug slug.Slug,
		recordSlug slug.Slug,
		req model.ListRequest,
	) (model.ListResponse[*model.AlertDeliveryAttempt], error)
	ListRecentAlertDeliveryAttemptsForRecords(
		ctx context.Context,
		orgSlug slug.Slug,
		recordSlugs []slug.Slug,
		limitPerRecord int,
	) ([]*model.AlertDeliveryAttempt, error)
	DeliverNotification(ctx context.Context, params DeliverNotificationParams) error
	MarkAlertDeliveryAttemptSent(ctx context.Context, params MarkAlertDeliveryAttemptSentParams) error
	MarkAlertDeliveryAttemptFailed(ctx context.Context, params MarkAlertDeliveryAttemptFailedParams) error
}

func New

func New(
	txm postgres.TransactionManager,
	repo reponotifications.Repository,
	clk clock.Clock,
	deliveryProducer NotificationDeliveryProducer,
	emailProducer NotificationEmailProducer,
	eventProducer LifecycleEventProducer,
	connectionProviders ConnectionProviders,
	frontendURL string,
) Service

New creates a notification service with repository-backed persistence.

type TestAlertDestinationParams

type TestAlertDestinationParams struct {
	OrgSlug         slug.Slug `validate:"required"`
	DestinationSlug slug.Slug `validate:"required"`
}

type UpdateAlertDestinationParams

type UpdateAlertDestinationParams struct {
	OrgSlug         slug.Slug                  `validate:"required"`
	Slug            slug.Slug                  `validate:"required"`
	Name            string                     `validate:"required"`
	Type            model.AlertDestinationType `validate:"alertdestinationtype"`
	NonSecretConfig map[string]any
	Enabled         bool
}

type UpdateAlertPolicyParams

type UpdateAlertPolicyParams struct {
	OrgSlug         slug.Slug              `validate:"required"`
	Slug            slug.Slug              `validate:"required"`
	Name            string                 `validate:"required"`
	Scope           model.AlertPolicyScope `validate:"alertpolicyscope"`
	ProjectSlug     *slug.Slug
	EnvironmentSlug *slug.Slug
	// NotificationType and Severity are optional individually; policy validation requires at least one.
	NotificationType *model.NotificationType           `validate:"omitempty,notificationtype"`
	Severity         *model.NotificationSeverity       `validate:"omitempty,notificationseverity"`
	LifecycleState   *model.NotificationLifecycleState `validate:"omitempty,notificationlifecyclestate"`
	SourceKind       *model.EventEntityType            `validate:"omitempty,evententitytype"`
	SourceAction     *model.EventAction                `validate:"omitempty,eventaction"`
	SourceRef        *slug.Slug
	DestinationSlugs []slug.Slug
	Enabled          bool
}

type UpsertRecordParams

type UpsertRecordParams struct {
	OrgSlug           slug.Slug `validate:"required"`
	Slug              slug.Slug `validate:"required"`
	ProjectSlug       *slug.Slug
	EnvironmentSlug   *slug.Slug
	NotificationType  model.NotificationType     `validate:"notificationtype"`
	Severity          model.NotificationSeverity `validate:"notificationseverity"`
	DedupeFingerprint string                     `validate:"required"`
	SourceEventSlug   *slug.Slug
	SourceEntityType  model.EventEntityType `validate:"evententitytype"`
	SourceAction      model.EventAction     `validate:"eventaction"`
	SourceRefs        map[string]string
	SafeMetadata      map[string]any
}

Directories

Path Synopsis
provider

Jump to

Keyboard shortcuts

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