storenow-sdk
v1.0.0
Published
JavaScript SDK for store.now - instant database for AI agents
Maintainers
Readme
@storenow/sdk
JavaScript SDK for store.now — instant database for AI agents.
Installation
npm install @storenow/sdkQuick Start
import StoreNow from '@storenow/sdk'
// Initialize with your store ID and token
const db = new StoreNow('your-store-id', 'wt_your-token')
// Create a document
await db.collection('users').create({ name: 'John', age: 30 })
// Get all documents
const { documents } = await db.collection('users').getAll()
// Query with filters
const { documents: adults } = await db.collection('users').query({
age: { $gte: 18 }
})Usage in HTML (Browser)
<script type="module">
import StoreNow from 'https://esm.sh/@storenow/sdk'
const db = new StoreNow('your-store-id', 'wt_your-token')
// Now use db.collection('name') to store/retrieve data
</script>API Reference
Initialize
const db = new StoreNow(storeId, token)Collections
Collections are created automatically when you first write to them.
const habits = db.collection('habits')Create Document
// Auto-generated ID
const doc = await habits.create({ name: 'Exercise', done: false })
console.log(doc.id) // e.g., 'abc123xyz'
// Custom ID
const doc = await habits.create({ name: 'Exercise' }, 'my-custom-id')Get All Documents
const { documents, total } = await habits.getAll()
// With pagination
const { documents } = await habits.getAll({
limit: 10,
offset: 0,
order_by: 'created_at:desc'
})Get Single Document
const doc = await habits.get('document-id')Query Documents
// Simple equality
const { documents } = await habits.query({ done: false })
// With operators
const { documents } = await habits.query({
age: { $gte: 18 },
status: { $in: ['active', 'pending'] }
})Supported operators:
$eq- equals (default)$ne- not equals$gt- greater than$gte- greater than or equal$lt- less than$lte- less than or equal$in- in array
Update Document
await habits.update('document-id', { name: 'Exercise', done: true })Delete Document
await habits.delete('document-id')List Collections
const collections = await db.listCollections()
// [{ name: 'habits', document_count: 5, storage_bytes: 1024 }]Examples
Habit Tracker
const db = new StoreNow('store-id', 'token')
const habits = db.collection('habits')
// Add habit
await habits.create({
name: 'Exercise',
streak: 0,
lastCompleted: null
})
// Mark complete
const habit = await habits.get('habit-id')
await habits.update('habit-id', {
...habit.data,
streak: habit.data.streak + 1,
lastCompleted: new Date().toISOString()
})
// Get all habits
const { documents } = await habits.getAll()Todo App
const db = new StoreNow('store-id', 'token')
const todos = db.collection('todos')
// Add todo
await todos.create({ text: 'Buy groceries', done: false })
// Get incomplete todos
const { documents } = await todos.query({ done: false })
// Mark complete
await todos.update('todo-id', { text: 'Buy groceries', done: true })
// Delete
await todos.delete('todo-id')User Preferences
const db = new StoreNow('store-id', 'token')
const prefs = db.collection('preferences')
// Save preferences (using custom ID for easy retrieval)
await prefs.create({
theme: 'dark',
language: 'en',
notifications: true
}, 'user-settings')
// Get preferences
const settings = await prefs.get('user-settings')Get Your Credentials
- Go to store.now
- Create a new store
- Copy your Store ID and Token
Or via API:
curl -X POST https://store-now.storenow-api.workers.dev/api/v1/stores \
-H "Content-Type: application/json" \
-d '{"name": "my-app"}'License
MIT
