@plenary/client
v0.5.1
Published
Plenary framework-free API client: content fetch, form submission, and query builder.
Downloads
989
Readme
@plenary/client
The framework-free Plenary content client: published-content reads, public
form submission, and webhook payload verification. Works anywhere fetch
does — Node, edge runtimes, the browser. No admin endpoints; it's configured
with a public delivery API key and can only read what that key allows.
npm install @plenary/clientReading content
import { createClient } from "@plenary/client";
const plenary = createClient({
baseUrl: "https://cms.example.com", // your Plenary origin
siteKey: "main",
apiKey: process.env.PLENARY_API_KEY!, // public delivery key
locale: "en",
});
// A collection entry by slug, typed however you've modeled it
const post = await plenary.getEntry<{ title: string; body: string }>(
"blog-post",
"hello-world",
);
// A singleton model
const settings = await plenary.getSingleton("site-settings");
// A filtered, paginated list; total comes back when you ask for a count
const { items, total } = await plenary.listEntries("blog-post", {
where: { "data.featured": true },
sort: "-created_at",
limit: 10,
count: true,
});Entries carry slug and path (the content-folder directory path, without
the slug) — route on both to mirror the folder tree in your URLs.
Errors are typed: requests that fail throw PlenaryError subclasses
(PlenaryNotFoundError, PlenaryValidationError, PlenaryForbiddenError)
with the server's error payload attached.
Forms
const form = await plenary.getForm("contact"); // render-safe field definitions
const result = await plenary.submitForm("contact", {
name: "Ada",
email: "[email protected]",
message: "Hello!",
});getForm returns the field list a renderer needs; submitForm posts a public
form entry. Validation failures surface as PlenaryValidationError with
per-field messages.
Webhook consumers
The payload types Plenary POSTs to your webhooks, plus framework-neutral verification and parsing:
import { parseWebhookRequest, isEntryWebhookPayload } from "@plenary/client";
const payload = await parseWebhookRequest(request, {
secret: process.env.PLENARY_WEBHOOK_SECRET!,
});
if (isEntryWebhookPayload(payload)) {
// payload.event, payload.entry, payload.actor …
}Verification is a constant-time shared-secret comparison against a header or
query parameter. If you're on Next.js, @plenary/next builds cache
revalidation handlers on top of these helpers.
Full documentation at docs.plenarycms.com.
