|
1 | | -# bun starter |
| 1 | +# UndbSDK |
2 | 2 |
|
3 | | -## Getting Started |
| 3 | +UndbSDK is a TypeScript SDK for interacting with the Undb API. It provides authentication services, base services, and an OpenAPI client. |
4 | 4 |
|
5 | | -Click the [Use this template](https://github.com/wobsoriano/bun-lib-starter/generate) button to create a new repository with the contents starter. |
| 5 | +## Installation |
6 | 6 |
|
7 | | -OR |
| 7 | +Install UndbSDK using npm: |
8 | 8 |
|
9 | | -Run `bun create wobsoriano/bun-lib-starter ./my-lib`. |
| 9 | +```bash |
| 10 | +npm install @undb/js-sdk |
| 11 | +# or |
| 12 | +yarn add @undb/js-sdk |
| 13 | +# or |
| 14 | +pnpm add @undb/js-sdk |
| 15 | +# or |
| 16 | +bun add @undb/js-sdk |
| 17 | +``` |
10 | 18 |
|
11 | | -## Setup |
| 19 | +## Usage |
12 | 20 |
|
13 | | -```bash |
14 | | -# install dependencies |
15 | | -bun install |
| 21 | +Import and use UndbSDK in your project: |
| 22 | + |
| 23 | +```typescript |
| 24 | +import { UndbSDK } from '@undb/js-sdk' |
| 25 | + |
| 26 | +const sdk = new UndbSDK({ |
| 27 | + baseURL: 'http://localhost:3721/openapi', // https://app.undb.io/openapi if you are using the hosted version |
| 28 | + fetch: fetch, // Optional, use a custom fetch function |
| 29 | +}) |
| 30 | + |
| 31 | +sdk.auth.setToken('secret') |
| 32 | + |
| 33 | +const client = sdk.getOpenapiClient<paths>() |
| 34 | + |
| 35 | +const res = await client.GET('/bases/templates/tables/templates/records') |
| 36 | +``` |
| 37 | + |
| 38 | +### Authentication |
| 39 | + |
| 40 | +Access the authentication service using the `auth` property: |
| 41 | + |
| 42 | +#### Set token |
| 43 | + |
| 44 | +```typescript |
| 45 | +sdk.auth.setToken('secret') |
| 46 | +``` |
| 47 | + |
| 48 | +### Usage with Base & Table names |
| 49 | + |
| 50 | +Get a `BaseService` instance using the `base` method: |
16 | 51 |
|
17 | | -# test the app |
18 | | -bun test |
| 52 | +```typescript |
| 53 | +const baseName = 'your-base-name' |
| 54 | +const baseService = sdk.base(baseName) |
| 55 | +// Access a specific table |
| 56 | +const tableService = baseService.table('your-table-name') |
19 | 57 |
|
20 | | -# build the app, available under dist |
21 | | -bun run build |
| 58 | +// Get records |
| 59 | +const records = await tableService.getRecords() |
| 60 | +// Create a record |
| 61 | +const newRecord = await tableService.createRecord({ values: { / your field values / } }) |
| 62 | +// Update a record |
| 63 | +const updatedRecord = await tableService.updateRecord('record-id', { values: { / updated field values / } }) |
| 64 | +// Delete a record |
| 65 | +await tableService.deleteRecord('record-id') |
| 66 | +``` |
| 67 | + |
| 68 | +#### Access a specific view |
| 69 | + |
| 70 | +```typescript |
| 71 | +const viewService = baseService.table('your-table-name', 'your-view-name') |
| 72 | + |
| 73 | +// Get records |
| 74 | +const records = await viewService.getRecords() |
| 75 | +``` |
| 76 | + |
| 77 | +### Usage with OpenAPI Client |
| 78 | + |
| 79 | +Get a `OpenApiClient` instance using the `getOpenapiClient` method: |
| 80 | + |
| 81 | +```typescript |
| 82 | +const client = sdk.getOpenapiClient<paths>() |
| 83 | + |
| 84 | +const res = await client.GET('/bases/templates/tables/templates/records') |
| 85 | +``` |
| 86 | + |
| 87 | +#### Generate OpenAPI types from undb |
| 88 | + |
| 89 | +TODO |
| 90 | + |
| 91 | +### Development |
| 92 | + |
| 93 | +```bash |
| 94 | +bun install |
| 95 | +bun run test:watch |
22 | 96 | ``` |
23 | 97 |
|
24 | | -## License |
| 98 | +### License |
25 | 99 |
|
26 | | -MIT |
| 100 | +[MIT](./LICENSE) |
0 commit comments