@neondatabase/neon-js 0.1.0-beta.2 → 0.1.0-beta.21

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/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 @neondatabase/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.2",
3
+ "version": "0.1.0-beta.21",
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",
@@ -18,13 +18,13 @@
18
18
  "supabase",
19
19
  "data-api"
20
20
  ],
21
- "homepage": "https://github.com/neondatabase-labs/neon-js/tree/main/packages/neon-js#readme",
21
+ "homepage": "https://github.com/neondatabase/neon-js/tree/main/packages/neon-js#readme",
22
22
  "bugs": {
23
- "url": "https://github.com/neondatabase-labs/neon-js/issues"
23
+ "url": "https://github.com/neondatabase/neon-js/issues"
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "git+https://github.com/neondatabase-labs/neon-js.git",
27
+ "url": "git+https://github.com/neondatabase/neon-js.git",
28
28
  "directory": "packages/neon-js"
29
29
  },
30
30
  "funding": {
@@ -51,6 +51,10 @@
51
51
  "types": "./dist/auth/index.d.mts",
52
52
  "default": "./dist/auth/index.mjs"
53
53
  },
54
+ "./auth/types": {
55
+ "types": "./dist/auth/types/index.d.mts",
56
+ "default": "./dist/auth/types/index.mjs"
57
+ },
54
58
  "./auth/react": {
55
59
  "types": "./dist/auth/react/index.d.mts",
56
60
  "default": "./dist/auth/react/index.mjs"
@@ -79,6 +83,10 @@
79
83
  "types": "./dist/auth/next/index.d.mts",
80
84
  "default": "./dist/auth/next/index.mjs"
81
85
  },
86
+ "./auth/next/server": {
87
+ "types": "./dist/auth/next/server/index.d.mts",
88
+ "default": "./dist/auth/next/server/index.mjs"
89
+ },
82
90
  "./ui/css": {
83
91
  "types": "./dist/ui/css.d.ts",
84
92
  "default": "./dist/ui/css.css"
@@ -88,7 +96,8 @@
88
96
  }
89
97
  },
90
98
  "files": [
91
- "dist"
99
+ "dist",
100
+ "llms.txt"
92
101
  ],
93
102
  "publishConfig": {
94
103
  "access": "public"
@@ -109,8 +118,8 @@
109
118
  "msw": "2.6.8"
110
119
  },
111
120
  "dependencies": {
112
- "@neondatabase/postgrest-js": "0.1.0-alpha.1",
113
- "@neondatabase/auth": "0.1.0-beta.2",
121
+ "@neondatabase/auth": "0.1.0-beta.20",
122
+ "@neondatabase/postgrest-js": "0.1.0-alpha.2",
114
123
  "@supabase/postgres-meta": "0.93.1",
115
124
  "meow": "14.0.0",
116
125
  "zod": "4.1.12"