fabrico-sdk
v1.1.0
Published
The official SDK for Fabrico Cloud
Readme
fabrico-sdk
The Developer-First Backend-as-a-Service (BaaS) SDK for Cloudflare.
fabrico-sdk is a type-safe, unified client for interacting with Fabrico Cloud. It provides a single interface for Authentication, Serverless Databases (Turso), Storage (R2), and managed AI models (Workers AI) — all pre-configured and scoped to your project.
🚀 Quick Start
1. Installation
npm install fabrico-sdk
# or
pnpm add fabrico-sdk2. Initialization
import { createClient } from "fabrico-sdk";
// Scoped to your project's multi-tenant infrastructure
const fabrico = createClient({
publishableKey: "project_id_...", // Found in your Dashboard
apiKey: process.env.FABRICO_API_TOKEN, // Required for secure server-side ops (DB, Storage, AI)
});🔐 1. Authentication (fabrico.auth)
A production-ready auth system powered by Better-Auth, supporting Email OTP and OAuth.
// Sign up a new user (Frontend)
const { user, session } = await fabrico.auth.signUp.email({
email: "[email protected]",
password: "secure-password",
name: "Fabrico Developer"
});
// Get current session
const session = await fabrico.auth.getSession();💾 2. Database (fabrico.db)
Direct SQL access to your project's isolated Turso (libSQL) database. No connection strings required.
// Execute raw SQL
const { rows } = await fabrico.db.query(
"SELECT * FROM posts WHERE status = ?",
["published"]
);
// High-level select helper
const posts = await fabrico.db.select("posts", { limit: 10 });📦 3. Storage (fabrico.storage)
Seamlessly manage files in your project's Cloudflare R2 buckets.
const bucket = fabrico.storage.bucket("uploads");
// Upload a file (Blob, File, or Buffer)
await bucket.upload("profile.png", fileBlob);
// Get a fast, unauthenticated public URL for frontend display
const url = bucket.getPublicUrl("profile.png");🤖 4. AI Gateway (fabrico.ai)
Direct access to Cloudflare Workers AI (Llama 3, SDXL, etc.) via a secure gateway.
import { AI_MODELS } from "fabrico-sdk";
const { text } = await fabrico.ai.chat.completions.create({
model: AI_MODELS.chat.LLAMA_3_8B,
messages: [{ role: "user", content: "Write a SQL query to..." }]
});⚡ 5. Realtime (fabrico.realtime)
Pub/Sub and Presence powered by Cloudflare Durable Objects.
// Subscribe to a channel (Frontend)
const channel = fabrico.realtime.channel("public:updates");
channel.on("new_post", (payload) => console.log(payload));
// Broadcast from your backend
await fabrico.realtime.broadcast("public:updates", { id: 1, title: "New Release!" });🛠️ Framework Integrations
React
Use the official hooks and premium UI components for a 10-minute "Zero-to-Auth" experience.
import { FabricoProvider, SignIn, UserButton } from "fabrico-sdk/react";
function App() {
return (
<FabricoProvider client={fabrico}>
<header>
<UserButton />
</header>
<SignIn />
</FabricoProvider>
);
}🛡️ Security Best Practices
| Environment | Keys Required | Allowed Operations |
| :--- | :--- | :--- |
| Frontend (Browser) | publishableKey | Auth (Client-side), Realtime (Public) |
| Backend (Worker/Node) | publishableKey + apiKey | Full Access: DB, Storage, AI, Admin Auth |
Note: Never expose your apiKey in client-side code (environment variables starting with VITE_ or NEXT_PUBLIC_).
📚 Documentation
For full documentation, visit docs.fabrico.diy.
📄 License
MIT © Fabrico
