From 810a13cee0ea1f81982e4bc722c30bdfe572c041 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Tue, 21 Apr 2026 21:55:37 +0000 Subject: [PATCH] Add initial lob hook receiver --- api/routes.go | 3 ++ resource/lob_hook.go | 94 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 resource/lob_hook.go diff --git a/api/routes.go b/api/routes.go index 6f02cae5..6935ab18 100644 --- a/api/routes.go +++ b/api/routes.go @@ -38,6 +38,9 @@ func AddRoutes(r *mux.Router) { lead := resource.Lead(r) r.Handle("/leads", authenticatedHandlerJSON(lead.List)).Methods("GET") r.Handle("/leads", authenticatedHandlerJSONPost(lead.Create)).Methods("POST") + lob_hook := resource.LobHook(router) + r.Handle("/lob/event", handlerBasic(lob_hook.Event)).Methods("POST") + mailer := resource.Mailer(router) r.Handle("/mailer", authenticatedHandlerJSONSlice(mailer.List)).Methods("GET") r.Handle("/mailer/{id}", authenticatedHandlerJSONPost(mailer.ByIDGet)).Methods("GET").Name("mailer.ByIDGet") diff --git a/resource/lob_hook.go b/resource/lob_hook.go new file mode 100644 index 00000000..94470c94 --- /dev/null +++ b/resource/lob_hook.go @@ -0,0 +1,94 @@ +package resource + +import ( + "context" + "encoding/json" + "io" + "net/http" + "time" + + /*"github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/Gleipnir-Technology/nidus-sync/html" + */ + nhttp "github.com/Gleipnir-Technology/nidus-sync/http" + /* + "github.com/Gleipnir-Technology/nidus-sync/platform" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" + "github.com/google/uuid" + "github.com/gorilla/mux" + */ + "github.com/rs/zerolog/log" +) + +func LobHook(r *router) *lobHookR { + return &lobHookR{ + router: r, + } +} + +type lobHookR struct { + router *router +} + +/* +"id": "redacted", + + "description": "redacted", + "name": "redacted", + "address_line1": "redacted", + "address_line2": "redacted", + "address_city": "redacted", + "address_state": "redacted", + "address_zip": "redacted", + "address_country": "redacted", + "metadata": {}, + "date_created": "2026-04-21T21:43:44.819Z", + "date_modified": "2026-04-21T21:43:44.819Z", + "object": "redacted" +*/ +type LobEventBody struct { + Description string `json:"description"` + Name string `json:"name"` + AddressLine1 string `json:"address_line1"` + AddressLine2 string `json:"address_line2"` + AddressCity string `json:"address_city"` + AddressState string `json:"address_state"` + AddressZip string `json:"address_zip"` + AddressCountry string `json:"address_country"` + Metadata json.RawMessage `json:"metadata"` + DateCreated time.Time `json:"date_created"` + DateModified time.Time `json:"date_modified"` + Object string `json:"object"` +} +type LobEventType struct { + ID string `json:"id"` + EnabledForTest bool `json:"enabled_for_test"` + Resource string `json:"addresses"` + Object string `json:"object"` +} +type LobEvent struct { + Body LobEventBody `json:"body"` + DateCreated time.Time `json:"date_created"` + ID string `json:"id"` + Object string `json:"object"` + ReferenceID string `json:"reference_id"` + EventType LobEventType `json:"event_type"` +} + +func (res *lobHookR) Event(ctx context.Context, w http.ResponseWriter, r *http.Request) *nhttp.ErrorWithStatus { + body, err := io.ReadAll(r.Body) + if err != nil { + return nhttp.NewError("read body: %w", err) + } + var event LobEvent + err = json.Unmarshal(body, &event) + if err != nil { + return nhttp.NewBadRequest("unmarshal json: %w", err) + } + log.Info().Str("method", r.Method).Str("content", string(body)).Str("id", event.ID).Msg("got lob event") + http.Error(w, "", http.StatusNoContent) + return nil +}