krisspy-sdk
v0.4.0
Published
Krisspy Cloud SDK - Database, Auth, Storage, and Functions for your apps
Maintainers
Readme
@krisspy/sdk
Krisspy Cloud SDK - Database, Auth, and Functions for your apps.
A simpler alternative to Supabase.
Installation
npm install @krisspy/sdk
# or
yarn add @krisspy/sdk
# or
pnpm add @krisspy/sdkQuick Start
import { createClient } from '@krisspy/sdk'
const krisspy = createClient({
backendId: 'your-backend-id',
apiKey: 'your-api-key', // optional for public access
})Authentication
Sign Up
const { data, error } = await krisspy.auth.signUp({
email: '[email protected]',
password: 'secret123',
metadata: { name: 'John Doe' }, // optional
})Sign In
const { data, error } = await krisspy.auth.signInWithPassword({
email: '[email protected]',
password: 'secret123',
})Get Current User
const user = krisspy.auth.user()
// or async
const { data: { user } } = await krisspy.auth.getUser()Sign Out
await krisspy.auth.signOut()Listen to Auth Changes
const { unsubscribe } = krisspy.auth.onAuthStateChange((event) => {
console.log('Auth event:', event) // 'SIGNED_IN' | 'SIGNED_OUT'
})
// Later...
unsubscribe()Database
Select
// Select all
const { data, error } = await krisspy
.from('products')
.select('*')
// Select specific columns
const { data, error } = await krisspy
.from('products')
.select('id, name, price')
// With filters
const { data, error } = await krisspy
.from('products')
.select('*')
.eq('active', true)
.gt('price', 100)
.order('created_at', { ascending: false })
.limit(10)
// Get single row
const { data, error } = await krisspy
.from('products')
.select('*')
.eq('id', 123)
.single()Insert
// Single insert
const { data, error } = await krisspy
.from('products')
.insert({ name: 'iPhone', price: 999 })
// Batch insert
const { data, error } = await krisspy
.from('products')
.insert([
{ name: 'iPhone', price: 999 },
{ name: 'iPad', price: 799 },
])Update
const { data, error } = await krisspy
.from('products')
.update({ price: 899 })
.eq('id', 123)Delete
const { data, error } = await krisspy
.from('products')
.delete()
.eq('id', 123)Filter Operators
| Method | SQL Equivalent |
|--------|----------------|
| .eq(column, value) | = value |
| .neq(column, value) | != value |
| .gt(column, value) | > value |
| .gte(column, value) | >= value |
| .lt(column, value) | < value |
| .lte(column, value) | <= value |
| .like(column, pattern) | LIKE pattern |
| .ilike(column, pattern) | ILIKE pattern |
| .in(column, values) | IN (values) |
| .is(column, value) | IS value (null, true, false) |
Ordering & Pagination
const { data, error } = await krisspy
.from('products')
.select('*')
.order('price', { ascending: true })
.order('name', { ascending: true }) // Multiple orders
.limit(10)
.range(0, 9) // First 10 items (offset 0, limit 10)Functions
// Invoke a function
const { data, error } = await krisspy.functions.invoke('hello-world', {
body: { name: 'John' },
})
// List functions
const { data: functions } = await krisspy.functions.list()Tables
// List tables
const { data: tables } = await krisspy.listTables()
// Get table schema
const { data: columns } = await krisspy.getTableSchema('products')TypeScript
The SDK is fully typed. You can define your table types:
interface Product {
id: number
name: string
price: number
created_at: string
}
const { data, error } = await krisspy
.from<Product>('products')
.select('*')
// data is Product[] | nullError Handling
All methods return { data, error }:
const { data, error } = await krisspy.from('products').select('*')
if (error) {
console.error('Error:', error.message)
return
}
console.log('Products:', data)Configuration
const krisspy = createClient({
// Required
backendId: 'your-backend-id',
// Optional
url: 'https://api.krisspy.ai', // Custom API URL
apiKey: 'your-api-key', // For authenticated requests
headers: { // Custom headers
'X-Custom-Header': 'value'
},
debug: true, // Enable debug logging
})License
MIT
