Documentation
¶
Index ¶
- Constants
- Variables
- func IsHTTPStatus(err error, codes ...int) bool
- func SetVersion(version string)
- type AckResponse
- type Client
- func (c *Client) AddMember(projectID, email, role string) (*MemberResponse, error)
- func (c *Client) CreateProject(name, description string) (*ProjectResponse, error)
- func (c *Client) DevicePoll(deviceCode, codeVerifier string) (*DevicePollResponse, error)
- func (c *Client) DeviceStart(email, codeChallenge, method, deviceName string) (*DeviceStartResponse, error)
- func (c *Client) Events(ctx context.Context, projectID, lastEventID string, idleTimeout time.Duration, ...) error
- func (c *Client) GetSnapshot(projectID string) (*SnapshotResponse, error)
- func (c *Client) HealthCheck() (*HealthResponse, error)
- func (c *Client) ListMembers(projectID string) ([]MemberResponse, error)
- func (c *Client) ListProjects() ([]ProjectResponse, error)
- func (c *Client) LoginPoll(deviceCode string) (*LoginPollResponse, error)
- func (c *Client) LoginStart(email string) (*LoginStartResponse, error)
- func (c *Client) Pull(projectID string, afterSeq int64, limit int, excludeDeviceID string) (*PullResponse, error)
- func (c *Client) Push(projectID string, req *PushRequest) (*PushResponse, error)
- func (c *Client) RemoveMember(projectID, userID string) error
- func (c *Client) SyncStatus(projectID string) (*SyncStatusResponse, error)
- func (c *Client) SyncStatusContext(ctx context.Context, projectID string) (*SyncStatusResponse, error)
- func (c *Client) UpdateMemberRole(projectID, userID, role string) error
- type DevicePollResponse
- type DeviceStartResponse
- type EventInput
- type HTTPError
- type HealthResponse
- type LoginPollResponse
- type LoginStartResponse
- type MemberResponse
- type PKCE
- type ProjectEvent
- type ProjectResponse
- type PullEvent
- type PullResponse
- type PushRequest
- type PushResponse
- type RejectResponse
- type SnapshotResponse
- type SyncStatusResponse
Constants ¶
const PKCEChallengeMethod = "S256"
PKCEChallengeMethod is the only PKCE method td-sync supports.
Variables ¶
var ( ErrForbidden = errors.New("forbidden") ErrNotFound = errors.New("not found") ErrStreamStalled = errors.New("event stream stalled") )
Sentinel errors for common HTTP error classes.
Functions ¶
func IsHTTPStatus ¶ added in v0.64.0
IsHTTPStatus reports whether err came from one of the supplied HTTP status codes. It also recognizes the package's historical sentinel errors.
func SetVersion ¶ added in v0.67.0
func SetVersion(version string)
SetVersion sets the td version that clients created afterwards send in their User-Agent. Call it once at startup.
Types ¶
type AckResponse ¶
type AckResponse struct {
ClientActionID int64 `json:"client_action_id"`
ServerSeq int64 `json:"server_seq"`
}
AckResponse is a single acknowledged event.
type Client ¶
type Client struct {
BaseURL string
APIKey string
DeviceID string
UserAgent string
HTTP *http.Client
}
Client is an HTTP client for the td-sync server.
func (*Client) AddMember ¶
func (c *Client) AddMember(projectID, email, role string) (*MemberResponse, error)
AddMember invites a user to a project by email.
func (*Client) CreateProject ¶
func (c *Client) CreateProject(name, description string) (*ProjectResponse, error)
CreateProject creates a new project on the server.
func (*Client) DevicePoll ¶ added in v0.49.0
func (c *Client) DevicePoll(deviceCode, codeVerifier string) (*DevicePollResponse, error)
DevicePoll checks the status of a PKCE device login. It sends the device_code from DeviceStart together with the local code_verifier; the server only issues a key once the emailed approval link has been clicked AND the verifier matches the code_challenge sent in DeviceStart. No API key required.
func (*Client) DeviceStart ¶ added in v0.49.0
func (c *Client) DeviceStart(email, codeChallenge, method, deviceName string) (*DeviceStartResponse, error)
DeviceStart initiates the PKCE device-login flow. The caller generates a local code_verifier and passes only its S256 code_challenge here; the verifier is never sent until DevicePoll. No API key required.
method must be "S256". The server emails a magic approval link to the address and returns a device_code used to poll for completion.
func (*Client) Events ¶ added in v0.64.0
func (c *Client) Events(ctx context.Context, projectID, lastEventID string, idleTimeout time.Duration, onOpen func(), onEvent func(ProjectEvent)) error
Events consumes the project event stream until ctx is canceled or the connection fails. The request deliberately has no whole-request timeout; idle body liveness is enforced separately so a connected SSE request may live indefinitely while a buffering or dead proxy is detected.
func (*Client) GetSnapshot ¶
func (c *Client) GetSnapshot(projectID string) (*SnapshotResponse, error)
GetSnapshot downloads a snapshot database for bootstrap.
func (*Client) HealthCheck ¶
func (c *Client) HealthCheck() (*HealthResponse, error)
HealthCheck hits the /healthz endpoint to verify server reachability.
func (*Client) ListMembers ¶
func (c *Client) ListMembers(projectID string) ([]MemberResponse, error)
ListMembers lists all members of a project.
func (*Client) ListProjects ¶
func (c *Client) ListProjects() ([]ProjectResponse, error)
ListProjects lists all projects for the authenticated user.
func (*Client) LoginPoll ¶
func (c *Client) LoginPoll(deviceCode string) (*LoginPollResponse, error)
LoginPoll checks the status of a device auth request. No API key required.
func (*Client) LoginStart ¶
func (c *Client) LoginStart(email string) (*LoginStartResponse, error)
LoginStart initiates device auth flow. No API key required.
func (*Client) Pull ¶
func (c *Client) Pull(projectID string, afterSeq int64, limit int, excludeDeviceID string) (*PullResponse, error)
Pull fetches remote events from the server.
func (*Client) Push ¶
func (c *Client) Push(projectID string, req *PushRequest) (*PushResponse, error)
Push sends local events to the server.
func (*Client) RemoveMember ¶
RemoveMember removes a user from a project.
func (*Client) SyncStatus ¶
func (c *Client) SyncStatus(projectID string) (*SyncStatusResponse, error)
SyncStatus gets the sync status for a project.
func (*Client) SyncStatusContext ¶ added in v0.64.0
func (c *Client) SyncStatusContext(ctx context.Context, projectID string) (*SyncStatusResponse, error)
SyncStatusContext gets sync status with caller cancellation.
func (*Client) UpdateMemberRole ¶
UpdateMemberRole changes a member's role in a project.
type DevicePollResponse ¶ added in v0.49.0
type DevicePollResponse struct {
Status string `json:"status"`
APIKey *string `json:"api_key,omitempty"`
UserID *string `json:"user_id,omitempty"`
Email *string `json:"email,omitempty"`
ExpiresAt *string `json:"expires_at,omitempty"`
}
DevicePollResponse is the response from POST /v1/auth/device/poll. When status=="pending" only Status is set; when status=="complete" all fields are populated.
type DeviceStartResponse ¶ added in v0.49.0
type DeviceStartResponse struct {
DeviceCode string `json:"device_code"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
EmailSent bool `json:"email_sent"`
}
DeviceStartResponse is the response from POST /v1/auth/device/start. The flow is non-enumerating: a syntactically-valid email always yields a device_code and email_sent=true, even for unknown accounts (in which case no email is sent and poll never transitions to complete).
type EventInput ¶
type EventInput struct {
ClientActionID int64 `json:"client_action_id"`
ActionType string `json:"action_type"`
EntityType string `json:"entity_type"`
EntityID string `json:"entity_id"`
Payload json.RawMessage `json:"payload"`
ClientTimestamp string `json:"client_timestamp"`
}
EventInput is a single event in a push request.
type HTTPError ¶ added in v0.64.0
HTTPError preserves the response status for callers implementing transport degradation policy without making that policy part of this HTTP adapter.
type HealthResponse ¶
type HealthResponse struct {
Status string `json:"status"`
}
HealthResponse is the response from GET /healthz.
type LoginPollResponse ¶
type LoginPollResponse struct {
Status string `json:"status"`
APIKey *string `json:"api_key,omitempty"`
UserID *string `json:"user_id,omitempty"`
Email *string `json:"email,omitempty"`
ExpiresAt *string `json:"expires_at,omitempty"`
}
LoginPollResponse is the response from POST /v1/auth/login/poll.
type LoginStartResponse ¶
type LoginStartResponse struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
LoginStartResponse is the response from POST /v1/auth/login/start.
type MemberResponse ¶
type MemberResponse struct {
ProjectID string `json:"project_id"`
UserID string `json:"user_id"`
Role string `json:"role"`
InvitedBy string `json:"invited_by"`
CreatedAt string `json:"created_at"`
}
MemberResponse represents a project member from the server.
type PKCE ¶ added in v0.49.0
PKCE holds a generated PKCE verifier/challenge pair for the device-login flow. Verifier is kept locally and only sent to the server at poll time; Challenge (the S256 hash) is the only part disclosed in DeviceStart.
func GeneratePKCE ¶ added in v0.49.0
GeneratePKCE creates a fresh PKCE pair using crypto/rand. The relationship is Challenge = base64.RawURLEncoding(SHA-256(Verifier)), which is exactly what the td-sync device/poll handler recomputes and compares against the stored code_challenge.
type ProjectEvent ¶ added in v0.64.0
ProjectEvent is one notification from the project's SSE endpoint. The payload is intentionally opaque: events are refresh hints, never the data path. State still arrives through Pull.
type ProjectResponse ¶
type ProjectResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt *string `json:"deleted_at,omitempty"`
}
ProjectResponse represents a project from the server.
type PullEvent ¶
type PullEvent struct {
ServerSeq int64 `json:"server_seq"`
DeviceID string `json:"device_id"`
SessionID string `json:"session_id"`
ClientActionID int64 `json:"client_action_id"`
ActionType string `json:"action_type"`
EntityType string `json:"entity_type"`
EntityID string `json:"entity_id"`
Payload json.RawMessage `json:"payload"`
ClientTimestamp string `json:"client_timestamp"`
}
PullEvent is a single event in a pull response.
type PullResponse ¶
type PullResponse struct {
Events []PullEvent `json:"events"`
LastServerSeq int64 `json:"last_server_seq"`
HasMore bool `json:"has_more"`
}
PullResponse is the response from a pull request.
type PushRequest ¶
type PushRequest struct {
DeviceID string `json:"device_id"`
SessionID string `json:"session_id"`
Events []EventInput `json:"events"`
}
PushRequest is the body for POST /v1/projects/{id}/sync/push.
type PushResponse ¶
type PushResponse struct {
Accepted int `json:"accepted"`
Acks []AckResponse `json:"acks"`
Rejected []RejectResponse `json:"rejected,omitempty"`
}
PushResponse is the response from a push request.
type RejectResponse ¶
type RejectResponse struct {
ClientActionID int64 `json:"client_action_id"`
Reason string `json:"reason"`
ServerSeq int64 `json:"server_seq,omitempty"`
}
RejectResponse is a single rejected event.
type SnapshotResponse ¶
SnapshotResponse holds the result of a snapshot download.
type SyncStatusResponse ¶
type SyncStatusResponse struct {
EventCount int64 `json:"event_count"`
LastServerSeq int64 `json:"last_server_seq"`
LastEventTime string `json:"last_event_time,omitempty"`
}
SyncStatusResponse is the response from GET /v1/projects/{id}/sync/status.