@ct0dev/mini-app-sdk
v1.0.5
Published
A lightweight React Native SDK for ct0.dev mini-apps
Downloads
15
Maintainers
Readme
🧩 @ct0/mini-app-sdk
A lightweight React Native SDK to simplify building AI-generated mini-apps inside ct0.dev.
Includes:
- ✅ App & user context (
MiniAppProvider) - ✅ Flexible CRUD (
useCrud) for any collection - ✅ Shared vs private access support
- ✅ Auto caching via AsyncStorage
- ✅ Extensible structure for future hooks (assets, auth, etc.)
✨ Installation
npm install @ct0/mini-app-sdk
# or
yarn add @ct0/mini-app-sdkPeer dependencies:
- react
- react-dom
- @react-native-async-storage/async-storage⚙️ Usage
1. Wrap your mini-app with MiniAppProvider
import { MiniAppProvider } from '@ct0/mini-app-sdk';
export default function App() {
return (
<MiniAppProvider
appId="your-app-id"
userId="ajay"
apiBaseUrl="https://api.ct0.in"
theme="dark"
language="en"
onClose={() => console.log('App closed')}
onError={(err) => console.error(err)}
>
<YourMiniApp />
</MiniAppProvider>
);
}2. Use Context Anywhere
import { useMiniAppContext } from '@ct0/mini-app-sdk';
const {
appId,
userId,
apiBaseUrl,
theme,
language,
onClose,
onError
} = useMiniAppContext();3. Use CRUD for Collections
import { useCrud } from '@ct0/mini-app-sdk';
const { items, create, update, remove, refresh, loading } = useCrud('todos');Shared access (e.g. group data)
const { items } = useCrud('expenses', { access: 'shared' });💾 Caching & Offline Support
- All
useCrud()data is cached inAsyncStorage - Auto loaded on mount, then updated in background
- Automatically updated on
create,update,remove
🧱 API Summary
| Feature | Hook | Description | Status |
|--------------------|-----------------------|---------------------------------------------------|----------|
| ✅ App Context | useMiniAppContext() | Access appId, userId, apiBaseUrl, etc. | ✅ Ready |
| ✅ Provider | MiniAppProvider | Wrap your app and pass context | ✅ Ready |
| ✅ Collection CRUD | useCrud() | Full CRUD with cache + accessMode | ✅ Ready |
🔮 Planned Additions
| Feature | Hook | Priority |
|---------------------|---------------------|-----------|
| 📁 Asset Uploads | useAssets() | 🔜 High |
| 🧠 Auth | useAuth() | 🔜 High |
| 🛠 App Settings | useSettings() | 🔜 Medium |
| 🌍 Translations | useI18n() | 🔜 Medium |
| 🔔 Notifications | useNotifications() | 🔜 Medium |
| 🕸 Realtime Sync | useRealtime() | 🔜 Medium |
| 📸 Media Capture | useCamera() | 🔜 Medium |
| 📤 Share | useShare() | 🔜 Optional |
| 🎛 Experiments | useExperiments() | 🔜 Optional |
✅ 𝙲𝙾𝚁𝙴 𝙰𝙿𝙸 𝙰𝙱𝚂𝚃𝚁𝙰𝙲𝚃𝙸𝙾𝙽𝚂
| Feature | Hook | Description | Priority |
|----------------|----------------|-------------------------------------------------------|-----------------|
| 🧠 User Auth | useAuth() | Identity context (guest/userId/login/logout) | ✅ Essential |
| 📦 CRUD | useCrud() | Generic collection-level CRUD with offline support | ✅ Already Done |
| 📁 Asset Uploads | useAssets() | Upload image/audio/video/files and get back URL | ✅ High |
| 🔄 Sync + Cache| useSync() | Background syncing, stale/while-revalidate pattern | ✅ High |
| 🧾 Metadata | useMeta() | Access appId, collectionId, userId, access mode | ✅ Essential |
🎨 𝚄𝚂𝙴𝚁 𝙴𝚇𝙿𝙴𝚁𝙸𝙴𝙽𝙲𝙴
| Feature | Hook | Description | Priority |
|-----------------|---------------------|-----------------------------------------------|----------------|
| 📍 Location | useLocation() | Get current location with permission flow | 🔜 Medium |
| 📤 Share | useShare() | Native or link-based content sharing | 🔜 Medium |
| 🔔 Notifications| useNotifications() | Show toast/in-app/push alerts | 🔜 Medium |
| 🌓 Theme | useTheme() | Access color palette, dark/light, etc. | 🔜 Optional |
| 🌐 Language | useI18n() | Simple string translation + language switch | 🔜 Optional |
🧰 𝙲𝙾𝙼𝙿𝙾𝙽𝙴𝙽𝚃 + 𝚂𝚃𝙰𝚃𝙴 𝚄𝚃𝙸𝙻𝚂
| Feature | Hook | Description | Priority |
|-----------------|-------------------|-----------------------------------------------------|----------------|
| 💾 Local Storage| useStorage() | Persistent key-value store (per user/app) | ✅ High |
| 🧪 Experiments | useExperiments() | Feature flags + variant checks | 🔜 Optional |
| ⚙️ Settings | useSettings() | App-wide settings (e.g. preferences) | 🔜 Optional |
| 🧭 Navigation | useNav() | Abstracted navigation across host/mini | 🔜 TBD |
| 💬 Prompting | usePrompt() | Call AI (Together, OpenAI, etc.) from inside app | 🔜 Very Useful |
🔁 𝚁𝙴𝙰𝙻𝚃𝙸𝙼𝙴 + 𝙲𝙾𝙻𝙻𝙰𝙱
| Feature | Hook | Description | Priority |
|-----------------|-------------------|-----------------------------------------------------|----------------|
| 🔃 Realtime Data| useRealtime() | Pub-sub or listener on collection | 🔜 Medium |
| 👥 Presence | usePresence() | Track who is online or live | 🔜 Optional |
| 🕒 Scheduler | useScheduler() | Run tasks on interval (e.g., sync every 5m) | 🔜 Optional |
| ⌛ Offline Detector | useOffline() | Show fallback if no connection | 🔜 Optional |
🧩 𝚂𝙿𝙴𝙲𝙸𝙰𝙻 𝙼𝙾𝙳𝙴𝙻𝚂 / 𝙲𝙰𝚂𝙴𝚂
| Feature | Hook | Description | Priority |
|-----------------|-----------------------|--------------------------------------------------|----------------|
| 📸 Media Capture| useCamera() / useMicrophone() | Capture image/audio and upload | ✅ For image/audio blogs |
| 📚 Collections Index | useIndex() | List all collections + schemas in app | 🔜 Optional |
| 🧵 Comments | useComments() | Prebuilt support for threaded replies | 🔜 Optional |
| 📈 Metrics | useMetrics() | Record engagement, actions, views | 🔜 Optional |
| 🎁 Templates | useTemplates() | Fetch reusable templates/layouts | 🔜 Optional |
📋 𝙿𝙻𝙰𝚃𝙵𝙾𝚁𝙼 𝚂𝚄𝙿𝙿𝙾𝚁𝚃
| Feature | Hook | Description | Priority |
|-----------------|-------------------|-------------------------------------------------|-----------------|
| 🧠 Model Context| useModelInfo() | Detect which model generated this mini-app | 🔜 Debugging |
| 🧩 App Info | useAppInfo() | Show version, bundle source, build ID | 🔜 Optional |
| 🧹 Cache Management | useCache() | Clear app or component cache | ✅ Already Added |
🧪 EXAMPLE ROLLING PLAN
- ✅
useCrud(),useAssets(),useAuth() - ✅
useMeta(),useStorage() - 🔜
useNotifications(),useLocation(),usePrompt() - 🔜
useRealtime(),useShare(),useCamera() - 🔜 Advanced:
useExperiments(),useScheduler(),usePresence()
🧪 Dev Commands
yarn build # Compile SDK to dist/
yarn dev # Watch mode (Rollup)
yarn lint # ESLint
yarn format # Prettier📦 This SDK powers…
✅ Todo apps
✅ Expense splitters
✅ Journals, trackers, diaries
✅ Group shared utilities
…and 100s of AI-generated ct0.dev apps!
Made for dynamic creativity at ct0.dev
