@bext-stack/platform
v0.2.0
Published
Platform SDK for bext — access KV, queue, cache, realtime, scheduler from your app
Downloads
19
Maintainers
Readme
@bext-stack/platform
Typed platform SDK for bext apps. Provides KV, queue, cache, realtime, scheduler, secrets, database, and blob storage clients that talk to the bext runtime over HTTP.
Install
npm i @bext-stack/platformUsage
import { createClient } from "@bext-stack/platform";
const bext = createClient();
// KV
await bext.kv.set("user:1", { name: "Ben" }, { ttlSeconds: 3600 });
const user = await bext.kv.get<{ name: string }>("user:1");
// Queue
await bext.queue.push("jobs", { type: "email", to: "[email protected]" });
const messages = await bext.queue.pull("jobs", { batch: 10 });
for (const m of messages) {
await bext.queue.ack("jobs", m.id);
}
// Cache with tag invalidation
await bext.cache.set("posts:index", posts, { tags: ["posts"] });
await bext.cache.invalidate({ tags: ["posts"] });
// Realtime
await bext.realtime.publish("chat:room-1", { text: "hello" });
// Scheduler
await bext.scheduler.register({
name: "nightly-cleanup",
cron: "0 3 * * *",
handler: "/jobs/cleanup",
});
// Secrets
await bext.secrets.set("STRIPE_KEY", "sk_live_...");
// Database
const rows = await bext.db.query("SELECT * FROM users WHERE id = ?", [42]);
// Blob
await bext.blob.put("uploads/hello.txt", "hello world", "text/plain");Config
createClient({
baseUrl: "http://localhost:3062", // default: same-origin
apiKey: process.env.BEXT_API_KEY, // optional
authHeader: "X-Bext-Key", // default header name
});How it works
Every method is a thin HTTP call to the /__bext/sdk/* endpoints exposed by bext-server. Your app code talks to localhost:3062 (or whatever baseUrl you configure), and bext handles persistence, replication, and cache coherency under the hood.
License
MIT — Part of the bext stack.
