@antlur/backstage
v1.12.12
Published
A simple client for Backstage CMS
Downloads
951
Maintainers
Readme
@antlur/backstage
A TypeScript client library for Backstage CMS with type-safe block and layout definitions.
Features
- 🔐 Type-safe API client for Backstage CMS
- 🧱 Define custom blocks with full TypeScript support
- 📐 Define custom layouts with schema validation
- 🔄 CLI tools for syncing blocks and layouts
- ⚛️ React components for page metadata and structured data
- 🎨 Framework-agnostic design (works with Next.js, React, etc.)
Installation
npm install @antlur/backstage
# or
yarn add @antlur/backstage
# or
pnpm add @antlur/backstageQuick Start
1. Environment Setup
Create a .env file in your project root:
# Required
BACKSTAGE_API_KEY=your_api_key_here
BACKSTAGE_ACCOUNT_ID=your_account_id_here
# Optional (defaults to https://bckstg.app/api)
BACKSTAGE_API_URL=https://bckstg.app/api2. Configure Backstage
Create a backstage.config.ts file:
import { defineConfig } from "@antlur/backstage";
export default defineConfig({
accountId: process.env.BACKSTAGE_ACCOUNT_ID,
token: process.env.BACKSTAGE_API_KEY,
// Optional: define your blocks and layouts here
blocks: [],
layouts: [],
});3. Use the Client
import { BackstageClient } from "@antlur/backstage";
const client = new BackstageClient();
// Fetch pages
const pages = await client.pages.getPages();
const homePage = await client.pages.getHomePage();
const page = await client.pages.getPageBySlug("about");
// Fetch locations
const locations = await client.locations.getLocations();
const location = await client.locations.getLocationBySlug("downtown");
// Fetch events
const events = await client.events.getEvents();
const event = await client.events.getEventBySlug("summer-festival");
// Fetch menus
const menu = await client.menus.getMenu("main-menu");Defining Custom Blocks
Create type-safe blocks for your CMS:
// blocks/hero/schema.ts
import { defineBlockSchema, defineField } from "@antlur/backstage/studio";
const heroFields = [
defineField({
name: "Title",
slug: "title",
type: "text",
required: true,
}),
defineField({
name: "Subtitle",
slug: "subtitle",
type: "text",
}),
defineField({
name: "Background Image",
slug: "backgroundImage",
type: "image",
required: true,
}),
] as const;
export const schema = defineBlockSchema({
fields: heroFields,
});
export default schema;// blocks/hero/component.tsx
import type { BlockComponentProps } from "@antlur/backstage/studio";
import schema from "./schema";
export default function Hero({ block }: BlockComponentProps<typeof schema>) {
const { title, subtitle, backgroundImage } = block.fields;
return (
<div className="hero" style={{ backgroundImage: `url(${backgroundImage.url})` }}>
<h1>{title}</h1>
{subtitle && <p>{subtitle}</p>}
</div>
);
}// blocks/hero/index.ts
import { defineBlock } from "@antlur/backstage/studio";
import schema from "./schema";
import Hero from "./component";
export const heroBlock = defineBlock({
name: "Hero",
slug: "hero",
description: "A hero section with title, subtitle, and background image",
schema,
component: Hero,
});CLI Commands
Sync your blocks and layouts to Backstage CMS:
# Sync blocks only
npx backstage sync blocks
# Sync layouts only
npx backstage sync layouts
# Sync everything
npx backstage sync allAdd this to your backstage.config.ts:
import { defineConfig } from "@antlur/backstage";
import { heroBlock } from "./blocks/hero";
export default defineConfig({
accountId: process.env.BACKSTAGE_ACCOUNT_ID,
token: process.env.BACKSTAGE_API_KEY,
blocks: [heroBlock],
});Available Services
The client provides the following services:
client.pages- Page managementclient.blocks- Block managementclient.layouts- Layout managementclient.locations- Location managementclient.events- Event managementclient.menus- Menu managementclient.navigation- Navigation managementclient.media- Media managementclient.alerts- Alert managementclient.press- Press release managementclient.website- Website settingsclient.instagram- Instagram integration
Field Types
Supported field types for blocks and layouts:
text- Single-line text inputtextarea- Multi-line text inputrich_text- Rich text editornumber- Numeric inputboolean- Checkboxurl- URL inputimage- Single image pickerimage_list- Multiple image pickermedia- Media item pickerlist_array- Array of stringsrepeater- Repeatable field groupevent_select- Event selectormenu_select- Menu selectorform_select- Form selectorpress_select- Press release selectornavigation_select- Navigation selector
React Components
import { PageMeta } from "@antlur/backstage";
export default function MyPage({ page }) {
return (
<>
<PageMeta page={page} />
{/* Your page content */}
</>
);
}TypeScript Support
This library is written in TypeScript and provides full type definitions. All API responses are typed, and block/layout definitions provide excellent autocompletion and type safety.
License
MIT
Contributing
Issues and pull requests are welcome! Please visit the GitHub repository.
Support
For questions or support, please open an issue on GitHub or contact the Backstage CMS team.
