Some checks failed
Go / build-and-release (push) Has been cancelled
Major refactoring of event handling into clean, testable domain services: - Add pkg/event/validation: JSON hex validation, signature verification, timestamp bounds, NIP-70 protected tag validation - Add pkg/event/authorization: Policy and ACL authorization decisions, auth challenge handling, access level determination - Add pkg/event/routing: Event router registry with ephemeral and delete handlers, kind-based dispatch - Add pkg/event/processing: Event persistence, delivery to subscribers, and post-save hooks (ACL reconfig, sync, relay groups) - Reduce handle-event.go from 783 to 296 lines (62% reduction) - Add comprehensive unit tests for all new domain services - Refactor database tests to use shared TestMain setup - Fix blossom URL test expectations (missing "/" separator) - Add go-memory-optimization skill and analysis documentation - Update DDD_ANALYSIS.md to reflect completed decomposition Files modified: - app/handle-event.go: Slim orchestrator using domain services - app/server.go: Service initialization and interface wrappers - app/handle-event-types.go: Shared types (OkHelper, result types) - pkg/event/validation/*: New validation service package - pkg/event/authorization/*: New authorization service package - pkg/event/routing/*: New routing service package - pkg/event/processing/*: New processing service package - pkg/database/*_test.go: Refactored to shared TestMain - pkg/blossom/http_test.go: Fixed URL format expectations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
73 lines
2.5 KiB
Go
73 lines
2.5 KiB
Go
package app
|
|
|
|
import (
|
|
"git.mleku.dev/mleku/nostr/encoders/envelopes/eventenvelope"
|
|
"git.mleku.dev/mleku/nostr/encoders/envelopes/okenvelope"
|
|
"git.mleku.dev/mleku/nostr/encoders/reason"
|
|
"next.orly.dev/pkg/event/authorization"
|
|
"next.orly.dev/pkg/event/routing"
|
|
"next.orly.dev/pkg/event/validation"
|
|
)
|
|
|
|
// sendValidationError sends an appropriate OK response for a validation failure.
|
|
func (l *Listener) sendValidationError(env eventenvelope.I, result validation.Result) error {
|
|
var r []byte
|
|
switch result.Code {
|
|
case validation.ReasonBlocked:
|
|
r = reason.Blocked.F(result.Msg)
|
|
case validation.ReasonInvalid:
|
|
r = reason.Invalid.F(result.Msg)
|
|
case validation.ReasonError:
|
|
r = reason.Error.F(result.Msg)
|
|
default:
|
|
r = reason.Error.F(result.Msg)
|
|
}
|
|
return okenvelope.NewFrom(env.Id(), false, r).Write(l)
|
|
}
|
|
|
|
// sendAuthorizationDenied sends an appropriate OK response for an authorization denial.
|
|
func (l *Listener) sendAuthorizationDenied(env eventenvelope.I, decision authorization.Decision) error {
|
|
var r []byte
|
|
if decision.RequireAuth {
|
|
r = reason.AuthRequired.F(decision.DenyReason)
|
|
} else {
|
|
r = reason.Blocked.F(decision.DenyReason)
|
|
}
|
|
return okenvelope.NewFrom(env.Id(), false, r).Write(l)
|
|
}
|
|
|
|
// sendRoutingError sends an appropriate OK response for a routing error.
|
|
func (l *Listener) sendRoutingError(env eventenvelope.I, result routing.Result) error {
|
|
if result.Error != nil {
|
|
return okenvelope.NewFrom(env.Id(), false, reason.Error.F(result.Error.Error())).Write(l)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// sendProcessingError sends an appropriate OK response for a processing failure.
|
|
func (l *Listener) sendProcessingError(env eventenvelope.I, msg string) error {
|
|
return okenvelope.NewFrom(env.Id(), false, reason.Error.F(msg)).Write(l)
|
|
}
|
|
|
|
// sendProcessingBlocked sends an appropriate OK response for a blocked event.
|
|
func (l *Listener) sendProcessingBlocked(env eventenvelope.I, msg string) error {
|
|
return okenvelope.NewFrom(env.Id(), false, reason.Blocked.F(msg)).Write(l)
|
|
}
|
|
|
|
// sendRawValidationError sends an OK response for raw JSON validation failure (before unmarshal).
|
|
// Since we don't have an event ID at this point, we pass nil.
|
|
func (l *Listener) sendRawValidationError(result validation.Result) error {
|
|
var r []byte
|
|
switch result.Code {
|
|
case validation.ReasonBlocked:
|
|
r = reason.Blocked.F(result.Msg)
|
|
case validation.ReasonInvalid:
|
|
r = reason.Invalid.F(result.Msg)
|
|
case validation.ReasonError:
|
|
r = reason.Error.F(result.Msg)
|
|
default:
|
|
r = reason.Error.F(result.Msg)
|
|
}
|
|
return okenvelope.NewFrom(nil, false, r).Write(l)
|
|
}
|