Skip to content

Commit fe53d4e

Browse files
committed
docs: updated sdk readme as of v0.2.0
1 parent fcfff05 commit fe53d4e

1 file changed

Lines changed: 67 additions & 44 deletions

File tree

‎sdks/urbackend-sdk/README.md‎

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# urbackend-sdk
22

3-
Official TypeScript SDK for [urBackend](https://urbackend.bitbros.in) — the instant Backend-as-a-Service for frontend developers.
3+
Official TypeScript SDK for [urBackend](https://urbackend.bitbros.in) — the instant Backend-as-a-Service for MongoDB.
44

55
## Installation
6+
```bash
67
npm install @urbackend/sdk
8+
```
79

810
## Quick Start
911
```javascript
@@ -12,49 +14,80 @@ import urBackend from '@urbackend/sdk';
1214
const client = urBackend({ apiKey: 'YOUR_API_KEY' });
1315

1416
// Auth
15-
await client.auth.signUp({ email, password, name });
16-
await client.auth.login({ email, password });
17-
await client.auth.me();
17+
const { accessToken } = await client.auth.login({ email, password });
18+
const user = await client.auth.me();
1819

19-
// Database — collections are auto-created on first insert
20-
await client.db.insert('products', { name: 'Chair', price: 99 });
21-
await client.db.getAll('products');
22-
await client.db.getOne('products', id);
23-
await client.db.update('products', id, { price: 79 });
24-
await client.db.delete('products', id);
20+
// Database — collections are managed via the urBackend Dashboard
21+
await client.db.insert('posts', { title: 'Hello World' }, client.auth.getToken());
22+
await client.db.getAll('posts', { sort: 'createdAt:desc', limit: 10 });
2523

2624
// Storage
27-
await client.storage.upload(file);
28-
await client.storage.deleteFile(path);
25+
const { url } = await client.storage.upload(file);
26+
27+
// Mail (Requires Secret Key)
28+
await client.mail.send({
29+
to: 'user@example.com',
30+
subject: 'Welcome!',
31+
text: 'Glad to have you.'
32+
});
2933
```
3034

3135
## API Reference
3236

33-
### Client initialization
37+
### Client Initialization
3438
`urBackend({ apiKey: string, baseUrl?: string })`
3539

36-
### Auth
40+
---
41+
42+
### Auth (`client.auth`)
3743
| Method | Params | Returns |
3844
|--------|--------|---------|
39-
| signUp | { email, password, name? } | AuthUser |
40-
| login | { email, password } | { token, user } |
41-
| me | token? | AuthUser |
42-
| logout | — | void |
45+
| `signUp` | `{ email, password, username?, name?, ... }` | `AuthUser` |
46+
| `login` | `{ email, password }` | `AuthResponse` |
47+
| `me` | `token?` | `AuthUser` |
48+
| `logout` | `token?` | `{ success: boolean }` |
49+
| `refreshToken` | `refreshToken?` | `AuthResponse` |
50+
| `updateProfile`| `payload, token?` | `{ message: string }` |
51+
| `changePassword`| `payload, token?` | `{ message: string }` |
52+
| `verifyEmail` | `{ email, otp }` | `{ message: string }` |
53+
| `publicProfile`| `username` | `AuthUser` |
54+
| `socialStart` | `provider ('github'\|'google')` | `string` (Redirect URL) |
55+
| `socialExchange`| `{ token, rtCode }` | `SocialExchangeResponse` |
56+
57+
---
58+
59+
### Database (`client.db`)
60+
Support for **Row-Level Security (RLS)** is built-in. Pass the user's `accessToken` as the final parameter to write routes if RLS is enabled for the collection.
4361

44-
### Database
4562
| Method | Params | Returns |
4663
|--------|--------|---------|
47-
| getAll<T> | collection | T[] |
48-
| getOne<T> | collection, id | T |
49-
| insert<T> | collection, data | T |
50-
| update<T> | collection, id, data | T |
51-
| delete | collection, id | { deleted: boolean } |
52-
53-
### Storage
64+
| `getAll<T>` | `collection, params?` | `T[]` |
65+
| `getOne<T>` | `collection, id, options?` | `T` |
66+
| `insert<T>` | `collection, data, token?` | `T` |
67+
| `update<T>` | `collection, id, data, token?` | `T` (Full Replace) |
68+
| `patch<T>` | `collection, id, data, token?` | `T` (Partial Update) |
69+
| `delete` | `collection, id, token?` | `{ deleted: boolean }` |
70+
71+
**Query Parameters (`params`):**
72+
- `filter`: `{ price_gt: 100 }`
73+
- `sort`: `"createdAt:desc"`
74+
- `limit`: `50`
75+
- `page`: `1`
76+
- `populate`: `"author"` (Expand Reference fields)
77+
78+
---
79+
80+
### Storage (`client.storage`)
5481
| Method | Params | Returns |
5582
|--------|--------|---------|
56-
| upload | file, filename? | { url, path } |
57-
| deleteFile | path | { deleted: boolean } |
83+
| `upload` | `file (Buffer\|Blob), filename?` | `{ url, path, provider }` |
84+
| `deleteFile` | `path` | `{ deleted: boolean }` |
85+
86+
---
87+
88+
### New Modules
89+
- **`client.schema`**: Use `getSchema(collection)` to fetch visual field definitions.
90+
- **`client.mail`**: Use `send(payload)` to send emails via Resend (Requires Secret Key).
5891

5992
## Error Handling
6093
```javascript
@@ -63,23 +96,13 @@ import { AuthError, NotFoundError, RateLimitError } from '@urbackend/sdk';
6396
try {
6497
await client.db.getOne('products', id);
6598
} catch (e) {
66-
if (e instanceof NotFoundError) console.log('Not found');
67-
if (e instanceof RateLimitError) console.log('Slow down');
99+
if (e instanceof AuthError) console.error('Invalid token or insufficient RLS permissions');
100+
if (e instanceof NotFoundError) console.error('Resource not found');
101+
if (e instanceof RateLimitError) console.error('Too many requests');
68102
}
69103
```
70104

71-
## TypeScript Support
72-
```typescript
73-
interface Product { _id: string; name: string; price: number; }
74-
const products = await client.db.getAll<Product>('products');
75-
```
76-
77-
## Limits
78-
- Rate limit: 100 requests / 15 mins per IP
79-
- Database: 50 MB per project
80-
- Storage: 100 MB per project
81-
- File upload: 5 MB per file
82-
83105
## Security
84-
⚠️ Never expose your API key in client-side/browser code.
85-
Use environment variables: `process.env.URBACKEND_API_KEY`
106+
- **Never expose your Secret Key (`sk_live_...`)** in frontend/browser code.
107+
- Use **Publishable Keys (`pk_live_...`)** for client-side applications.
108+
- Enable **RLS** in the urBackend Dashboard to allow secure writes from the frontend using the user's access token.

0 commit comments

Comments
 (0)