Files
tenant-registry/internal/store/intake.go
Sharang ParnerkarandClaude Opus 5.5 4c17affc1f
ci / shared (pull_request) Successful in 10s
ci / test (pull_request) Successful in 5m9s
ci / image (pull_request) Skipped
feat(intake): page the pending list and say when a capture is settled
The pending list is across workspaces, oldest first; entries that keep
waiting in one workspace (no receiving workflow, not booked) could fill
every page and hide those of all others. GET /v1/internal/intake/pending
takes after=<entry id>, so the reader pages on with the last id it got.

Each item says whether its report's capture is settled
(capture_settled), so a reader paging on can hold a supplement back
until its capture is handed over, also when the capture was on an
earlier page. Without after the route answers as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-10 10:50:54 +01:00

116 lines
3.5 KiB
Go

package store
import (
"encoding/json"
"fmt"
"time"
)
// R1 intake (0028, docgen#6 F01): the original capture of a security
// notice, its supplements and what became of each downstream. Nothing is
// ever changed.
// Intake channels, what a report is about by the reporter's own account, and
// the reporter's answer to "immediate danger to people?".
const (
IntakeChannelPortal = "portal"
IntakeAboutProduct = "product"
IntakeAboutITOT = "it_ot"
IntakeAboutUnknown = "unknown"
IntakeEntryCapture = "capture"
IntakeEntrySupplement = "supplement"
IntakeWaiting = "waiting"
IntakeDelivered = "delivered"
IntakeProcessed = "processed"
IntakeRefused = "refused"
)
// IntakeReference is the Eingangsreferenz of a tenant's seq-th report,
// received at.
func IntakeReference(at time.Time, seq int) string {
return fmt.Sprintf("SH-%04d-%05d", at.UTC().Year(), seq)
}
// IntakeReport is one report: its reference, the time of the first R1
// capture, the channel, the reporter and the reporter's own answers.
type IntakeReport struct {
TenantID string `json:"tenant_id"`
Reference string `json:"reference"`
ReceivedAt time.Time `json:"received_at"`
Channel string `json:"channel"`
ReporterSub string `json:"-"`
About string `json:"about"`
Danger string `json:"danger"`
}
// IntakeEntry is the capture or a supplement, with its receipts, oldest
// first. Content is the original as entered.
type IntakeEntry struct {
ID int64 `json:"id"`
TenantID string `json:"-"`
Reference string `json:"-"`
Kind string `json:"kind"`
Content json.RawMessage `json:"-"`
By string `json:"-"`
At time.Time `json:"at"`
Receipts []IntakeReceipt `json:"receipts"`
}
// Status is the newest receipt's status, "" before the first one.
func (e IntakeEntry) Status() string {
if len(e.Receipts) == 0 {
return ""
}
return e.Receipts[len(e.Receipts)-1].Status
}
// IntakeReceipt is what became of an entry downstream.
type IntakeReceipt struct {
EntryID int64 `json:"-"`
Status string `json:"status"`
Reason string `json:"reason,omitempty"`
HandoffID string `json:"handoff_id,omitempty"`
RunID string `json:"run_id,omitempty"`
By string `json:"-"`
At time.Time `json:"at"`
}
// Settled: processed or refused, after which no receipt follows.
func (r IntakeReceipt) Settled() bool {
return r.Status == IntakeProcessed || r.Status == IntakeRefused
}
// IntakeCapture records a new report.
type IntakeCapture struct {
TenantID string
Channel string
ReporterSub string
About string
Danger string
Original json.RawMessage
At time.Time
}
// PendingIntake is an entry not settled yet, with what routing reads of its
// report; never its content.
type PendingIntake struct {
EntryID int64 `json:"entry_id"`
TenantID string `json:"tenant_id"`
Reference string `json:"reference"`
Kind string `json:"kind"`
At time.Time `json:"at"`
ReceivedAt time.Time `json:"received_at"`
Channel string `json:"channel"`
About string `json:"about"`
Danger string `json:"danger"`
Status string `json:"status,omitempty"`
Reason string `json:"reason,omitempty"`
HandoffID string `json:"handoff_id,omitempty"`
// CaptureSettled: the report's capture is processed or refused. A
// supplement is handed over only after its capture.
CaptureSettled bool `json:"capture_settled"`
}