syncclient

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 9 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

This section is empty.

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