@neondatabase/neon-js 0.1.0-beta.14 → 0.1.0-beta.15
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 +0 -25
- package/dist/package.json +3 -4
- package/llms-full.txt +1181 -0
- package/llms.txt +264 -0
- package/package.json +3 -4
package/llms.txt
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# @neondatabase/neon-js
|
|
2
|
+
|
|
3
|
+
> The official TypeScript SDK for Neon - unified client combining authentication and PostgreSQL database querying with automatic token management.
|
|
4
|
+
|
|
5
|
+
`@neondatabase/neon-js` brings together Neon Auth and Neon Data API in a single client. It provides a familiar interface for authentication and type-safe database queries with PostgREST.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @neondatabase/neon-js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createClient } from '@neondatabase/neon-js';
|
|
17
|
+
|
|
18
|
+
const client = createClient<Database>({
|
|
19
|
+
auth: {
|
|
20
|
+
url: import.meta.env.VITE_NEON_AUTH_URL,
|
|
21
|
+
},
|
|
22
|
+
dataApi: {
|
|
23
|
+
url: import.meta.env.VITE_NEON_DATA_API_URL,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Authenticate
|
|
28
|
+
await client.auth.signIn.email({
|
|
29
|
+
email: 'user@example.com',
|
|
30
|
+
password: 'secure-password',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Query database (token automatically injected)
|
|
34
|
+
const { data: users } = await client
|
|
35
|
+
.from('users')
|
|
36
|
+
.select('*')
|
|
37
|
+
.eq('status', 'active');
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Authentication
|
|
41
|
+
|
|
42
|
+
### Sign Up & Sign In
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// Sign up
|
|
46
|
+
await client.auth.signUp.email({
|
|
47
|
+
email: 'user@example.com',
|
|
48
|
+
password: 'secure-password',
|
|
49
|
+
name: 'John Doe',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Sign in with email
|
|
53
|
+
await client.auth.signIn.email({
|
|
54
|
+
email: 'user@example.com',
|
|
55
|
+
password: 'secure-password',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Sign in with OAuth
|
|
59
|
+
await client.auth.signIn.social({
|
|
60
|
+
provider: 'google',
|
|
61
|
+
callbackURL: '/dashboard',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Get session
|
|
65
|
+
const session = await client.auth.getSession();
|
|
66
|
+
|
|
67
|
+
// Sign out
|
|
68
|
+
await client.auth.signOut();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Adapters
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// SupabaseAuthAdapter - Supabase-compatible API
|
|
75
|
+
import { createClient, SupabaseAuthAdapter } from '@neondatabase/neon-js';
|
|
76
|
+
|
|
77
|
+
const client = createClient<Database>({
|
|
78
|
+
auth: {
|
|
79
|
+
adapter: SupabaseAuthAdapter(),
|
|
80
|
+
url: import.meta.env.VITE_NEON_AUTH_URL,
|
|
81
|
+
},
|
|
82
|
+
dataApi: {
|
|
83
|
+
url: import.meta.env.VITE_NEON_DATA_API_URL,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await client.auth.signInWithPassword({ email, password });
|
|
88
|
+
const { data: session } = await client.auth.getSession();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// BetterAuthReactAdapter - React hooks
|
|
93
|
+
import { createClient } from '@neondatabase/neon-js';
|
|
94
|
+
import { BetterAuthReactAdapter } from '@neondatabase/neon-js/auth/react/adapters';
|
|
95
|
+
|
|
96
|
+
const client = createClient<Database>({
|
|
97
|
+
auth: {
|
|
98
|
+
adapter: BetterAuthReactAdapter(),
|
|
99
|
+
url: import.meta.env.VITE_NEON_AUTH_URL,
|
|
100
|
+
},
|
|
101
|
+
dataApi: {
|
|
102
|
+
url: import.meta.env.VITE_NEON_DATA_API_URL,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
function MyComponent() {
|
|
107
|
+
const session = client.auth.useSession();
|
|
108
|
+
if (session.isPending) return <div>Loading...</div>;
|
|
109
|
+
return <div>Hello, {session.data?.user.name}</div>;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Anonymous Access
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const client = createClient<Database>({
|
|
117
|
+
auth: {
|
|
118
|
+
url: import.meta.env.VITE_NEON_AUTH_URL,
|
|
119
|
+
allowAnonymous: true, // Enable anonymous data access via RLS
|
|
120
|
+
},
|
|
121
|
+
dataApi: {
|
|
122
|
+
url: import.meta.env.VITE_NEON_DATA_API_URL,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Works without signing in - uses anonymous token for RLS
|
|
127
|
+
const { data: publicItems } = await client.from('public_items').select();
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Database Querying
|
|
131
|
+
|
|
132
|
+
### SELECT
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Simple select
|
|
136
|
+
const { data } = await client.from('users').select('id, name, email');
|
|
137
|
+
|
|
138
|
+
// With filters
|
|
139
|
+
const { data } = await client
|
|
140
|
+
.from('posts')
|
|
141
|
+
.select('*')
|
|
142
|
+
.eq('status', 'published')
|
|
143
|
+
.gt('views', 100)
|
|
144
|
+
.order('created_at', { ascending: false })
|
|
145
|
+
.limit(10);
|
|
146
|
+
|
|
147
|
+
// Joins
|
|
148
|
+
const { data } = await client
|
|
149
|
+
.from('posts')
|
|
150
|
+
.select(`
|
|
151
|
+
id,
|
|
152
|
+
title,
|
|
153
|
+
author:users(name, email)
|
|
154
|
+
`)
|
|
155
|
+
.eq('status', 'published');
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### INSERT
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// Single row
|
|
162
|
+
const { data } = await client
|
|
163
|
+
.from('users')
|
|
164
|
+
.insert({ name: 'Alice', email: 'alice@example.com' })
|
|
165
|
+
.select();
|
|
166
|
+
|
|
167
|
+
// Multiple rows
|
|
168
|
+
const { data } = await client
|
|
169
|
+
.from('users')
|
|
170
|
+
.insert([
|
|
171
|
+
{ name: 'Bob', email: 'bob@example.com' },
|
|
172
|
+
{ name: 'Carol', email: 'carol@example.com' },
|
|
173
|
+
])
|
|
174
|
+
.select();
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### UPDATE
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const { data } = await client
|
|
181
|
+
.from('users')
|
|
182
|
+
.update({ status: 'inactive' })
|
|
183
|
+
.eq('last_login', null)
|
|
184
|
+
.select();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### DELETE
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
const { data } = await client
|
|
191
|
+
.from('users')
|
|
192
|
+
.delete()
|
|
193
|
+
.eq('status', 'deleted')
|
|
194
|
+
.select();
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### RPC (Stored Procedures)
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const { data } = await client.rpc('get_user_stats', {
|
|
201
|
+
user_id: 123,
|
|
202
|
+
start_date: '2024-01-01',
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## TypeScript
|
|
207
|
+
|
|
208
|
+
Generate types from your database schema:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
npx neon-js gen-types --db-url "postgresql://user:pass@host/db"
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Use generated types:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import type { Database } from './types/database';
|
|
218
|
+
|
|
219
|
+
const client = createClient<Database>({
|
|
220
|
+
auth: { url: process.env.NEON_AUTH_URL! },
|
|
221
|
+
dataApi: { url: process.env.NEON_DATA_API_URL! },
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// Fully typed queries with autocomplete
|
|
225
|
+
const { data } = await client
|
|
226
|
+
.from('users')
|
|
227
|
+
.select('id, name, email')
|
|
228
|
+
.eq('status', 'active');
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Configuration
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
const client = createClient({
|
|
235
|
+
auth: {
|
|
236
|
+
url: 'https://your-auth-server.neon.tech/auth',
|
|
237
|
+
allowAnonymous: true,
|
|
238
|
+
},
|
|
239
|
+
dataApi: {
|
|
240
|
+
url: 'https://your-data-api.neon.tech/rest/v1',
|
|
241
|
+
options: {
|
|
242
|
+
db: { schema: 'public' },
|
|
243
|
+
global: { headers: { 'X-Custom-Header': 'value' } },
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## CSS for UI Components
|
|
250
|
+
|
|
251
|
+
```css
|
|
252
|
+
/* Without Tailwind */
|
|
253
|
+
@import '@neondatabase/neon-js/ui/css';
|
|
254
|
+
|
|
255
|
+
/* With Tailwind CSS v4 */
|
|
256
|
+
@import 'tailwindcss';
|
|
257
|
+
@import '@neondatabase/neon-js/ui/tailwind';
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Optional
|
|
261
|
+
|
|
262
|
+
- [CLI Tool](https://github.com/neondatabase/neon-js/tree/main/packages/neon-js#cli-tool): Generate TypeScript types from database
|
|
263
|
+
- [PostgREST Documentation](https://postgrest.org): Query syntax reference
|
|
264
|
+
- [Better Auth Documentation](https://www.better-auth.com/docs): Authentication library docs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neondatabase/neon-js",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.15",
|
|
4
4
|
"description": "TypeScript SDK for Neon Auth and Data API - authentication and PostgreSQL querying",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -93,9 +93,8 @@
|
|
|
93
93
|
},
|
|
94
94
|
"files": [
|
|
95
95
|
"dist",
|
|
96
|
-
"llms-full.txt",
|
|
97
96
|
"llms.txt",
|
|
98
|
-
"llms-
|
|
97
|
+
"llms-full.txt"
|
|
99
98
|
],
|
|
100
99
|
"publishConfig": {
|
|
101
100
|
"access": "public"
|
|
@@ -117,7 +116,7 @@
|
|
|
117
116
|
},
|
|
118
117
|
"dependencies": {
|
|
119
118
|
"@neondatabase/postgrest-js": "0.1.0-alpha.1",
|
|
120
|
-
"@neondatabase/auth": "0.1.0-beta.
|
|
119
|
+
"@neondatabase/auth": "0.1.0-beta.15",
|
|
121
120
|
"@supabase/postgres-meta": "0.93.1",
|
|
122
121
|
"meow": "14.0.0",
|
|
123
122
|
"zod": "4.1.12"
|