Documentation
¶
Overview ¶
Package apicontract defines the release-independent Tapper REST contract.
Index ¶
- Constants
- func Do(client *http.Client, req *http.Request) (*http.Response, error)
- func IsCompatibility(err error) bool
- func LogFailure(ctx context.Context, logger *slog.Logger, level slog.Level, client string, ...)
- func Middleware(server string, logger *slog.Logger) func(http.Handler) http.Handler
- func RequestRevision(ctx context.Context) string
- func SupportedRevisions() []string
- func WithRequestRevision(ctx context.Context, rev string) context.Context
- func WithSession(ctx context.Context, s *Session) context.Context
- type CompatibilityError
- type Discovery
- type DiscoveryCache
- type Session
Constants ¶
const ClientHeader = "Tapper-Client-Version"
const DefaultDiscoveryCacheTTL = time.Hour
DefaultDiscoveryCacheTTL is how long a cached discovery success is trusted when Session.CacheTTL is unset.
const DiscoveryInvalid = "API_DISCOVERY_INVALID"
const Required = "API_VERSION_REQUIRED"
const Revision = "2026-10-17"
Revision is the contract this build speaks: the revision a client sends on every REST request and the newest one a Hub serves.
const Unsupported = "API_VERSION_UNSUPPORTED"
const VersionHeader = "Tapper-API-Version"
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do applies discovery, mandatory headers, redirect restrictions and typed errors to a REST request. Non-REST OAuth and archive requests pass through unchanged.
func IsCompatibility ¶
func LogFailure ¶
func LogFailure(ctx context.Context, logger *slog.Logger, level slog.Level, client string, err error, requestID string)
LogFailure emits only compatibility metadata, never request contents or credentials.
func Middleware ¶
Middleware gates all /api/v1 paths, including unknown operations, before auth. Discovery is build-only and remains usable when database services are down. An accepted request carries its revision in the response header and in its context (RequestRevision).
func RequestRevision ¶ added in v0.47.0
RequestRevision reports the contract revision Middleware accepted for the request carrying ctx, or "" when the request did not pass the REST gate.
func SupportedRevisions ¶ added in v0.47.0
func SupportedRevisions() []string
SupportedRevisions lists every revision a Hub accepts, newest first. The slice is a fresh copy on each call.
func WithRequestRevision ¶ added in v0.47.0
WithRequestRevision returns ctx recording rev as the negotiated revision, as Middleware does for every accepted REST request. Tests of handlers that answer per revision use it to stand in for the gate.
Types ¶
type CompatibilityError ¶
type CompatibilityError struct {
Message string `json:"error"`
Code string `json:"code"`
Requested []string `json:"requested_api_versions"`
Supported []string `json:"supported_api_versions"`
ServerVersion string `json:"server_version,omitempty"`
OperationPerformed bool `json:"operationPerformed"`
}
CompatibilityError guarantees the blocked application operation was not sent or was rejected by the server before authentication and dispatch.
func Validate ¶
func Validate(h http.Header, server string) *CompatibilityError
Validate accepts exactly one unmodified contract revision header value naming one of SupportedRevisions.
func (*CompatibilityError) Error ¶
func (e *CompatibilityError) Error() string
type DiscoveryCache ¶ added in v0.47.0
type DiscoveryCache interface {
// Get returns when key last passed discovery.
Get(key string) (time.Time, bool)
// Put records that key passed discovery at checked.
Put(key string, checked time.Time)
// Delete forgets key after the Hub rejected the cached contract.
Delete(key string)
}
DiscoveryCache persists successful discovery beyond one Session, so a new invocation can skip GET /api/version. Keys name a Hub base URL and this package's Revision. Only successes are stored; failures stay with the Session that saw them. Implementations must be safe for concurrent use and treat every error as a miss.
type Session ¶
type Session struct {
ClientVersion string
Logger *slog.Logger
Cache DiscoveryCache
CacheTTL time.Duration
Now func() time.Time
// contains filtered or unexported fields
}
Session caches discovery per Hub for one invocation or MCP connection.
Cache, when set, extends a success past the Session for CacheTTL (DefaultDiscoveryCacheTTL when zero), measured with Now (time.Now when nil). A stale entry is safe: the Hub still validates every request, and a typed rejection evicts the entry.