fix(sync): add ClientSequence and LastSeenServerSeq to Op struct and Push

- Add ClientSequence and LastSeenServerSeq fields to sync.Op struct
- Fix Client.Push() to copy these fields to PushOp
- Add GetDeviceID() method to sync.Service
This commit is contained in:
mirivlad 2026-06-02 08:02:03 +08:00
parent 87c8dfcbea
commit 3c7e9d1d56
3 changed files with 34 additions and 16 deletions

1
.gitignore vendored
View File

@ -25,6 +25,7 @@ frontend/bindings/
/verstak-gui /verstak-gui
/verstak-cli /verstak-cli
/verstak-server /verstak-server
/verstak
# Vault data # Vault data
.verstak/ .verstak/

View File

@ -130,6 +130,19 @@ func (c *Client) Login(username, password string) (token string, err error) {
return resp.Token, nil return resp.Token, nil
} }
// TestAuth checks credentials without creating a device.
func (c *Client) TestAuth(serverURL, username, password string) error {
body := map[string]string{"username": username, "password": password}
savedURL := c.ServerURL
savedKey := c.APIKey
c.ServerURL = serverURL
c.APIKey = ""
err := c.post("/api/auth/test", body, nil)
c.ServerURL = savedURL
c.APIKey = savedKey
return err
}
// PushRequest is the payload for POST /sync/push. // PushRequest is the payload for POST /sync/push.
type PushRequest struct { type PushRequest struct {
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
@ -166,6 +179,8 @@ func (c *Client) Push(ops []Op) (*PushResponse, error) {
EntityID: op.EntityID, EntityID: op.EntityID,
OpType: op.OpType, OpType: op.OpType,
PayloadJSON: op.PayloadJSON, PayloadJSON: op.PayloadJSON,
ClientSequence: op.ClientSequence,
LastSeenServerSeq: op.LastSeenServerSeq,
CreatedAt: op.CreatedAt, CreatedAt: op.CreatedAt,
} }
} }

View File

@ -40,6 +40,8 @@ type Op struct {
PayloadJSON string `json:"payload_json"` PayloadJSON string `json:"payload_json"`
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
PushedAt *string `json:"pushed_at,omitempty"` PushedAt *string `json:"pushed_at,omitempty"`
ClientSequence int `json:"client_sequence,omitempty"`
LastSeenServerSeq int `json:"last_seen_server_seq,omitempty"`
} }
// Service records and manages sync operations. // Service records and manages sync operations.