1.0.4 โข Published 8 months ago
๐งฉ @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-sdk
Peer 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 in AsyncStorage - 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