Skip to content

Commit f3f62ca

Browse files
committed
chore: build
1 parent 80847b2 commit f3f62ca

File tree

3 files changed

+93
-19
lines changed

3 files changed

+93
-19
lines changed

README.md

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,100 @@
1-
# bun starter
1+
# UndbSDK
22

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.
44

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
66

7-
OR
7+
Install UndbSDK using npm:
88

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+
```
1018

11-
## Setup
19+
## Usage
1220

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:
1651

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')
1957

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
2296
```
2397

24-
## License
98+
### License
2599

26-
MIT
100+
[MIT](./LICENSE)

src/services/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class AuthService {
1616
this.client = client
1717
}
1818

19-
async loginWithEmail(email: string, password: string): Promise<AuthResponse> {
19+
async loginWithEmailPassword(email: string, password: string): Promise<AuthResponse> {
2020
if (this.token) {
2121
throw new Error('Already authenticated with API token.')
2222
}

test/template.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { UndbSDK } from '../src/Sdk'
66
import type { components, paths } from './templates'
77

88
const SECRET = 'secret'
9-
const BASE_URL = 'http://localhost:3721/api'
9+
const BASE_URL = 'http://localhost:3721/openapi'
1010

1111
describe('template', () => {
1212
let sdk: UndbSDK
@@ -34,7 +34,7 @@ describe('template', () => {
3434
const request = mockFetch.mock.calls[0][0]
3535

3636
expect(request).toHaveProperty('url')
37-
expect(request.url).toBe('http://localhost:3721/api/bases/templates/tables/templates/records')
37+
expect(request.url).toBe('http://localhost:3721/openapi/bases/templates/tables/templates/records')
3838
expect(request).toHaveProperty('headers')
3939
expect(request.headers).toBeInstanceOf(Headers)
4040
expect((request.headers as Headers).get('x-undb-api-token')).toBe(SECRET)
@@ -47,7 +47,7 @@ describe('template', () => {
4747
})
4848

4949
const request = mockFetch.mock.calls[0][0]
50-
expect(request.url).toBe(`http://localhost:3721/api/bases/templates/tables/templates/records/${recordId}`)
50+
expect(request.url).toBe(`http://localhost:3721/openapi/bases/templates/tables/templates/records/${recordId}`)
5151
})
5252
})
5353

0 commit comments

Comments
 (0)