profound-logoProfound CMS
⌘K
Admin
Theme
DocsTutorialBlogPhilosophy
DocsTutorialBlogPhilosophy

Hybrid

Collection of Pages with ComponentsTypes of ComponentsSetup server sent events (SSE) content refetchInstall Profound CMS as a proxyCEL Scripting in Template BuilderProject ScaffoldingMedia Library

Headless

Quick startSplit Screen JSON Component Builder with LLMComponent Zod Pull

REST API

REST API OverviewgetConnect your websitegetGET /routesgetGET /routegetGET /blocksgetGET /blocks/with-cel-cachegetGET /blocks/generatedgetGET /componentsgetGET /components/{name}getGET /dataset/{schema_name}getGET /content-changes (SSE)patchPATCH /dataset/{schema_name}postPOST /translationpatchPATCH /translationsgetGET /usagepostPOST /csvpatchPATCH /csv
All Systems Operational
Powered Byprofound-logo
Theme

Quick start

A post about schemas

Generate Type-Safe Zod Schemas

This feature allows you to get your components description in the form of a type-safe Zod schema, providing:

  • TypeScript-first schema validation
  • Static type inference

Learn more: https://zod.dev

Setup

To pull your Zod schema, you will:

  1. Load required dependencies
  2. Create a script using utilities from cms-renderer

Project Structure

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts   # script file

Script: generated-schema.ts

import { fetchAllCustomSchemaFields, saveZodSchemaCode } from 'cms-renderer/lib/custom-schemas';
import { cmsConfig } from '../lib/cms-config';

async function main() {
  const { cmsUrl, websiteId, apiKey } = cmsConfig;

  if (!cmsUrl) {
    throw new Error(
      '[generate-schemas] NEXT_PUBLIC_CMS_API_URL is not set. Set it in your environment or .env file.'
    );
  }

  if (!websiteId) {
    throw new Error(
      '[generate-schemas] CMS_WEBSITE_ID is not set. Set it in your environment or .env file.'
    );
  }

  if (!apiKey) {
    throw new Error(
      '[generate-schemas] PROFOUND_API_KEY is not set. Set it in your environment or .env file.'
    );
  }

  const schemas = await fetchAllCustomSchemaFields({ cmsUrl, websiteId, apiKey });

  if (schemas.length === 0) {
    throw new Error(
      '[generate-schemas] No components returned from the API. Check that PROFOUND_API_KEY is valid and points at the right website.'
    );
  }

  console.log(
    `[generate-schemas] Found ${schemas.length} components: ${schemas.map((s) => s.name).join(', ')}`
  );

  await saveZodSchemaCode(schemas, './generated/cms-schemas.ts');

  console.log('[generate-schemas] Done.');
}

main().catch((err) => {
  console.error('[generate-schemas] Failed:', err);
  process.exit(1);
});

CMS Config Example

export const cmsConfig = {
  cmsUrl: process.env.NEXT_PUBLIC_CMS_API_URL,
  apiKey: process.env.CMS_API_KEY,
  websiteId: '...',
};

package.json Configuration

Note: If you don't have a tsconfig.json, remove the --tsconfig flag.

{
  "name": "web",
  "version": "0.1.0",
  "type": "module",
  "private": true,
  "scripts": {
    "generate-schemas": "tsx --tsconfig tsconfig.json scripts/generate-schemas.ts",
    "...": "..."
  },
  "dependencies": {
    "cms-renderer": "0.3.1",
    "zod": "^4.3.6",
    "...": "..."
  },
  "devDependencies": {
    "tsx": "^4.21.0",
    "object-hash": "^3.0.0",
    "...": "..."
  }
}

Running the Script

bun run generate-schemas

Example output:

tsx --tsconfig tsconfig.json scripts/generate-schemas.ts
[generate-schemas] Found 3 components: post, categories, header
[generate-schemas] Done.

Updated Project Structure

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts
    generated/
      cms-schemas.ts   # generated Zod schema

Usage in page.tsx

import type { PetFoodPost, SiteConfig } from '@/generated/cms-schemas';
import { petFoodPostSchema } from '@/generated/cms-schemas';

// Use for type-safe parsing
petFoodPostSchema.parse(obj);

Notes

  • Inspect the generated file to understand your component's structure
  • Re-run the script whenever your component's structure changes:
bun run generate-schemas
  • You can integrate this into your dev or build workflow
  • Update components via the admin panel, then regenerate locally
Continue Reading
NextSplit Screen JSON Component Builder with LLM›