hatch-surf/internal/store/models.go
SoftwareEngineer 4256d34c27 feat: add one-click replay for captured requests
- Add POST /e/{endpoint}/requests/{id}/replay endpoint
- Replay re-sends captured method, path, headers, query, body to target URL
- Response includes target status code, headers, body (truncated 64KB)
- SSRF guard: denies replay to private/loopback by default
- Opt-in env var HATCH_ALLOW_PRIVATE_REPLAY=true for local dev
- Server-rendered inspect page at GET /e/{endpoint} with replay button UI
- SSE live stream for new requests (EventSource)
- Mock configuration at PUT /e/{endpoint}/mock
- Store: GetRequest, GetMock, SetMock methods added
- Chi router migration from stdlib ServeMux
- 26 passing tests including replay unit tests and E2E capture-to-replay

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-22 16:58:42 +02:00

43 lines
1.3 KiB
Go

package store
import "context"
type Endpoint struct {
ID string `json:"id"`
URL string `json:"url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
type Request struct {
ID string `json:"id"`
EndpointID string `json:"endpoint_id"`
Method string `json:"method"`
Path string `json:"path"`
Headers string `json:"headers"`
Query string `json:"query"`
Body []byte `json:"body"`
CreatedAt string `json:"created_at"`
}
// MockConfig holds the mock response configuration for an endpoint.
type MockConfig struct {
EndpointID string `json:"endpoint_id"`
Status int `json:"status"`
Headers map[string]string `json:"headers"`
Body []byte `json:"body"`
}
type Repository interface {
CreateEndpoint(ctx context.Context, url string) (*Endpoint, error)
GetEndpoint(ctx context.Context, id string) (*Endpoint, error)
AppendRequest(ctx context.Context, endpointID string, req *Request) error
GetRequest(ctx context.Context, id string) (*Request, error)
ListRequests(ctx context.Context, endpointID string, limit int) ([]*Request, error)
GetMock(ctx context.Context, endpointID string) (*MockConfig, error)
SetMock(ctx context.Context, mock *MockConfig) error
Close() error
}
var _ Repository = (*sqliteRepo)(nil)