syncclient

package
v0.55.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const PKCEChallengeMethod = "S256"

PKCEChallengeMethod is the only PKCE method td-sync supports.

Variables

View Source
var (
	ErrUnauthorized = errors.New("unauthorized")
	ErrForbidden    = errors.New("forbidden")
	ErrNotFound     = errors.New("not found")
)

Sentinel errors for common HTTP error classes.

Functions

This section is empty.

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
	HTTP     *http.Client
}

Client is an HTTP client for the td-sync server.

func New

func New(baseURL, apiKey, deviceID string) *Client

New creates a new sync client.

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) 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

func (c *Client) RemoveMember(projectID, userID string) error

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) UpdateMemberRole

func (c *Client) UpdateMemberRole(projectID, userID, role string) error

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 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

type PKCE struct {
	Verifier  string
	Challenge string
	Method    string
}

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

func GeneratePKCE() (*PKCE, error)

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 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

type SnapshotResponse struct {
	Data        []byte
	SnapshotSeq int64
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL