@glean-oak/sync-client-types
v0.2.3
Published
TypeScript types for glean-oak-sync-client - generated from Rust with Specta
Maintainers
Readme
@glean-oak/sync-client-types
TypeScript types and browser/Node.js client for glean-oak-sync-client - types generated from Rust with Specta.
Installation
npm install @glean-oak/sync-client-typesUsage
Config helper
import { createSyncClientConfig, GleanOakClient } from '@glean-oak/sync-client-types';
const config = createSyncClientConfig(
'https://sync.example.com',
'my-app-id',
'my-api-key',
{
defaultBatchSize: 100,
timeoutMs: 30000,
apiBasePath: '/api/v1', // optional, default is "/api/v1"
}
);
const client = new GleanOakClient(config);Authentication
await client.login('[email protected]', 'password');
// Restore from stored tokens
client.setTokens(accessToken, refreshToken, userId);
// Persist tokens
const { accessToken, refreshToken } = client.getTokens();Sync operations
// Push local changes
const pushResult = await client.push(records);
// Pull remote changes
const pullResult = await client.pull(checkpoint, batchSize);
// Delta sync (push + pull in one request)
const deltaResult = await client.delta(records, checkpoint);Custom HTTP transport
import { GleanOakClient, type HttpClientFn } from '@glean-oak/sync-client-types';
const myHttpClient: HttpClientFn = async (request) => {
// custom fetch logic
};
const client = new GleanOakClient(config, myHttpClient);SyncClientConfig
| Field | Type | Default | Description |
|-------|------|---------|-------------|
| serverUrl | string | — | Base URL of the sync server |
| appId | string | — | Application ID |
| apiKey | string | — | API key for the application |
| defaultBatchSize | number | 100 | Default pull batch size |
| timeoutMs | number | 30000 | Request timeout in ms |
| apiBasePath | string | "/api/v1" | Prefix for all API endpoints |
Regenerating Types
Types are generated from Rust using Specta. To regenerate after modifying Rust structs:
cargo run -p glean-oak-sync-client --bin export_typesThen update src/index.ts with the generated types.
Local Development
npm install
npm run build
npm link
# In your project
npm link @glean-oak/sync-client-typesPublishing
npm run build
npm publish --access public
npm view @glean-oak/sync-client-types