UndbSDK is a TypeScript SDK for interacting with the Undb API. It provides authentication services, base services, and an OpenAPI client.
Install UndbSDK using npm:
npm install @undb/js-sdk
# or
yarn add @undb/js-sdk
# or
pnpm add @undb/js-sdk
# or
bun add @undb/js-sdk
Import and use UndbSDK in your project:
import { UndbSDK } from '@undb/js-sdk'
const sdk = new UndbSDK({
baseURL: 'http://localhost:3721/openapi', // https://app.undb.io/openapi if you are using the hosted version
fetch: fetch, // Optional, use a custom fetch function
})
sdk.auth.setToken('secret')
const client = sdk.getOpenapiClient<paths>()
const res = await client.GET('/bases/templates/tables/templates/records')
Access the authentication service using the auth
property:
sdk.auth.setToken('secret')
Get a BaseService
instance using the base
method:
const baseName = 'your-base-name'
const baseService = sdk.base(baseName)
// Access a specific table
const tableService = baseService.table('your-table-name')
// Get records
const records = await tableService.getRecords()
// Create a record
const newRecord = await tableService.createRecord({ values: { / your field values / } })
// Update a record
const updatedRecord = await tableService.updateRecord('record-id', { values: { / updated field values / } })
// Delete a record
await tableService.deleteRecord('record-id')
const viewService = baseService.table('your-table-name', 'your-view-name')
// Get records
const records = await viewService.getRecords()
Get a OpenApiClient
instance using the getOpenapiClient
method:
const client = sdk.getOpenapiClient<paths>()
const res = await client.GET('/bases/templates/tables/templates/records')
TODO
bun install
bun run test:watch