Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventData ¶
type EventData struct {
// ServiceName identifies the service that produced the audit event.
ServiceName string
Action constants.AuditAction
ResourceType constants.ObjectType
ResourceID string
Changes []FieldChange
// RootResourceType / RootResourceID identify the root record this audited entity belongs to (e.g. the sales_order that a sales_order_line, pick, shipment, or invoice hangs off of). Optional; when set they let a single query return an entire record tree's history, including deleted children. Leave empty for top-level records with no parent.
RootResourceType constants.ObjectType
RootResourceID string
// Metadata is any additional JSON-serializable context associated with the mutation (e.g. "reason", "source", "tags").
Metadata map[string]any
}
EventData is the producer-side input for publishing an audit event via the platform's transactional outbox pipeline.
type FieldChange ¶
type FieldChange struct {
Field string `json:"field"`
OldValue json.RawMessage `json:"old_value"`
NewValue json.RawMessage `json:"new_value"`
}
FieldChange represents a single field-level before/after transition.
OldValue/NewValue are JSON fragments (possibly "null").
func ComputeChanges ¶
func ComputeChanges(old, new any, fields ...string) []FieldChange
ComputeChanges compares two values (typically two versions of the same struct) and returns field-level before/after changes.
Only struct fields with a non-empty `audit` struct tag are considered. When fields is empty, every exported field that has an `audit` tag is compared. When fields is non-empty, each name must be a Go struct field name that also has an `audit` tag; untagged fields are skipped.
func NewFieldChange ¶
func NewFieldChange(field string, oldValue, newValue any) FieldChange
NewFieldChange builds a FieldChange from explicit old/new values for call sites where the change is not derivable from two struct snapshots (e.g. computed quantities). Values are marshalled to JSON fragments the same way ComputeChanges does.
type PublishedEvent ¶
type PublishedEvent struct {
TypeID string `json:"type_id"`
Action constants.AuditAction `json:"action"`
ResourceType constants.ObjectType `json:"resource_type"`
ResourceID string `json:"resource_id"`
RootResourceType constants.ObjectType `json:"root_resource_type,omitempty"`
RootResourceID string `json:"root_resource_id,omitempty"`
Changes []FieldChange `json:"changes"`
Metadata map[string]any `json:"metadata"`
ServiceName string `json:"service_name"`
IdempotencyKeyID *string `json:"idempotency_key_id,omitempty"`
SourceIP *string `json:"source_ip,omitempty"`
// OccurredAt is the time the mutation took effect (UTC).
OccurredAt time.Time `json:"occurred_at"`
}
PublishedEvent is the JSON payload persisted in the outbox and later processed by the platform-service audit consumer.
type Publisher ¶
type Publisher struct{}
func NewPublisher ¶
func NewPublisher() *Publisher
func (*Publisher) Publish ¶
func (p *Publisher) Publish( ctx context.Context, outboxRepo messaging.OutboxRepo, data EventData, ) *apierror.APIError
Publish enqueues an audit event via the platform outbox pipeline.
It is safe to call inside a service transaction: the outboxRepo write is performed atomically with the business mutation.