public
import "github.com/prescriptoo/prescriptoo-api/services/audit/public"Package public defines Audit capabilities. HTTP belongs to Admin and Organization.
Index
- Variables
- func ValidateOperation(op OperationContext) error
- func WithOperation(ctx context.Context, op OperationContext) context.Context
- func WithRequest(ctx context.Context, r RequestContext) context.Context
- type Actor
- type AuditActor
- type AuditChange
- type AuditEvent
- type AuditEventSummary
- type AuditPage
- type AuditScope
- type Change
- type Changes
- type Event
- type EventInput
- type EventLister
- type EventQuery
- type EventReader
- type EventSummary
- type ListInput
- type OperationContext
- type Page
- type Query
- type Recorder
- type RequestContext
- type Scope
- type TransactionalRecorderFactory
Variables
var (
// ErrInvalidInput rejects an invalid event or query.
ErrInvalidInput = errors.New("invalid audit input")
// ErrForbidden denies access without the scoped audit grant.
ErrForbidden = errors.New("audit access forbidden")
// ErrNotFound indicates no event in the requested history.
ErrNotFound = errors.New("audit event not found")
// ErrUnavailable indicates a required audit dependency failed.
ErrUnavailable = errors.New("audit unavailable")
// ErrAppend indicates recording failed and the transaction was aborted.
ErrAppend = errors.New("audit append failed")
)func ValidateOperation
func ValidateOperation(op OperationContext) errorValidateOperation rejects incomplete trusted context before a transaction can write, including effective no-op operations which won't append a change entry.
func WithOperation
func WithOperation(ctx context.Context, op OperationContext) context.ContextWithOperation propagates verified operation context through legacy adapters.
func WithRequest
func WithRequest(ctx context.Context, r RequestContext) context.ContextWithRequest attaches transport metadata captured by the API composition root.
type Actor
Actor is the concise Go name for an immutable Audit actor snapshot.
type Actor = AuditActortype AuditActor
AuditActor preserves the verified identity and display name at event time. NewOperation uses UserID as the name when no display name is supplied.
type AuditActor struct {
UserID string `json:"user_id"`
MembershipID string `json:"membership_id,omitempty"`
Name string `json:"name"`
}type AuditChange
AuditChange contains the previous and committed values of one approved field.
type AuditChange struct {
Before any `json:"before"`
After any `json:"after"`
}type AuditEvent
AuditEvent adds approved changes and request context to a history summary.
type AuditEvent struct {
EventSummary
Changes Changes `json:"changes"`
Metadata map[string]json.RawMessage `json:"metadata"`
Reason string `json:"reason,omitempty"`
IPAddress string `json:"ip_address,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
}type AuditEventSummary
AuditEventSummary contains the immutable attribution and resource reference used in lists.
type AuditEventSummary struct {
ID string `json:"id"`
Version int `json:"version"`
Name string `json:"name"`
Source string `json:"source"`
Scope Scope `json:"scope"`
OrganizationID string `json:"organization_id,omitempty"`
ResourceType string `json:"resource_type"`
ResourceID string `json:"resource_id"`
Actor Actor `json:"actor"`
RequestID string `json:"request_id"`
OperationID string `json:"operation_id"`
OccurredAt time.Time `json:"occurred_at"`
RecordedAt time.Time `json:"recorded_at"`
}type AuditPage
AuditPage returns summaries and a cursor bound to the query scope and filters.
type AuditPage struct {
Items []EventSummary `json:"items" nullable:"false"`
NextCursor string `json:"next_cursor,omitempty"`
}type AuditScope
AuditScope selects platform history or exactly one organization history.
type AuditScope struct {
Type string `json:"type" enum:"admin,organization"`
OrganizationID string `json:"organization_id,omitempty"`
}type Change
Change is the concise Go name for a field change.
type Change = AuditChangetype Changes
Changes maps approved business fields to their historical values.
type Changes map[string]Changefunc Diff
func Diff(before, after map[string]any) ChangesDiff compares explicitly selected JSON-safe business fields. It never reflects over a domain entity, which could accidentally capture credentials.
type Event
Event is the concise Go name for a complete Audit event.
type Event = AuditEventtype EventInput
EventInput describes one authoritative change using an application-owned event schema.
type EventInput struct {
Name string
Source string
ResourceType string
ResourceID string
OrganizationID string
Changes Changes
Metadata map[string]any
}type EventLister
EventLister lists history after enforcing the scoped audit permission.
type EventLister interface {
ListEvents(context.Context, ListInput) (*Page, error)
}type EventQuery
EventQuery identifies a single event within an authorized history.
type EventQuery struct {
Query
EventID string
}type EventReader
EventReader reads an event after enforcing the scoped audit permission.
type EventReader interface {
GetEvent(context.Context, EventQuery) (*Event, error)
}type EventSummary
EventSummary is the concise Go name for an Audit list entry.
type EventSummary = AuditEventSummarytype ListInput
ListInput filters scoped history; a resource ID requires a resource type.
type ListInput struct {
Query
ActorUserID string
Name string
ResourceType string
ResourceID string
OperationID string
OrganizationID string
From *time.Time
To *time.Time
Limit int
Cursor string
}type OperationContext
OperationContext is server-constructed and is never decoded from HTTP bodies.
type OperationContext struct {
Scope Scope
Actor Actor
RequestID string
OperationID string
IPAddress string
UserAgent string
Reason string
}func NewOperation
func NewOperation(ctx context.Context, scope Scope, actor Actor) OperationContextNewOperation combines the verified actor and scope with captured request metadata. A missing display name falls back to the verified actor's user ID.
func OperationFrom
func OperationFrom(ctx context.Context) OperationContextOperationFrom returns the verified operation context, or an empty value when absent.
type Page
Page is the concise Go name for a scoped Audit result page.
type Page = AuditPagetype Query
Query identifies the authenticated reader and explicit history scope.
type Query struct {
UserID string
Scope Scope
}type Recorder
Recorder appends within its bound transaction and aborts that transaction on failure.
type Recorder interface {
Append(context.Context, OperationContext, EventInput) error
}type RequestContext
RequestContext carries server-generated correlation and transport-peer metadata.
type RequestContext struct{ RequestID, OperationID, IPAddress, UserAgent string }func RequestFrom
func RequestFrom(ctx context.Context) RequestContextRequestFrom returns captured metadata, or an empty value when absent.
type Scope
Scope is the concise Go name for the distinctly named Audit OpenAPI schema.
type Scope = AuditScopetype TransactionalRecorderFactory
TransactionalRecorderFactory is consumed only by infrastructure adapters.
type TransactionalRecorderFactory interface{ InTransaction(pgx.Tx) Recorder }Generated by gomarkdoc