From e898acedc8a4bf50f90df8d709ac7ee1e1d0607c Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sun, 15 Nov 2026 18:07:28 +1100 Subject: [PATCH] fix(events): the events API returns a JSON view, not the row struct (#1980) --- modules/events/events.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/events/events.go b/modules/events/events.go index a844c0287..8a22441bd 100644 --- a/modules/events/events.go +++ b/modules/events/events.go @@ -259,7 +259,36 @@ func (m *Module) recent(w http.ResponseWriter, r *http.Request) { httpjson.Error(w, http.StatusInternalServerError, err.Error()) return } - httpjson.Write(w, http.StatusOK, events) + out := make([]eventView, 0, len(events)) + for _, e := range events { + out = append(out, viewOf(e)) + } + httpjson.Write(w, http.StatusOK, out) +} + +// eventView is an event as the API returns it. +type eventView struct { + ID uuid.UUID `json:"id"` + Source string `json:"source"` + Type string `json:"type"` + Fields json.RawMessage `json:"fields"` + LinkedTo *uuid.UUID `json:"linked_to,omitempty"` + OccurredAt *time.Time `json:"occurred_at,omitempty"` + ReceivedAt time.Time `json:"received_at"` + Matched bool `json:"matched"` + DispatchedAt *time.Time `json:"dispatched_at,omitempty"` +} + +func viewOf(e store.Event) eventView { + v := eventView{ID: e.ID, Source: e.Source, Type: e.Type, Fields: e.Fields, LinkedTo: e.LinkedTo, + ReceivedAt: e.ReceivedAt, Matched: e.Matched} + if e.OccurredAt.Valid { + v.OccurredAt = &e.OccurredAt.Time + } + if e.DispatchedAt.Valid { + v.DispatchedAt = &e.DispatchedAt.Time + } + return v } func newToken() (string, error) {