"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }

var _chunkGERCMTPQjs = require('./chunk-GERCMTPQ.js');


var _chunkHOY77YBFjs = require('./chunk-HOY77YBF.js');




var _chunkEGTDJ4PLjs = require('./chunk-EGTDJ4PL.js');

// src/config/validation.ts
var _zod = require('zod');

// src/config/content-validation.ts

var jsonDataSchema = _zod.z.record(_zod.z.string(), _zod.z.any());
var contentTypeKeySchema = _zod.z.string().min(1).regex(
  /^[a-z][a-z0-9-]*$/,
  "Key must be lowercase, start with a letter, and contain only letters, numbers, and hyphens"
);
var contentTypeConfigSchema = _zod.z.object({
  key: contentTypeKeySchema,
  name: _zod.z.string().min(1),
  description: _zod.z.string().optional(),
  hasPages: _zod.z.boolean(),
  routePattern: _zod.z.string().optional(),
  // Fields are validated as any[] here - deep field validation happens in @riverbankcms/blocks
  fields: _zod.z.array(_zod.z.any()).min(1, "At least one field is required"),
  titleField: _zod.z.string().optional()
}).refine(
  (data) => {
    if (data.hasPages) {
      return data.routePattern && data.routePattern.includes("{slug}");
    }
    return true;
  },
  { message: "routePattern with {slug} is required when hasPages is true" }
).refine(
  (data) => {
    if (!data.hasPages && data.routePattern) {
      return false;
    }
    return true;
  },
  { message: "routePattern must not be defined when hasPages is false" }
);
var blockKindSchema = _zod.z.string().refine(
  (kind) => {
    if (_chunkGERCMTPQjs.SYSTEM_BLOCK_KINDS.includes(kind)) {
      return true;
    }
    if (kind.startsWith("custom.") && kind.length > 7) {
      return true;
    }
    return false;
  },
  {
    message: 'Block kind must be a system block (e.g., "block.hero") or a custom block (e.g., "custom.myBlock")'
  }
);
var blockConfigSchema = _zod.z.object({
  kind: blockKindSchema,
  content: jsonDataSchema,
  orderIndex: _zod.z.number().optional()
});
var pageConfigSchema = _zod.z.object({
  identifier: _zod.z.string().min(1, "Identifier is required"),
  title: _zod.z.string().min(1, "Title is required"),
  path: _zod.z.string().regex(/^\//, "Path must start with /"),
  purpose: _zod.z.string().default("content"),
  blocks: _zod.z.array(blockConfigSchema).optional(),
  status: _zod.z.enum(["draft", "published"]).default("draft"),
  metaTitle: _zod.z.string().optional(),
  metaDescription: _zod.z.string().optional()
});
var entryConfigSchema = _zod.z.object({
  identifier: _zod.z.string().min(1, "Identifier is required"),
  contentType: _zod.z.string().min(1, "Content type is required"),
  data: jsonDataSchema,
  status: _zod.z.enum(["draft", "published"]).default("draft"),
  slug: _zod.z.string().optional(),
  title: _zod.z.string().optional(),
  summary: _zod.z.string().optional(),
  metaTitle: _zod.z.string().optional(),
  metaDescription: _zod.z.string().optional()
});
var pageLinkSchema = _zod.z.object({
  kind: _zod.z.literal("page"),
  identifier: _zod.z.string().min(1)
});
var entryLinkSchema = _zod.z.object({
  kind: _zod.z.literal("entry"),
  identifier: _zod.z.string().min(1)
});
var externalLinkSchema = _zod.z.object({
  kind: _zod.z.literal("external"),
  href: _zod.z.string().url("Invalid URL")
});
var dropdownLinkSchema = _zod.z.object({
  kind: _zod.z.literal("dropdown")
});
var navigationLinkSchema = _zod.z.discriminatedUnion("kind", [
  pageLinkSchema,
  entryLinkSchema,
  externalLinkSchema,
  dropdownLinkSchema
]);
var baseNavigationItemSchema = _zod.z.object({
  label: _zod.z.string().min(1, "Label is required"),
  link: navigationLinkSchema,
  isCta: _zod.z.boolean().optional()
});
var navigationItemConfigSchema = baseNavigationItemSchema.extend({
  children: _zod.z.lazy(() => _zod.z.array(navigationItemConfigSchema)).optional()
});
var navigationMenuConfigSchema = _zod.z.object({
  identifier: _zod.z.string().min(1, "Identifier is required"),
  name: _zod.z.string().min(1, "Name is required"),
  isPrimary: _zod.z.boolean().optional(),
  items: _zod.z.array(navigationItemConfigSchema)
});
var siteSettingsConfigSchema = _zod.z.object({
  homepagePath: _zod.z.string().optional(),
  siteTitle: _zod.z.string().optional(),
  siteDescription: _zod.z.string().optional(),
  defaultTemplates: _zod.z.record(_zod.z.string(), _zod.z.string()).optional()
});
var contentConfigBaseSchema = _zod.z.object({
  contentTypes: _zod.z.array(contentTypeConfigSchema).optional(),
  entries: _zod.z.array(entryConfigSchema).optional(),
  pages: _zod.z.array(pageConfigSchema).optional(),
  navigationMenus: _zod.z.array(navigationMenuConfigSchema).optional(),
  settings: siteSettingsConfigSchema.optional()
});
var contentConfigSchema = contentConfigBaseSchema.superRefine((data, ctx) => {
  if (data.contentTypes && data.contentTypes.length > 1) {
    const keys = data.contentTypes.map((ct) => ct.key);
    const duplicateKeys = keys.filter((key, i) => keys.indexOf(key) !== i);
    if (duplicateKeys.length > 0) {
      ctx.addIssue({
        code: _zod.z.ZodIssueCode.custom,
        message: `Content type keys must be unique. Duplicates: ${duplicateKeys.join(", ")}`,
        path: ["contentTypes"]
      });
    }
  }
  if (data.pages && data.pages.length > 1) {
    const identifiers = data.pages.map((p) => p.identifier);
    const duplicateIds = identifiers.filter((id, i) => identifiers.indexOf(id) !== i);
    if (duplicateIds.length > 0) {
      ctx.addIssue({
        code: _zod.z.ZodIssueCode.custom,
        message: `Page identifiers must be unique. Duplicates: ${duplicateIds.join(", ")}`,
        path: ["pages"]
      });
    }
    const paths = data.pages.map((p) => p.path);
    const duplicatePaths = paths.filter((path, i) => paths.indexOf(path) !== i);
    if (duplicatePaths.length > 0) {
      ctx.addIssue({
        code: _zod.z.ZodIssueCode.custom,
        message: `Page paths must be unique. Duplicates: ${duplicatePaths.join(", ")}`,
        path: ["pages"]
      });
    }
  }
  if (data.entries && data.entries.length > 1) {
    const identifiers = data.entries.map((e) => e.identifier);
    const duplicateIds = identifiers.filter((id, i) => identifiers.indexOf(id) !== i);
    if (duplicateIds.length > 0) {
      ctx.addIssue({
        code: _zod.z.ZodIssueCode.custom,
        message: `Entry identifiers must be unique. Duplicates: ${duplicateIds.join(", ")}`,
        path: ["entries"]
      });
    }
  }
  if (data.navigationMenus && data.navigationMenus.length > 1) {
    const identifiers = data.navigationMenus.map((m) => m.identifier);
    const duplicateIds = identifiers.filter((id, i) => identifiers.indexOf(id) !== i);
    if (duplicateIds.length > 0) {
      ctx.addIssue({
        code: _zod.z.ZodIssueCode.custom,
        message: `Navigation menu identifiers must be unique. Duplicates: ${duplicateIds.join(", ")}`,
        path: ["navigationMenus"]
      });
    }
  }
});

// src/config/validation.ts
var sdkThemePaletteSchema = _zod.z.record(_zod.z.string(), _zod.z.string());
var sdkThemeConfigSchema = _zod.z.object({
  palette: sdkThemePaletteSchema
});
var sectionBackgroundSchema = _zod.z.object({
  id: _zod.z.string(),
  label: _zod.z.string(),
  token: _zod.z.string()
  // Reference to theme palette token
});
var sectionSpacingSchema = _zod.z.enum(["compact", "default", "spacious"]);
var containerMaxWidthSchema = _zod.z.enum(["narrow", "default", "wide", "full"]);
var containerAlignmentSchema = _zod.z.enum(["left", "center", "right"]);
var sectionOptionsSchema = _zod.z.object({
  backgroundColor: _zod.z.boolean().optional(),
  backgroundImage: _zod.z.boolean().optional(),
  backgroundGradient: _zod.z.boolean().optional(),
  spacing: _zod.z.union([
    _zod.z.array(sectionSpacingSchema),
    _zod.z.boolean()
  ]).optional(),
  textColor: _zod.z.boolean().optional()
}).optional();
var containerOptionsSchema = _zod.z.object({
  maxWidth: _zod.z.union([
    _zod.z.array(containerMaxWidthSchema),
    _zod.z.boolean()
  ]).optional(),
  alignment: _zod.z.union([
    _zod.z.array(containerAlignmentSchema),
    _zod.z.boolean()
  ]).optional()
}).optional();
var siteStyleConfigSchema = _zod.z.object({
  sectionBackgrounds: _zod.z.array(sectionBackgroundSchema).optional(),
  sectionOptions: sectionOptionsSchema,
  containerOptions: containerOptionsSchema
}).optional();
var sdkLoaderEndpointSchema = _zod.z.enum(_chunkHOY77YBFjs.SUPPORTED_LOADER_ENDPOINTS);
var loaderParamBindingSchema = _zod.z.object({
  $bind: _zod.z.object({
    from: _zod.z.string().min(1, "Binding path is required"),
    fallback: _zod.z.string().optional()
  })
});
var loaderParamValueSchema = _zod.z.union([
  _zod.z.string(),
  _zod.z.number(),
  _zod.z.boolean(),
  loaderParamBindingSchema
]);
var sdkConfigLoaderSchema = _zod.z.object({
  endpoint: sdkLoaderEndpointSchema,
  params: _zod.z.record(_zod.z.string(), loaderParamValueSchema),
  mode: _zod.z.enum(["server", "client"]).default("server")
});
var sdkDataLoadersSchema = _zod.z.record(_zod.z.string(), sdkConfigLoaderSchema).refine(
  (loaders) => Object.keys(loaders).length <= 5,
  { message: "Maximum 5 data loaders per block" }
).optional();
var fieldSelectOptionSchema = _zod.z.object({
  value: _zod.z.string().min(1, "Option value is required"),
  label: _zod.z.string().min(1, "Option label is required")
});
var blockFieldConfigSchema = _zod.z.object({
  options: _zod.z.array(fieldSelectOptionSchema).min(1, "At least one option is required").optional()
});
var blockFieldOptionsSchema = _zod.z.record(
  _zod.z.string().regex(/^(block\.|custom\.)[a-z][a-z0-9-]*$/, {
    message: "Block ID must be 'block.*' or 'custom.*' format"
  }),
  _zod.z.record(
    _zod.z.string().min(1, "Field ID is required"),
    blockFieldConfigSchema
  )
).optional();
var blockFieldExtensionSchema = _zod.z.object({
  fields: _chunkEGTDJ4PLjs.fieldSchema.array().min(1, "At least one field is required")
}).refine(
  (data) => {
    return data.fields.every((field) => {
      if (!field.required) return true;
      return field.defaultValue !== void 0;
    });
  },
  {
    message: "Required fields must have a defaultValue to support existing blocks"
  }
);
var blockFieldExtensionsSchema = _zod.z.record(
  _zod.z.string().regex(/^block\.[a-z][a-zA-Z0-9]*$/, {
    message: "Block ID must be 'block.*' format (system blocks only)"
  }),
  blockFieldExtensionSchema
).optional();
function validateFieldIdConflicts(blockFieldExtensions) {
  if (!blockFieldExtensions) return [];
  const conflicts = [];
  for (const [blockId, extension] of Object.entries(blockFieldExtensions)) {
    const definition = _chunkEGTDJ4PLjs.getBlockDefinition.call(void 0, blockId);
    if (!definition) {
      conflicts.push({
        blockId,
        fieldId: "",
        message: `Unknown block type: ${blockId}`
      });
      continue;
    }
    const existingFieldIds = /* @__PURE__ */ new Set();
    const collectFieldIds = (fields) => {
      if (!fields) return;
      for (const field of fields) {
        existingFieldIds.add(field.id);
        if (field.type === "group" || field.type === "modal") {
          collectFieldIds(_optionalChain([field, 'access', _ => _.schema, 'optionalAccess', _2 => _2.fields]));
        } else if (field.type === "repeater" && _optionalChain([field, 'access', _3 => _3.schema, 'optionalAccess', _4 => _4.fields])) {
          collectFieldIds(field.schema.fields);
        } else if (field.type === "tabGroup") {
          for (const tab of _nullishCoalesce(field.tabs, () => ( []))) {
            collectFieldIds(tab.fields);
          }
        }
      }
    };
    collectFieldIds(definition.manifest.fields);
    for (const field of extension.fields) {
      if (existingFieldIds.has(field.id)) {
        conflicts.push({
          blockId,
          fieldId: field.id,
          message: `Field ID "${field.id}" conflicts with existing field in ${blockId}`
        });
      }
    }
  }
  return conflicts;
}
var sdkCustomBlockSchema = _zod.z.object({
  // Block ID must start with 'custom.'
  id: _zod.z.string().min(8).regex(/^custom\.[a-z][a-z0-9-]*$/, {
    message: "Block ID must start with 'custom.' followed by lowercase letters, numbers, or hyphens"
  }),
  title: _zod.z.string().min(1, "Title is required"),
  titleSource: _zod.z.string().optional(),
  description: _zod.z.string().optional(),
  category: _chunkEGTDJ4PLjs.blockCategoryEnum,
  icon: _zod.z.string().optional(),
  tags: _zod.z.array(_zod.z.string()).optional(),
  // Reuse the exact field schema from @riverbankcms/blocks - all field types supported
  fields: _chunkEGTDJ4PLjs.fieldSchema.array().min(1, "Custom blocks must have at least one field"),
  // Data loaders for CMS endpoints
  dataLoaders: sdkDataLoadersSchema
}).refine(
  // Validate titleSource references a valid field if provided
  (data) => {
    if (!data.titleSource) return true;
    return data.fields.some((f) => f.id === data.titleSource);
  },
  {
    message: "titleSource must reference a valid field ID",
    path: ["titleSource"]
  }
);
var riverbankSiteConfigSchema = _zod.z.object({
  siteId: _zod.z.string().uuid(),
  theme: sdkThemeConfigSchema.optional(),
  styles: siteStyleConfigSchema,
  customBlocks: _zod.z.array(sdkCustomBlockSchema).max(20, "Maximum 20 custom blocks per site").refine(
    // Ensure unique block IDs
    (blocks) => {
      const ids = blocks.map((b) => b.id);
      return ids.length === new Set(ids).size;
    },
    { message: "Block IDs must be unique" }
  ).optional(),
  blockFieldOptions: blockFieldOptionsSchema,
  blockFieldExtensions: blockFieldExtensionsSchema,
  content: contentConfigSchema.optional()
}).strict();
































exports.contentTypeConfigSchema = contentTypeConfigSchema; exports.blockConfigSchema = blockConfigSchema; exports.pageConfigSchema = pageConfigSchema; exports.entryConfigSchema = entryConfigSchema; exports.navigationItemConfigSchema = navigationItemConfigSchema; exports.navigationMenuConfigSchema = navigationMenuConfigSchema; exports.siteSettingsConfigSchema = siteSettingsConfigSchema; exports.contentConfigSchema = contentConfigSchema; exports.sdkThemePaletteSchema = sdkThemePaletteSchema; exports.sdkThemeConfigSchema = sdkThemeConfigSchema; exports.sectionBackgroundSchema = sectionBackgroundSchema; exports.sectionSpacingSchema = sectionSpacingSchema; exports.containerMaxWidthSchema = containerMaxWidthSchema; exports.containerAlignmentSchema = containerAlignmentSchema; exports.sectionOptionsSchema = sectionOptionsSchema; exports.containerOptionsSchema = containerOptionsSchema; exports.siteStyleConfigSchema = siteStyleConfigSchema; exports.sdkLoaderEndpointSchema = sdkLoaderEndpointSchema; exports.loaderParamBindingSchema = loaderParamBindingSchema; exports.loaderParamValueSchema = loaderParamValueSchema; exports.sdkConfigLoaderSchema = sdkConfigLoaderSchema; exports.sdkDataLoadersSchema = sdkDataLoadersSchema; exports.fieldSelectOptionSchema = fieldSelectOptionSchema; exports.blockFieldConfigSchema = blockFieldConfigSchema; exports.blockFieldOptionsSchema = blockFieldOptionsSchema; exports.blockFieldExtensionSchema = blockFieldExtensionSchema; exports.blockFieldExtensionsSchema = blockFieldExtensionsSchema; exports.validateFieldIdConflicts = validateFieldIdConflicts; exports.sdkCustomBlockSchema = sdkCustomBlockSchema; exports.riverbankSiteConfigSchema = riverbankSiteConfigSchema;
//# sourceMappingURL=chunk-ZIM53VP6.js.map