notification

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: GPL-3.0 Imports: 6 Imported by: ? 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

Index

Constants

View Source
const (
	AudienceAll   = "all"
	AudienceGroup = "group"
	AudienceUser  = "user"
)

Audience constants

View Source
const (
	SeverityCritical = "critical"
	SeverityHigh     = "high"
	SeverityMedium   = "medium"
	SeverityLow      = "low"
	SeverityInfo     = "info"
)

Severity constants

View Source
const (
	TypeFindingNew          = "finding_new"
	TypeFindingAssigned     = "finding_assigned"
	TypeFindingStatusChange = "finding_status_change"
	TypeFindingComment      = "finding_comment"
	TypeFindingMention      = "finding_mention"
	TypeScanStarted         = "scan_started"
	TypeScanCompleted       = "scan_completed"
	TypeScanFailed          = "scan_failed"
	TypeAssetDiscovered     = "asset_discovered"
	TypeMemberInvited       = "member_invited"
	TypeMemberJoined        = "member_joined"
	TypeRoleChanged         = "role_changed"
	TypeSLABreach           = "sla_breach"
	TypeSystemAlert         = "system_alert"
)

Notification types

Variables

View Source
var (
	ErrNotificationNotFound = fmt.Errorf("%w: notification not found", shared.ErrNotFound)
)

Functions

func IsValidSeverity added in v0.1.2

func IsValidSeverity(s string) bool

IsValidSeverity checks if a string is a valid severity value.

func IsValidType added in v0.1.2

func IsValidType(t string) bool

IsValidType checks if a string is a valid notification type.

Types

type ID

type ID = shared.ID

ID is the unique identifier for a notification.

func ParseID

func ParseID(s string) (ID, error)

ParseID parses a string into a notification ID.

type ListFilter added in v0.1.2

type ListFilter struct {
	Severity string
	Type     string
	IsRead   *bool
}

ListFilter contains filter parameters for listing notifications.

type Notification added in v0.1.2

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

Notification represents an in-app notification.

func NewNotification added in v0.1.2

func NewNotification(params NotificationParams) *Notification

NewNotification creates a new notification.

func Reconstitute

func Reconstitute(
	id ID,
	tenantID shared.ID,
	audience string,
	audienceID *shared.ID,
	notificationType string,
	title string,
	body string,
	severity string,
	resourceType string,
	resourceID *shared.ID,
	url string,
	actorID *shared.ID,
	createdAt time.Time,
	isRead bool,
) *Notification

Reconstitute recreates a notification from persistence.

func (*Notification) ActorID added in v0.1.2

func (n *Notification) ActorID() *shared.ID

func (*Notification) Audience added in v0.1.2

func (n *Notification) Audience() string

func (*Notification) AudienceID added in v0.1.2

func (n *Notification) AudienceID() *shared.ID

func (*Notification) Body added in v0.1.2

func (n *Notification) Body() string

func (*Notification) CreatedAt added in v0.1.2

func (n *Notification) CreatedAt() time.Time

func (*Notification) ID added in v0.1.2

func (n *Notification) ID() ID

Getters

func (*Notification) IsRead added in v0.1.2

func (n *Notification) IsRead() bool

func (*Notification) NotificationType added in v0.1.2

func (n *Notification) NotificationType() string

func (*Notification) ResourceID added in v0.1.2

func (n *Notification) ResourceID() *shared.ID

func (*Notification) ResourceType added in v0.1.2

func (n *Notification) ResourceType() string

func (*Notification) Severity added in v0.1.2

func (n *Notification) Severity() string

func (*Notification) TenantID added in v0.1.2

func (n *Notification) TenantID() shared.ID

func (*Notification) Title added in v0.1.2

func (n *Notification) Title() string

func (*Notification) URL added in v0.1.2

func (n *Notification) URL() string

type NotificationParams added in v0.1.2

type NotificationParams struct {
	TenantID         shared.ID
	Audience         string
	AudienceID       *shared.ID
	NotificationType string
	Title            string
	Body             string
	Severity         string
	ResourceType     string
	ResourceID       *shared.ID
	URL              string
	ActorID          *shared.ID
}

NotificationParams contains parameters for creating a new notification.

type Preferences added in v0.1.2

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

Preferences represents user notification preferences.

func DefaultPreferences added in v0.1.2

func DefaultPreferences(tenantID, userID shared.ID) *Preferences

DefaultPreferences returns default preferences.

func ReconstitutePref added in v0.1.2

func ReconstitutePref(
	tenantID shared.ID,
	userID shared.ID,
	inAppEnabled bool,
	emailDigest string,
	mutedTypes []string,
	minSeverity string,
	updatedAt time.Time,
) *Preferences

ReconstitutePref recreates preferences from persistence.

func (*Preferences) EmailDigest added in v0.1.2

func (p *Preferences) EmailDigest() string

func (*Preferences) InAppEnabled added in v0.1.2

func (p *Preferences) InAppEnabled() bool

func (*Preferences) IsSeverityAllowed added in v0.1.2

func (p *Preferences) IsSeverityAllowed(severity string) bool

IsSeverityAllowed checks if a severity meets the minimum threshold.

func (*Preferences) IsTypeMuted added in v0.1.2

func (p *Preferences) IsTypeMuted(notifType string) bool

IsTypeMuted checks if a notification type is muted.

func (*Preferences) MinSeverity added in v0.1.2

func (p *Preferences) MinSeverity() string

func (*Preferences) MutedTypes added in v0.1.2

func (p *Preferences) MutedTypes() []string

func (*Preferences) TenantID added in v0.1.2

func (p *Preferences) TenantID() shared.ID

Getters

func (*Preferences) UpdatedAt added in v0.1.2

func (p *Preferences) UpdatedAt() time.Time

func (*Preferences) UserID added in v0.1.2

func (p *Preferences) UserID() shared.ID

type PreferencesParams added in v0.1.2

type PreferencesParams struct {
	InAppEnabled bool
	EmailDigest  string
	MutedTypes   []string
	MinSeverity  string
}

PreferencesParams contains parameters for creating/updating preferences.

type Repository added in v0.1.2

type Repository interface {
	// Create inserts a new notification.
	Create(ctx context.Context, n *Notification) error

	// List returns notifications visible to a user (with audience filtering and read status).
	// Group membership is resolved via subquery internally, eliminating an extra DB roundtrip.
	List(ctx context.Context, tenantID, userID shared.ID, filter ListFilter, page pagination.Pagination) (pagination.Result[*Notification], error)

	// UnreadCount returns the number of unread notifications for a user.
	// Group membership is resolved via subquery internally, eliminating an extra DB roundtrip.
	UnreadCount(ctx context.Context, tenantID, userID shared.ID) (int, error)

	// MarkAsRead marks a single notification as read for a user.
	MarkAsRead(ctx context.Context, tenantID shared.ID, notificationID ID, userID shared.ID) error

	// MarkAllAsRead updates the watermark timestamp for a user.
	MarkAllAsRead(ctx context.Context, tenantID, userID shared.ID) error

	// DeleteOlderThan removes notifications older than the given duration.
	DeleteOlderThan(ctx context.Context, age time.Duration) (int64, error)

	// GetPreferences returns notification preferences for a user.
	GetPreferences(ctx context.Context, tenantID, userID shared.ID) (*Preferences, error)

	// UpsertPreferences creates or updates notification preferences.
	UpsertPreferences(ctx context.Context, tenantID, userID shared.ID, params PreferencesParams) (*Preferences, error)
}

Repository defines the interface for user notification persistence.

Jump to

Keyboard shortcuts

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