Offline Sync
The SDK sync module queues writes in IndexedDB when offline and replays them when connectivity returns. The API detects conflicts using the X-Sync-Version header (the client sends the last known updatedAt timestamp).
const db = createClient({
apiKey: process.env.PAPERDB_API_KEY!,
sync: {
collections: ["todos"],
conflictResolution: "last-write-wins",
syncInterval: 30000,
},
});
await db.sync.init();
// Queue offline change
await db.sync.queueChange({
collection: "todos",
operation: "insert",
data: { title: "Buy milk" },
});
// Manual sync
const { synced, conflicts } = await db.sync.force();Conflict handling
When a remote document was updated after the client's version, the API returns 409 Conflict with a remote payload. The SDK applies your chosen strategy (last-write-wins, first-write-wins, merge, or manual).
Offline sync requires a browser environment with IndexedDB. Use a secret API key for write operations queued from sync.