Skip to content

@offlinesync/transport-http

HTTP transport using the global fetch API. Works in Node.js, Bun, Deno, Cloudflare Workers, and browsers.

HttpSyncTransport

typescript
import { HttpSyncTransport } from '@offlinesync/transport-http'

const transport = new HttpSyncTransport({
  syncEndpoint: 'https://api.example.com/sync',
  snapshotEndpoint: 'https://api.example.com/snapshot',
  clientId: 'client-abc',
  headers: { Authorization: 'Bearer token' },
})

Options

OptionTypeDescription
syncEndpointstringURL for incremental sync
snapshotEndpoint?stringURL for snapshot sync
clientIdstringClient identifier sent with each request
headers?Record<string, string>Custom headers (e.g., auth)
fetchFn?typeof fetchCustom fetch implementation

SyncTransportError

typescript
import { SyncTransportError } from '@offlinesync/transport-http'

try {
  await transport.sendSync(request)
} catch (e) {
  if (e instanceof SyncTransportError) {
    console.log(e.code)  // Protocol error code
  }
}
PropertyTypeDescription
codestringMapped protocol error code
cause?ErrorOriginal error

Released under the MIT License.