feat(platform): add the notification inbox and deterministic match search
This commit is contained in:
1 parent
5edff21d2d
commit
0b11021b16
169 files changed
+17083
-443
No files matched your search
@@ -14,13 +14,41 @@ var ErrInvalidNotificationInboxEntry = errors.New("invalid notification inbox en
|
||||
// in the internal inbox.
|
||||
type NotificationInboxEventType string
|
||||
|
||||
const NotificationInboxInvitationDelivered NotificationInboxEventType = "invitation.delivered"
|
||||
const (
|
||||
// NotificationInboxInvitationDelivered records that an invitation reached
|
||||
// the candidate's inbox. Its source is the invitation.
|
||||
NotificationInboxInvitationDelivered NotificationInboxEventType = "invitation.delivered"
|
||||
// NotificationInboxSyntheticDelivered is a synthetic event type. It
|
||||
// carries no product meaning: it exists to exercise the whole inbox path
|
||||
// (outbox, consumer, read-time visibility check, listing, read state)
|
||||
// before real producers exist and in browser tests. Its source is the
|
||||
// sending organization, and its content is a fixed notice that names that
|
||||
// organization.
|
||||
NotificationInboxSyntheticDelivered NotificationInboxEventType = "notification.synthetic_delivered"
|
||||
)
|
||||
|
||||
// NotificationInboxSourceType identifies the current source-of-truth record
|
||||
// used to resolve an inbox item's content.
|
||||
type NotificationInboxSourceType string
|
||||
|
||||
const NotificationInboxSourceInvitation NotificationInboxSourceType = "invitation"
|
||||
const (
|
||||
NotificationInboxSourceInvitation NotificationInboxSourceType = "invitation"
|
||||
NotificationInboxSourceOrganization NotificationInboxSourceType = "organization"
|
||||
)
|
||||
|
||||
// NotificationInboxSourceFor returns the only source type that an event type
|
||||
// may refer to, and false for an event type that is not allowlisted. The
|
||||
// database repeats the same pairs in a CHECK constraint.
|
||||
func NotificationInboxSourceFor(eventType NotificationInboxEventType) (NotificationInboxSourceType, bool) {
|
||||
switch eventType {
|
||||
case NotificationInboxInvitationDelivered:
|
||||
return NotificationInboxSourceInvitation, true
|
||||
case NotificationInboxSyntheticDelivered:
|
||||
return NotificationInboxSourceOrganization, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
// NotificationInboxEntryInput contains identifiers and event metadata only.
|
||||
// It deliberately has no content snapshot: presentation is resolved from the
|
||||
@@ -78,7 +106,8 @@ func restoreNotificationInboxEntryWithLocation(
|
||||
if input.EventID == uuid.Nil || input.RecipientUserID == uuid.Nil || input.OrganizationID == uuid.Nil || input.SourceID == uuid.Nil {
|
||||
return NotificationInboxEntry{}, fmt.Errorf("%s - event, recipient, organization, and source IDs are required: %w", location, ErrInvalidNotificationInboxEntry)
|
||||
}
|
||||
if input.EventType != NotificationInboxInvitationDelivered || input.SchemaVersion != 1 || input.SourceType != NotificationInboxSourceInvitation {
|
||||
sourceType, known := NotificationInboxSourceFor(input.EventType)
|
||||
if !known || input.SchemaVersion != 1 || input.SourceType != sourceType {
|
||||
return NotificationInboxEntry{}, fmt.Errorf("%s - event type, schema version, and source type are unsupported: %w", location, ErrInvalidNotificationInboxEntry)
|
||||
}
|
||||
if input.OccurredAt.IsZero() {
|
||||
|
||||
Reference in new issue
Block a user