@blueline/astro (0.1.0)
Installation
@blueline:registry=npm install @blueline/astro@0.1.0"@blueline/astro": "0.1.0"About this package
@blueline/astro
Typed fetch helpers for the Blueline content, preview, and redirect REST
envelopes. The package name records the first documented frontend. The
implementation is fetch plus types, so Eleventy or any other static
generator can import the same modules. Astro is an optional peer.
There is no required Astro runtime and no .astro component in this
package.
Install
pnpm add @blueline/astro --registry https://git.rallen.dev/api/packages/rallendev/npm/
Or pin the scope in .npmrc:
@blueline:registry=https://git.rallen.dev/api/packages/rallendev/npm/
From this repository, the workspace package is packages/astro.
CMS origin
Pass cmsUrl on every call, or set PUBLIC_BLUELINE_CMS_URL (Astro
exposes PUBLIC_* on import.meta.env). Trailing slashes are stripped.
There is no other env fallback.
import { getPublishedContent, listPublishedContent, searchPublishedContent } from "@blueline/astro";
import { getMenu } from "@blueline/astro/menus";
import { listSitemapEntries } from "@blueline/astro/sitemap";
const cmsUrl = import.meta.env.PUBLIC_BLUELINE_CMS_URL;
const posts = await listPublishedContent({ cmsUrl, type: "post" });
const post = await getPublishedContent("notes-from-the-field", { cmsUrl });
const hits = await searchPublishedContent({ cmsUrl, q: "field" });
const nav = await getMenu("primary", { cmsUrl });
const sitemap = await listSitemapEntries({ cmsUrl, siteUrl: "https://example.com" });
listPublishedContent follows X-Blueline-Total-Pages. Both helpers
call GET {cmsUrl}/wp-json/blueline/v1/content, not wp/v2.
Fail-open published, fail-closed preview
Marketing static builds must not crash the whole site when WordPress is
unreachable. Published helpers fail open: network errors, empty
cmsUrl, and non-2xx responses become [] or null.
Preview is fail-closed. An invalid, expired, or mismatched token
returns null. The client never falls back to the published item and
never pretends a draft is live.
Redirects on the plugin are fail-closed (401 without
BLUELINE_BUILD_TOKEN). This client treats 401 and offline as [] so a
misconfigured build still finishes; the baked map is empty until the
token is set.
Preview route sketch
Preview needs a server route. Keep it off the static graph:
// src/pages/preview/[slug].ts — or any SSR / edge handler
export const prerender = false;
import { getPreviewContent } from "@blueline/astro/preview";
export async function GET({ url }: { url: URL }) {
const draft = await getPreviewContent({
cmsUrl: import.meta.env.PUBLIC_BLUELINE_CMS_URL,
id: Number(url.searchParams.get("p")),
token: url.searchParams.get("token") ?? "",
});
if (draft === null) {
return new Response("Not found", { status: 404 });
}
return new Response(draft.html, {
headers: { "content-type": "text/html; charset=utf-8" },
});
}
verifyPreviewToken POSTs { token } to blueline/v1/preview/verify
and returns { post_id, exp } or null.
Redirects at build time
import { listRedirects } from "@blueline/astro/redirects";
const redirects = await listRedirects({
cmsUrl: import.meta.env.PUBLIC_BLUELINE_CMS_URL,
buildToken: process.env.BLUELINE_BUILD_TOKEN,
});
The client sends Authorization: Bearer and X-Blueline-Build-Token.
HTML
Trust the plugin sanitiser. This package applies the same light strip
(script, style, iframe, on* handlers, javascript: URLs) as
defense in depth. It does not invent a second allow-list.
Exports
| Specifier | Helpers |
|---|---|
@blueline/astro |
listPublishedContent, getPublishedContent, searchPublishedContent |
@blueline/astro/preview |
getPreviewContent, verifyPreviewToken |
@blueline/astro/redirects |
listRedirects |
@blueline/astro/menus |
getMenu |
@blueline/astro/sitemap |
listSitemapEntries |
Envelope fields match docs/architecture/rest.md.
Product contract: docs/architecture/client-astro.md.
Scripts
pnpm --filter @blueline/astro test
pnpm --filter @blueline/astro check
Dependencies
Development dependencies
| ID | Version |
|---|---|
| typescript | ^5.9.2 |
| vitest | ^3.2.4 |
Peer dependencies
| ID | Version |
|---|---|
| astro | >=4 |