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 proxyScripts dans le générateur de modÚlesProject ScaffoldingBibliothÚque multimédia

Sans interface

Démarrage rapideSplit Screen JSON Component Builder with LLMComponent Zod Pull

API REST

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

Démarrage rapide

Un article sur les schémas

Générer des schémas Zod sûrs pour les types

Cette fonctionnalité vous permet d'obtenir la description de vos composants sous la forme d'un schéma Zod sûr pour les types, offrant :

  • Validation de schĂ©mas priorisant TypeScript
  • InfĂ©rence statique des types

En savoir plus : https://zod.dev

Configuration

Pour récupérer votre schéma Zod, vous allez :

  1. Charger les dépendances requises
  2. Créer un script utilisant les utilitaires de cms-renderer

Structure du projet

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

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);
});

Exemple de configuration CMS

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

Configuration de package.json

Remarque : si vous n'avez pas de tsconfig.json, supprimez l'indicateur --tsconfig.

{
  "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",
    "...": "..."
  }
}

Exécution du script

bun run generate-schemas

Exemple de sortie :

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

Structure du projet mise Ă  jour

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts
    generated/
      cms-schemas.ts   # schéma Zod généré

Utilisation dans page.tsx

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

// À utiliser pour une analyse sĂ»re du typage
petFoodPostSchema.parse(obj);

Remarques

  • Inspectez le fichier gĂ©nĂ©rĂ© pour comprendre la structure de votre composant
  • Relancez le script chaque fois que la structure de votre composant change :
bun run generate-schemas
  • Vous pouvez intĂ©grer cela dans votre flux de travail de dĂ©veloppement ou de build
  • Mettez Ă  jour les composants via le panneau d'administration, puis rĂ©gĂ©nĂ©rez localement
Continue Reading
NextSplit Screen JSON Component Builder with LLMâ€ș