krisspy-sdk 0.1.0

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 ADDED
@@ -0,0 +1,243 @@
1
+ # @krisspy/sdk
2
+
3
+ Krisspy Cloud SDK - Database, Auth, and Functions for your apps.
4
+
5
+ A simpler alternative to Supabase.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @krisspy/sdk
11
+ # or
12
+ yarn add @krisspy/sdk
13
+ # or
14
+ pnpm add @krisspy/sdk
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```typescript
20
+ import { createClient } from '@krisspy/sdk'
21
+
22
+ const krisspy = createClient({
23
+ backendId: 'your-backend-id',
24
+ apiKey: 'your-api-key', // optional for public access
25
+ })
26
+ ```
27
+
28
+ ## Authentication
29
+
30
+ ### Sign Up
31
+
32
+ ```typescript
33
+ const { data, error } = await krisspy.auth.signUp({
34
+ email: 'user@example.com',
35
+ password: 'secret123',
36
+ metadata: { name: 'John Doe' }, // optional
37
+ })
38
+ ```
39
+
40
+ ### Sign In
41
+
42
+ ```typescript
43
+ const { data, error } = await krisspy.auth.signInWithPassword({
44
+ email: 'user@example.com',
45
+ password: 'secret123',
46
+ })
47
+ ```
48
+
49
+ ### Get Current User
50
+
51
+ ```typescript
52
+ const user = krisspy.auth.user()
53
+ // or async
54
+ const { data: { user } } = await krisspy.auth.getUser()
55
+ ```
56
+
57
+ ### Sign Out
58
+
59
+ ```typescript
60
+ await krisspy.auth.signOut()
61
+ ```
62
+
63
+ ### Listen to Auth Changes
64
+
65
+ ```typescript
66
+ const { unsubscribe } = krisspy.auth.onAuthStateChange((event) => {
67
+ console.log('Auth event:', event) // 'SIGNED_IN' | 'SIGNED_OUT'
68
+ })
69
+
70
+ // Later...
71
+ unsubscribe()
72
+ ```
73
+
74
+ ## Database
75
+
76
+ ### Select
77
+
78
+ ```typescript
79
+ // Select all
80
+ const { data, error } = await krisspy
81
+ .from('products')
82
+ .select('*')
83
+
84
+ // Select specific columns
85
+ const { data, error } = await krisspy
86
+ .from('products')
87
+ .select('id, name, price')
88
+
89
+ // With filters
90
+ const { data, error } = await krisspy
91
+ .from('products')
92
+ .select('*')
93
+ .eq('active', true)
94
+ .gt('price', 100)
95
+ .order('created_at', { ascending: false })
96
+ .limit(10)
97
+
98
+ // Get single row
99
+ const { data, error } = await krisspy
100
+ .from('products')
101
+ .select('*')
102
+ .eq('id', 123)
103
+ .single()
104
+ ```
105
+
106
+ ### Insert
107
+
108
+ ```typescript
109
+ // Single insert
110
+ const { data, error } = await krisspy
111
+ .from('products')
112
+ .insert({ name: 'iPhone', price: 999 })
113
+
114
+ // Batch insert
115
+ const { data, error } = await krisspy
116
+ .from('products')
117
+ .insert([
118
+ { name: 'iPhone', price: 999 },
119
+ { name: 'iPad', price: 799 },
120
+ ])
121
+ ```
122
+
123
+ ### Update
124
+
125
+ ```typescript
126
+ const { data, error } = await krisspy
127
+ .from('products')
128
+ .update({ price: 899 })
129
+ .eq('id', 123)
130
+ ```
131
+
132
+ ### Delete
133
+
134
+ ```typescript
135
+ const { data, error } = await krisspy
136
+ .from('products')
137
+ .delete()
138
+ .eq('id', 123)
139
+ ```
140
+
141
+ ### Filter Operators
142
+
143
+ | Method | SQL Equivalent |
144
+ |--------|----------------|
145
+ | `.eq(column, value)` | `= value` |
146
+ | `.neq(column, value)` | `!= value` |
147
+ | `.gt(column, value)` | `> value` |
148
+ | `.gte(column, value)` | `>= value` |
149
+ | `.lt(column, value)` | `< value` |
150
+ | `.lte(column, value)` | `<= value` |
151
+ | `.like(column, pattern)` | `LIKE pattern` |
152
+ | `.ilike(column, pattern)` | `ILIKE pattern` |
153
+ | `.in(column, values)` | `IN (values)` |
154
+ | `.is(column, value)` | `IS value` (null, true, false) |
155
+
156
+ ### Ordering & Pagination
157
+
158
+ ```typescript
159
+ const { data, error } = await krisspy
160
+ .from('products')
161
+ .select('*')
162
+ .order('price', { ascending: true })
163
+ .order('name', { ascending: true }) // Multiple orders
164
+ .limit(10)
165
+ .range(0, 9) // First 10 items (offset 0, limit 10)
166
+ ```
167
+
168
+ ## Functions
169
+
170
+ ```typescript
171
+ // Invoke a function
172
+ const { data, error } = await krisspy.functions.invoke('hello-world', {
173
+ body: { name: 'John' },
174
+ })
175
+
176
+ // List functions
177
+ const { data: functions } = await krisspy.functions.list()
178
+ ```
179
+
180
+ ## Tables
181
+
182
+ ```typescript
183
+ // List tables
184
+ const { data: tables } = await krisspy.listTables()
185
+
186
+ // Get table schema
187
+ const { data: columns } = await krisspy.getTableSchema('products')
188
+ ```
189
+
190
+ ## TypeScript
191
+
192
+ The SDK is fully typed. You can define your table types:
193
+
194
+ ```typescript
195
+ interface Product {
196
+ id: number
197
+ name: string
198
+ price: number
199
+ created_at: string
200
+ }
201
+
202
+ const { data, error } = await krisspy
203
+ .from<Product>('products')
204
+ .select('*')
205
+
206
+ // data is Product[] | null
207
+ ```
208
+
209
+ ## Error Handling
210
+
211
+ All methods return `{ data, error }`:
212
+
213
+ ```typescript
214
+ const { data, error } = await krisspy.from('products').select('*')
215
+
216
+ if (error) {
217
+ console.error('Error:', error.message)
218
+ return
219
+ }
220
+
221
+ console.log('Products:', data)
222
+ ```
223
+
224
+ ## Configuration
225
+
226
+ ```typescript
227
+ const krisspy = createClient({
228
+ // Required
229
+ backendId: 'your-backend-id',
230
+
231
+ // Optional
232
+ url: 'https://api.krisspy.ai', // Custom API URL
233
+ apiKey: 'your-api-key', // For authenticated requests
234
+ headers: { // Custom headers
235
+ 'X-Custom-Header': 'value'
236
+ },
237
+ debug: true, // Enable debug logging
238
+ })
239
+ ```
240
+
241
+ ## License
242
+
243
+ MIT