@contentful/experiences-validators 3.7.0-beta.0 → 3.7.0-dev-20250917T1203-0e23897.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -183,20 +183,20 @@ type BreakpointQuery = '*' | `>${number}px` | `<${number}px`;
183
183
  declare const BreakpointSchema: z.ZodObject<{
184
184
  id: z.ZodString;
185
185
  query: z.ZodEffects<z.ZodString, BreakpointQuery, string>;
186
- previewSize: z.ZodOptional<z.ZodString>;
186
+ previewSize: z.ZodString;
187
187
  displayName: z.ZodString;
188
188
  displayIcon: z.ZodOptional<z.ZodEnum<["desktop", "tablet", "mobile"]>>;
189
189
  }, "strict", z.ZodTypeAny, {
190
190
  id: string;
191
191
  query: BreakpointQuery;
192
+ previewSize: string;
192
193
  displayName: string;
193
- previewSize?: string | undefined;
194
194
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
195
195
  }, {
196
196
  id: string;
197
197
  query: string;
198
+ previewSize: string;
198
199
  displayName: string;
199
- previewSize?: string | undefined;
200
200
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
201
201
  }>;
202
202
  declare const BaseComponentTreeNodeSchema: z.ZodObject<{
@@ -337,32 +337,32 @@ declare const ComponentTreeSchema: z.ZodObject<{
337
337
  breakpoints: z.ZodEffects<z.ZodArray<z.ZodObject<{
338
338
  id: z.ZodString;
339
339
  query: z.ZodEffects<z.ZodString, BreakpointQuery, string>;
340
- previewSize: z.ZodOptional<z.ZodString>;
340
+ previewSize: z.ZodString;
341
341
  displayName: z.ZodString;
342
342
  displayIcon: z.ZodOptional<z.ZodEnum<["desktop", "tablet", "mobile"]>>;
343
343
  }, "strict", z.ZodTypeAny, {
344
344
  id: string;
345
345
  query: BreakpointQuery;
346
+ previewSize: string;
346
347
  displayName: string;
347
- previewSize?: string | undefined;
348
348
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
349
349
  }, {
350
350
  id: string;
351
351
  query: string;
352
+ previewSize: string;
352
353
  displayName: string;
353
- previewSize?: string | undefined;
354
354
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
355
355
  }>, "many">, {
356
356
  id: string;
357
357
  query: BreakpointQuery;
358
+ previewSize: string;
358
359
  displayName: string;
359
- previewSize?: string | undefined;
360
360
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
361
361
  }[], {
362
362
  id: string;
363
363
  query: string;
364
+ previewSize: string;
364
365
  displayName: string;
365
- previewSize?: string | undefined;
366
366
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
367
367
  }[]>;
368
368
  children: z.ZodArray<z.ZodType<ComponentTreeNode, z.ZodTypeDef, ComponentTreeNode>, "many">;
@@ -372,8 +372,8 @@ declare const ComponentTreeSchema: z.ZodObject<{
372
372
  breakpoints: {
373
373
  id: string;
374
374
  query: BreakpointQuery;
375
+ previewSize: string;
375
376
  displayName: string;
376
- previewSize?: string | undefined;
377
377
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
378
378
  }[];
379
379
  schemaVersion: "2023-09-28";
@@ -382,8 +382,8 @@ declare const ComponentTreeSchema: z.ZodObject<{
382
382
  breakpoints: {
383
383
  id: string;
384
384
  query: string;
385
+ previewSize: string;
385
386
  displayName: string;
386
- previewSize?: string | undefined;
387
387
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
388
388
  }[];
389
389
  schemaVersion: "2023-09-28";
@@ -424,16 +424,12 @@ type Parameter = z.infer<typeof ParameterSchema>;
424
424
  declare const VariableMappingSchema: z.ZodObject<{
425
425
  parameterId: z.ZodString;
426
426
  type: z.ZodLiteral<"ContentTypeMapping">;
427
- pathsByContentType: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodObject<{
427
+ pathsByContentType: z.ZodRecord<z.ZodString, z.ZodObject<{
428
428
  path: z.ZodString;
429
429
  }, "strip", z.ZodTypeAny, {
430
430
  path: string;
431
431
  }, {
432
432
  path: string;
433
- }>>, Record<string, {
434
- path: string;
435
- }>, Record<string, {
436
- path: string;
437
433
  }>>;
438
434
  }, "strip", z.ZodTypeAny, {
439
435
  type: "ContentTypeMapping";
@@ -551,7 +547,7 @@ declare const ParameterDefinitionSchema: z.ZodObject<{
551
547
  nodeId: string;
552
548
  }[] | undefined;
553
549
  }>;
554
- declare const ComponentSettingsSchema: z.ZodEffects<z.ZodObject<{
550
+ declare const ComponentSettingsSchema: z.ZodObject<{
555
551
  variableDefinitions: z.ZodRecord<z.ZodString, z.ZodObject<{
556
552
  displayName: z.ZodOptional<z.ZodString>;
557
553
  type: z.ZodEnum<["Text", "RichText", "Number", "Date", "Boolean", "Location", "Media", "Object", "Hyperlink", "Array", "Link"]>;
@@ -820,16 +816,12 @@ declare const ComponentSettingsSchema: z.ZodEffects<z.ZodObject<{
820
816
  variableMappings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
821
817
  parameterId: z.ZodString;
822
818
  type: z.ZodLiteral<"ContentTypeMapping">;
823
- pathsByContentType: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodObject<{
819
+ pathsByContentType: z.ZodRecord<z.ZodString, z.ZodObject<{
824
820
  path: z.ZodString;
825
821
  }, "strip", z.ZodTypeAny, {
826
822
  path: string;
827
823
  }, {
828
824
  path: string;
829
- }>>, Record<string, {
830
- path: string;
831
- }>, Record<string, {
832
- path: string;
833
825
  }>>;
834
826
  }, "strip", z.ZodTypeAny, {
835
827
  type: "ContentTypeMapping";
@@ -1038,142 +1030,8 @@ declare const ComponentSettingsSchema: z.ZodEffects<z.ZodObject<{
1038
1030
  }> | undefined;
1039
1031
  allowedVariableOverrides?: string[] | undefined;
1040
1032
  }[] | undefined;
1041
- }>, {
1042
- variableDefinitions: Record<string, {
1043
- type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
1044
- displayName?: string | undefined;
1045
- description?: string | undefined;
1046
- group?: string | undefined;
1047
- defaultValue?: string | number | boolean | Record<any, any> | {
1048
- type: "DesignValue";
1049
- valuesByBreakpoint: Record<string, string | number | boolean | Record<any, any> | undefined>;
1050
- } | {
1051
- path: string;
1052
- type: "BoundValue";
1053
- } | {
1054
- type: "HyperlinkValue";
1055
- linkTargetKey: string;
1056
- overrides?: {} | undefined;
1057
- } | {
1058
- type: "UnboundValue";
1059
- key: string;
1060
- } | {
1061
- type: "ComponentValue";
1062
- key: string;
1063
- } | {
1064
- type: "NoValue";
1065
- } | undefined;
1066
- validations?: {
1067
- required?: boolean | undefined;
1068
- bindingSourceType?: ["entry" | "asset" | "manual" | "experience", ...("entry" | "asset" | "manual" | "experience")[]] | undefined;
1069
- format?: "URL" | undefined;
1070
- in?: {
1071
- value: string | number;
1072
- displayName?: string | undefined;
1073
- }[] | undefined;
1074
- } | undefined;
1075
- }>;
1076
- thumbnailId?: "columns" | "columnsPlusRight" | "imagesSquare" | "subtitles" | "rowsPlusBottom" | "userRectangle" | "textbox" | "monitorPlay" | "article" | "table" | "star" | "heartStraight" | "frameCorners" | "rows" | "dotsThreeOutline" | "listDashes" | "checkerBoard" | "gridFour" | "slideshow" | "diamondsFour" | "cards" | "textColumns" | "duplex" | undefined;
1077
- category?: string | undefined;
1078
- prebindingDefinitions?: {
1079
- id: string;
1080
- parameterDefinitions: Record<string, {
1081
- contentTypes: string[];
1082
- defaultSource?: {
1083
- type: "Entry";
1084
- contentTypeId: string;
1085
- link: {
1086
- sys: {
1087
- type: "Link";
1088
- id: string;
1089
- linkType: "Entry";
1090
- };
1091
- };
1092
- } | undefined;
1093
- passToNodes?: {
1094
- prebindingId: string;
1095
- parameterId: string;
1096
- nodeId: string;
1097
- }[] | undefined;
1098
- }>;
1099
- variableMappings?: Record<string, {
1100
- type: "ContentTypeMapping";
1101
- parameterId: string;
1102
- pathsByContentType: Record<string, {
1103
- path: string;
1104
- }>;
1105
- }> | undefined;
1106
- allowedVariableOverrides?: string[] | undefined;
1107
- }[] | undefined;
1108
- }, {
1109
- variableDefinitions: Record<string, {
1110
- type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
1111
- displayName?: string | undefined;
1112
- description?: string | undefined;
1113
- group?: string | undefined;
1114
- defaultValue?: string | number | boolean | Record<any, any> | {
1115
- type: "DesignValue";
1116
- valuesByBreakpoint: Record<string, string | number | boolean | Record<any, any> | undefined>;
1117
- } | {
1118
- path: string;
1119
- type: "BoundValue";
1120
- } | {
1121
- type: "HyperlinkValue";
1122
- linkTargetKey: string;
1123
- overrides?: {} | undefined;
1124
- } | {
1125
- type: "UnboundValue";
1126
- key: string;
1127
- } | {
1128
- type: "ComponentValue";
1129
- key: string;
1130
- } | {
1131
- type: "NoValue";
1132
- } | undefined;
1133
- validations?: {
1134
- required?: boolean | undefined;
1135
- bindingSourceType?: ["entry" | "asset" | "manual" | "experience", ...("entry" | "asset" | "manual" | "experience")[]] | undefined;
1136
- format?: "URL" | undefined;
1137
- in?: {
1138
- value: string | number;
1139
- displayName?: string | undefined;
1140
- }[] | undefined;
1141
- } | undefined;
1142
- }>;
1143
- thumbnailId?: "columns" | "columnsPlusRight" | "imagesSquare" | "subtitles" | "rowsPlusBottom" | "userRectangle" | "textbox" | "monitorPlay" | "article" | "table" | "star" | "heartStraight" | "frameCorners" | "rows" | "dotsThreeOutline" | "listDashes" | "checkerBoard" | "gridFour" | "slideshow" | "diamondsFour" | "cards" | "textColumns" | "duplex" | undefined;
1144
- category?: string | undefined;
1145
- prebindingDefinitions?: {
1146
- id: string;
1147
- parameterDefinitions: Record<string, {
1148
- contentTypes: string[];
1149
- defaultSource?: {
1150
- type: "Entry";
1151
- contentTypeId: string;
1152
- link: {
1153
- sys: {
1154
- type: "Link";
1155
- id: string;
1156
- linkType: "Entry";
1157
- };
1158
- };
1159
- } | undefined;
1160
- passToNodes?: {
1161
- prebindingId: string;
1162
- parameterId: string;
1163
- nodeId: string;
1164
- }[] | undefined;
1165
- }>;
1166
- variableMappings?: Record<string, {
1167
- type: "ContentTypeMapping";
1168
- parameterId: string;
1169
- pathsByContentType: Record<string, {
1170
- path: string;
1171
- }>;
1172
- }> | undefined;
1173
- allowedVariableOverrides?: string[] | undefined;
1174
- }[] | undefined;
1175
1033
  }>;
1176
- declare const PatternFieldsCMAShapeSchema: z.ZodEffects<z.ZodObject<{
1034
+ declare const PatternFieldsCMAShapeSchema: z.ZodObject<{
1177
1035
  componentTree: z.ZodRecord<z.ZodString, z.ZodTypeAny>;
1178
1036
  dataSource: z.ZodRecord<z.ZodString, z.ZodTypeAny>;
1179
1037
  unboundValues: z.ZodRecord<z.ZodString, z.ZodTypeAny>;
@@ -1191,18 +1049,6 @@ declare const PatternFieldsCMAShapeSchema: z.ZodEffects<z.ZodObject<{
1191
1049
  unboundValues: Record<string, any>;
1192
1050
  componentSettings: Record<string, any>;
1193
1051
  usedComponents?: Record<string, any> | undefined;
1194
- }>, {
1195
- componentTree: Record<string, any>;
1196
- dataSource: Record<string, any>;
1197
- unboundValues: Record<string, any>;
1198
- componentSettings: Record<string, any>;
1199
- usedComponents?: Record<string, any> | undefined;
1200
- }, {
1201
- componentTree: Record<string, any>;
1202
- dataSource: Record<string, any>;
1203
- unboundValues: Record<string, any>;
1204
- componentSettings: Record<string, any>;
1205
- usedComponents?: Record<string, any> | undefined;
1206
1052
  }>;
1207
1053
  type PatternFields = z.infer<typeof PatternFieldsCMAShapeSchema>;
1208
1054
  type ParameterDefinition = z.infer<typeof ParameterDefinitionSchema>;
@@ -1547,7 +1393,7 @@ type ValidatorReturnValue = {
1547
1393
  errors?: ContentfulErrorDetails[];
1548
1394
  };
1549
1395
 
1550
- declare const validateBreakpointsDefinition: (breakpoints: Breakpoint[]) => ValidatorReturnValue;
1396
+ declare const validateBreakpointsDefinition: (breakpoints: any) => ValidatorReturnValue;
1551
1397
 
1552
1398
  declare const validateComponentDefinition: (definition: any) => ValidatorReturnValue;
1553
1399
 
package/dist/index.js CHANGED
@@ -193,7 +193,7 @@ const BreakpointSchema = z
193
193
  id: propertyKeySchema,
194
194
  // Can be replace with z.templateLiteral when upgrading to zod v4
195
195
  query: z.string().refine((s) => BREAKPOINT_QUERY_REGEX.test(s)),
196
- previewSize: z.string().optional(),
196
+ previewSize: z.string(),
197
197
  displayName: z.string(),
198
198
  displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
199
199
  })
@@ -247,25 +247,6 @@ const ExperienceFieldsCMAShapeSchema = z.object({
247
247
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
248
248
  });
249
249
 
250
- function treeVisit(initialNode, onNode) {
251
- const _treeVisit = (currentNode) => {
252
- const children = [...currentNode.children];
253
- onNode(currentNode);
254
- for (const child of children) {
255
- _treeVisit(child);
256
- }
257
- };
258
- if (Array.isArray(initialNode)) {
259
- for (const node of initialNode) {
260
- _treeVisit(node);
261
- }
262
- }
263
- else {
264
- _treeVisit(initialNode);
265
- }
266
- }
267
-
268
- const MAX_ALLOWED_PATHS = 200;
269
250
  const THUMBNAIL_IDS = [
270
251
  'columns',
271
252
  'columnsPlusRight',
@@ -296,17 +277,7 @@ const THUMBNAIL_IDS = [
296
277
  const VariableMappingSchema = z.object({
297
278
  parameterId: propertyKeySchema,
298
279
  type: z.literal('ContentTypeMapping'),
299
- pathsByContentType: z
300
- .record(z.string(), z.object({ path: z.string() }))
301
- .superRefine((paths, ctx) => {
302
- const variableId = ctx.path[ctx.path.length - 2];
303
- if (Object.keys(paths).length > MAX_ALLOWED_PATHS) {
304
- ctx.addIssue({
305
- code: z.ZodIssueCode.custom,
306
- message: `Too many paths defined for variable mapping with id "${variableId}", maximum allowed is ${MAX_ALLOWED_PATHS}`,
307
- });
308
- }
309
- }),
280
+ pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
310
281
  });
311
282
  const PassToNodeSchema = z
312
283
  .object({
@@ -330,10 +301,7 @@ const ParameterDefinitionSchema = z.object({
330
301
  })
331
302
  .optional(),
332
303
  contentTypes: z.array(z.string()).min(1),
333
- passToNodes: z
334
- .array(PassToNodeSchema)
335
- .max(1, 'At most one "passToNodes" element is allowed per parameter definition.')
336
- .optional(), // we might change this to be empty array for native parameter definitions, that's why we don't use .length(1)
304
+ passToNodes: z.array(PassToNodeSchema).optional(),
337
305
  });
338
306
  const ParameterDefinitionsSchema = z.record(propertyKeySchema, ParameterDefinitionSchema);
339
307
  const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
@@ -354,108 +322,14 @@ const ComponentSettingsSchema = z
354
322
  category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
355
323
  prebindingDefinitions: z.array(PrebindingDefinitionSchema).length(1).optional(),
356
324
  })
357
- .strict()
358
- .superRefine((componentSettings, ctx) => {
359
- const { variableDefinitions, prebindingDefinitions } = componentSettings;
360
- if (!prebindingDefinitions || prebindingDefinitions.length === 0) {
361
- return;
362
- }
363
- const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions[0];
364
- validateAtMostOneNativeParameterDefinition(parameterDefinitions, ctx);
365
- validateNoOverlapBetweenMappingAndOverrides(variableMappings, allowedVariableOverrides, ctx);
366
- validateMappingsAgainstVariableDefinitions(variableMappings, allowedVariableOverrides, variableDefinitions, ctx);
367
- validateMappingsAgainstParameterDefinitions(variableMappings, parameterDefinitions, ctx);
368
- });
369
- const PatternFieldsCMAShapeSchema = z
370
- .object({
325
+ .strict();
326
+ const PatternFieldsCMAShapeSchema = z.object({
371
327
  componentTree: localeWrapper(ComponentTreeSchema),
372
328
  dataSource: localeWrapper(DataSourceSchema),
373
329
  unboundValues: localeWrapper(UnboundValuesSchema),
374
330
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
375
331
  componentSettings: localeWrapper(ComponentSettingsSchema),
376
- })
377
- .superRefine((patternFields, ctx) => {
378
- const { componentTree, componentSettings } = patternFields;
379
- // values at this point are wrapped under locale code
380
- const nonLocalisedComponentTree = Object.values(componentTree)[0];
381
- const nonLocalisedComponentSettings = Object.values(componentSettings)[0];
382
- if (!nonLocalisedComponentSettings || !nonLocalisedComponentTree) {
383
- return;
384
- }
385
- validatePassToNodes(nonLocalisedComponentTree.children || [], nonLocalisedComponentSettings || {}, ctx);
386
332
  });
387
- const validateAtMostOneNativeParameterDefinition = (parameterDefinitions, ctx) => {
388
- const nativeParamDefinitions = Object.values(parameterDefinitions).filter((paramDefinition) => !(paramDefinition.passToNodes && paramDefinition.passToNodes.length > 0));
389
- if (nativeParamDefinitions.length > 1) {
390
- ctx.addIssue({
391
- code: z.ZodIssueCode.custom,
392
- message: `Only one native parameter definition (parameter definition without passToNodes) is allowed per prebinding definition.`,
393
- });
394
- }
395
- };
396
- const validateNoOverlapBetweenMappingAndOverrides = (variableMappings, allowedVariableOverrides, ctx) => {
397
- const variableMappingKeys = Object.keys(variableMappings || {});
398
- const overridesSet = new Set(allowedVariableOverrides || []);
399
- const overlap = variableMappingKeys.filter((key) => overridesSet.has(key));
400
- if (overlap.length > 0) {
401
- ctx.addIssue({
402
- code: z.ZodIssueCode.custom,
403
- message: `Found both variable mapping and allowed override for the following keys: ${overlap.map((key) => `"${key}"`).join(', ')}.`,
404
- });
405
- }
406
- };
407
- const validateMappingsAgainstVariableDefinitions = (variableMappings, allowedVariableOverrides, variableDefinitions, ctx) => {
408
- const nonDesignVariableDefinitionKeys = Object.entries(variableDefinitions)
409
- .filter(([_, def]) => def.group !== 'style')
410
- .map(([key]) => key);
411
- const variableMappingKeys = Object.keys(variableMappings || {});
412
- const allKeys = [...variableMappingKeys, ...(allowedVariableOverrides || [])];
413
- const invalidMappings = allKeys.filter((key) => !nonDesignVariableDefinitionKeys.includes(key));
414
- if (invalidMappings.length > 0) {
415
- ctx.addIssue({
416
- code: z.ZodIssueCode.custom,
417
- message: `The following variable mappings or overrides are missing from the variable definitions: ${invalidMappings.map((key) => `"${key}"`).join(', ')}.`,
418
- });
419
- }
420
- };
421
- const validateMappingsAgainstParameterDefinitions = (variableMappings, parameterDefinitions, ctx) => {
422
- const parameterDefinitionKeys = Object.keys(parameterDefinitions || {});
423
- for (const [mappingKey, mappingValue] of Object.entries(variableMappings || {})) {
424
- if (!parameterDefinitionKeys.includes(mappingValue.parameterId)) {
425
- ctx.addIssue({
426
- code: z.ZodIssueCode.custom,
427
- message: `The variable mapping with id "${mappingKey}" references a non-existing parameterId "${mappingValue.parameterId}".`,
428
- });
429
- }
430
- }
431
- };
432
- const validatePassToNodes = (rootChildren, componentSettings, ctx) => {
433
- if (!componentSettings.prebindingDefinitions ||
434
- componentSettings.prebindingDefinitions.length === 0) {
435
- return;
436
- }
437
- const { parameterDefinitions } = componentSettings.prebindingDefinitions[0];
438
- let nodeIds = new Set();
439
- for (const paramDef of Object.values(parameterDefinitions || {})) {
440
- paramDef.passToNodes?.forEach((n) => nodeIds.add(n.nodeId));
441
- }
442
- treeVisit(rootChildren, (node) => {
443
- if (!node.id)
444
- return;
445
- if (nodeIds.has(node.id)) {
446
- nodeIds.delete(node.id);
447
- }
448
- });
449
- if (nodeIds.size > 0) {
450
- const stringifiedNodeIds = Array.from(nodeIds)
451
- .map((id) => `"${id}"`)
452
- .join(', ');
453
- ctx.addIssue({
454
- code: z.ZodIssueCode.custom,
455
- message: `The following node IDs referenced in passToNodes are not present in the component tree: ${stringifiedNodeIds}.`,
456
- });
457
- }
458
- };
459
333
 
460
334
  const ComponentDefinitionSchema = z
461
335
  .object({