import { CURRENT_STEP_CONTRACT_VERSION, validateFunnelStepContractSnapshot, type FunnelContractDiagnostic, type FunnelStepContractProjectSnapshot, type FunnelStepMeta, } from '@funnelsgrove/runtime'; import docsManifest from '../../.funnelsgrove-docs.json'; import { rawFunnelManifest } from '@/config/funnel.manifest'; import { stepRegistry } from '@/runtime/step-registry'; import { contentOptionsByStepId } from '@/steps/step-content.registry'; export const FUNNEL_PROJECT_CONTRACT_VERSION = CURRENT_STEP_CONTRACT_VERSION; export const buildFunnelProjectSnapshot = (): FunnelStepContractProjectSnapshot => { const componentMetaByKey = Object.fromEntries( Object.entries(stepRegistry).map(([componentKey, entry]) => [componentKey, entry.meta]), ) as Record; return { manifest: rawFunnelManifest, componentMetaByKey, registeredComponentKeys: Object.keys(stepRegistry), contentOptionsByStepId, edgesByStepId: rawFunnelManifest.edgesByStepId, experiments: rawFunnelManifest.experiments, docs: { schemaVersion: docsManifest.schemaVersion, bundleVersion: docsManifest.bundleVersion, stepContractVersion: docsManifest.stepContractVersion, contractHash: docsManifest.contractHash, missing: [], changed: [], conflicts: [], }, }; }; export const validateFunnelProject = ( snapshot: FunnelStepContractProjectSnapshot = buildFunnelProjectSnapshot(), ): FunnelContractDiagnostic[] => { return validateFunnelStepContractSnapshot(snapshot, { mode: 'authoring' }); };