@tuzzle/client
Typed API client for uploading and managing assets, generated from the OpenAPI spec.
@tuzzle/client is a typed client for the management and upload API. Its types are generated from the API's OpenAPI 3.1 spec, and it wraps openapi-fetch with authentication, one-shot token refresh, and convenience helpers.
npm install @tuzzle/client
Create a client
Authenticate with a space-scoped API key, or with OAuth access/refresh tokens.
import { createTuzzleClient } from '@tuzzle/client'
// With an API key (server-side)
const client = createTuzzleClient({
baseUrl: 'https://api.tzzl.io',
apiKey: 'sk_a1b2c3d4...',
})
// With OAuth tokens (auto-refreshes on 401)
const client = createTuzzleClient({
baseUrl: 'https://api.tzzl.io',
accessToken: '...',
refreshToken: '...',
onTokensRefreshed: tokens => storage.set(tokens),
})
| Option | Type | Notes |
|---|---|---|
baseUrl | string | e.g. https://api.tzzl.io |
apiKey | string | Space-scoped key; no refresh flow |
accessToken / refreshToken | string | OAuth tokens; the client refreshes once on 401 |
onTokensRefreshed | (tokens) => void | Persist rotated tokens |
fetch | typeof fetch | Custom fetch implementation |
timeoutMs, retry, throwOnError | Request behaviour |
Upload a file
upload() handles the multipart request and reports progress.
const result = await client.upload(file, {
space: 'a1b2c3',
uploadConfig: 'config-id', // optional
onProgress: pct => setProgress(pct),
})
Manage resources
The client exposes typed resource helpers; each returns { data, error }.
// List files in a space
const { data } = await client.files.list({ params: { query: { space_id: 'a1b2c3' } } })
// Get / update / delete by id
const { data: file } = await client.files.get('01HQ...')
await client.files.delete('01HQ...')
// Cursor pagination
const all = []
for await (const file of client.files.paginate({ space_id: 'a1b2c3' })) {
all.push(file)
}
The same shape is available for folders, spaces, collections, uploadConfigs, webhooks, members, invitations, apiKeys, sessions, and analytics. For the full set of endpoints and payloads, see the API Reference.
Types are regenerated from the live spec with bun run gen. When the API changes, the client's types update with it.