@brandfine/client-astro
v0.1.0
Published
Astro adapter for @brandfine/client — APIRoute-shaped webhook handler and env helpers.
Readme
@brandfine/client-astro
Astro adapter for @brandfine/client. Two thin helpers:
createBrandfineWebhookRoute— wraps the framework-agnostic webhook handler in Astro'sAPIRouteshape.readBrandfineEnv— readsBRANDFINE_API_URL,BRANDFINE_API_KEY, andBRANDFINE_WEBHOOK_SECRETfrom Vite'simport.meta.envwith aprocess.envfallback.
Status: early development (
0.x.y). API may change in minor bumps before1.0.
The actual SDK (client, caches, resolvers) lives in @brandfine/client and is framework-agnostic. Install both:
npm install @brandfine/client @brandfine/client-astroWebhook route
// src/pages/api/brandfine-webhook.ts
import { createBrandfineWebhookRoute, readBrandfineEnv } from '@brandfine/client-astro'
import { postsCache, navigationsCache, workspaceCache } from '@/lib/bf'
export const prerender = false
export const POST = createBrandfineWebhookRoute({
secret: readBrandfineEnv().webhookSecret,
onEvent: ({ event, key }) => {
postsCache.invalidate()
workspaceCache.invalidate()
if (event.startsWith('navigation.')) navigationsCache.invalidate(key ?? undefined)
},
})Client construction
// src/lib/bf.ts
import { createBrandfineClient } from '@brandfine/client'
import { readBrandfineEnv } from '@brandfine/client-astro'
const env = readBrandfineEnv()
export const bf = createBrandfineClient({
baseUrl: env.apiUrl,
apiKey: env.apiKey,
// Optional: locales, defaultLocale, fetch
})Peer requirements
astro>= 4.0.0 (uses the modernAPIRouteshape withRequest)@brandfine/client(workspace dep — installed automatically)
License
MIT
