@idnbase/js 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# `@idnbase/js`
|
|
2
|
+
|
|
3
|
+
Official TypeScript / JavaScript client SDK for **IDNBase** — supporting End-User Auth (v1/v2), Auto-REST CRUD, `pgvector` Cosine Similarity Search, RPC, GraphQL, Realtime SSE, and Storage.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @idnbase/js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createClient } from '@idnbase/js';
|
|
15
|
+
|
|
16
|
+
export const idnbase = createClient('https://your-idnbase-domain.com', {
|
|
17
|
+
slug: 'your-project-slug',
|
|
18
|
+
projectId: 'your-project-uuid', // optional, required for graphql.query()
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Authentication (End-User Auth v1/v2)
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// Register & sign in (JWT access & refresh tokens are stored automatically)
|
|
26
|
+
await idnbase.auth.signUp({
|
|
27
|
+
email: 'user@example.com',
|
|
28
|
+
password: 'Password1234!',
|
|
29
|
+
displayName: 'Budi',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
await idnbase.auth.signIn({
|
|
33
|
+
email: 'user@example.com',
|
|
34
|
+
password: 'Password1234!',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Refresh session token
|
|
38
|
+
await idnbase.auth.refreshSession();
|
|
39
|
+
|
|
40
|
+
// OAuth2 URL (Google / GitHub)
|
|
41
|
+
const oauthUrl = idnbase.auth.getOAuthUrl('google', 'https://your-app.com/callback');
|
|
42
|
+
|
|
43
|
+
// Sign out
|
|
44
|
+
idnbase.auth.signOut();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Auto-REST CRUD & `pgvector` Similarity Search
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// Select rows
|
|
51
|
+
const { data, error } = await idnbase.from('posts').select({
|
|
52
|
+
order: 'created_at.desc',
|
|
53
|
+
limit: 20,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Insert row
|
|
57
|
+
await idnbase.from('posts').insert({
|
|
58
|
+
title: 'Hello IDNBase',
|
|
59
|
+
published: true,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Update & Delete
|
|
63
|
+
await idnbase.from('posts').update({ published: false }, { id: 'row-uuid' });
|
|
64
|
+
await idnbase.from('posts').delete({ id: 'row-uuid' });
|
|
65
|
+
|
|
66
|
+
// AI / RAG Cosine Similarity Search (pgvector)
|
|
67
|
+
const { data: matches } = await idnbase.from('documents').vectorSearch({
|
|
68
|
+
column: 'embedding',
|
|
69
|
+
vector: [0.12, 0.34, 0.56],
|
|
70
|
+
limit: 5,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// PostgreSQL RPC Function
|
|
74
|
+
const { data: rpcResult } = await idnbase.rpc('calculate_summary', { year: 2026 });
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## GraphQL & Realtime SSE
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
// GraphQL query
|
|
81
|
+
const { data: gqlData } = await idnbase.graphql.query(`
|
|
82
|
+
query {
|
|
83
|
+
__schema { queryType { name } }
|
|
84
|
+
}
|
|
85
|
+
`);
|
|
86
|
+
|
|
87
|
+
// Realtime SSE subscription
|
|
88
|
+
const { unsubscribe } = idnbase.realtime.subscribe((event) => {
|
|
89
|
+
console.log('Realtime event:', event);
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Storage (Presigned Upload & Download)
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
const { data: signed } = await idnbase.storage.createSignedUploadUrl('avatars', 'user-1.png');
|
|
97
|
+
if (signed) {
|
|
98
|
+
await idnbase.storage.uploadToSignedUrl(signed.uploadUrl, fileBlob, 'image/png');
|
|
99
|
+
}
|
|
100
|
+
```
|
package/package.json
CHANGED