@contentful/experiences-visual-editor-react 3.7.0-dev-20250917T1203-0e23897.0 → 3.7.0-dev-20250917T1357-4fbbff5.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/renderApp.js CHANGED
@@ -44272,6 +44272,25 @@ z.object({
44272
44272
  usedComponents: localeWrapper$1(UsedComponentsSchema$1).optional(),
44273
44273
  });
44274
44274
 
44275
+ function treeVisit$1$1(initialNode, onNode) {
44276
+ const _treeVisit = (currentNode) => {
44277
+ const children = [...currentNode.children];
44278
+ onNode(currentNode);
44279
+ for (const child of children) {
44280
+ _treeVisit(child);
44281
+ }
44282
+ };
44283
+ if (Array.isArray(initialNode)) {
44284
+ for (const node of initialNode) {
44285
+ _treeVisit(node);
44286
+ }
44287
+ }
44288
+ else {
44289
+ _treeVisit(initialNode);
44290
+ }
44291
+ }
44292
+
44293
+ const MAX_ALLOWED_PATHS$1 = 200;
44275
44294
  const THUMBNAIL_IDS$1 = [
44276
44295
  'columns',
44277
44296
  'columnsPlusRight',
@@ -44302,7 +44321,17 @@ const THUMBNAIL_IDS$1 = [
44302
44321
  const VariableMappingSchema$1 = z.object({
44303
44322
  parameterId: propertyKeySchema$1,
44304
44323
  type: z.literal('ContentTypeMapping'),
44305
- pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
44324
+ pathsByContentType: z
44325
+ .record(z.string(), z.object({ path: z.string() }))
44326
+ .superRefine((paths, ctx) => {
44327
+ const variableId = ctx.path[ctx.path.length - 2];
44328
+ if (Object.keys(paths).length > MAX_ALLOWED_PATHS$1) {
44329
+ ctx.addIssue({
44330
+ code: z.ZodIssueCode.custom,
44331
+ message: `Too many paths defined for variable mapping with id "${variableId}", maximum allowed is ${MAX_ALLOWED_PATHS$1}`,
44332
+ });
44333
+ }
44334
+ }),
44306
44335
  });
44307
44336
  const PassToNodeSchema$1 = z
44308
44337
  .object({
@@ -44326,7 +44355,10 @@ const ParameterDefinitionSchema$1 = z.object({
44326
44355
  })
44327
44356
  .optional(),
44328
44357
  contentTypes: z.array(z.string()).min(1),
44329
- passToNodes: z.array(PassToNodeSchema$1).optional(),
44358
+ passToNodes: z
44359
+ .array(PassToNodeSchema$1)
44360
+ .max(1, 'At most one "passToNodes" element is allowed per parameter definition.')
44361
+ .optional(), // we might change this to be empty array for native parameter definitions, that's why we don't use .length(1)
44330
44362
  });
44331
44363
  const ParameterDefinitionsSchema$1 = z.record(propertyKeySchema$1, ParameterDefinitionSchema$1);
44332
44364
  const VariableMappingsSchema$1 = z.record(propertyKeySchema$1, VariableMappingSchema$1);
@@ -44347,14 +44379,108 @@ const ComponentSettingsSchema$1 = z
44347
44379
  category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
44348
44380
  prebindingDefinitions: z.array(PrebindingDefinitionSchema$1).length(1).optional(),
44349
44381
  })
44350
- .strict();
44351
- z.object({
44382
+ .strict()
44383
+ .superRefine((componentSettings, ctx) => {
44384
+ const { variableDefinitions, prebindingDefinitions } = componentSettings;
44385
+ if (!prebindingDefinitions || prebindingDefinitions.length === 0) {
44386
+ return;
44387
+ }
44388
+ const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions[0];
44389
+ validateAtMostOneNativeParameterDefinition$1(parameterDefinitions, ctx);
44390
+ validateNoOverlapBetweenMappingAndOverrides$1(variableMappings, allowedVariableOverrides, ctx);
44391
+ validateMappingsAgainstVariableDefinitions$1(variableMappings, allowedVariableOverrides, variableDefinitions, ctx);
44392
+ validateMappingsAgainstParameterDefinitions$1(variableMappings, parameterDefinitions, ctx);
44393
+ });
44394
+ z
44395
+ .object({
44352
44396
  componentTree: localeWrapper$1(ComponentTreeSchema$1),
44353
44397
  dataSource: localeWrapper$1(DataSourceSchema$1),
44354
44398
  unboundValues: localeWrapper$1(UnboundValuesSchema$1),
44355
44399
  usedComponents: localeWrapper$1(UsedComponentsSchema$1).optional(),
44356
44400
  componentSettings: localeWrapper$1(ComponentSettingsSchema$1),
44401
+ })
44402
+ .superRefine((patternFields, ctx) => {
44403
+ const { componentTree, componentSettings } = patternFields;
44404
+ // values at this point are wrapped under locale code
44405
+ const nonLocalisedComponentTree = Object.values(componentTree)[0];
44406
+ const nonLocalisedComponentSettings = Object.values(componentSettings)[0];
44407
+ if (!nonLocalisedComponentSettings || !nonLocalisedComponentTree) {
44408
+ return;
44409
+ }
44410
+ validatePassToNodes$1(nonLocalisedComponentTree.children || [], nonLocalisedComponentSettings || {}, ctx);
44357
44411
  });
44412
+ const validateAtMostOneNativeParameterDefinition$1 = (parameterDefinitions, ctx) => {
44413
+ const nativeParamDefinitions = Object.values(parameterDefinitions).filter((paramDefinition) => !(paramDefinition.passToNodes && paramDefinition.passToNodes.length > 0));
44414
+ if (nativeParamDefinitions.length > 1) {
44415
+ ctx.addIssue({
44416
+ code: z.ZodIssueCode.custom,
44417
+ message: `Only one native parameter definition (parameter definition without passToNodes) is allowed per prebinding definition.`,
44418
+ });
44419
+ }
44420
+ };
44421
+ const validateNoOverlapBetweenMappingAndOverrides$1 = (variableMappings, allowedVariableOverrides, ctx) => {
44422
+ const variableMappingKeys = Object.keys(variableMappings || {});
44423
+ const overridesSet = new Set(allowedVariableOverrides || []);
44424
+ const overlap = variableMappingKeys.filter((key) => overridesSet.has(key));
44425
+ if (overlap.length > 0) {
44426
+ ctx.addIssue({
44427
+ code: z.ZodIssueCode.custom,
44428
+ message: `Found both variable mapping and allowed override for the following keys: ${overlap.map((key) => `"${key}"`).join(', ')}.`,
44429
+ });
44430
+ }
44431
+ };
44432
+ const validateMappingsAgainstVariableDefinitions$1 = (variableMappings, allowedVariableOverrides, variableDefinitions, ctx) => {
44433
+ const nonDesignVariableDefinitionKeys = Object.entries(variableDefinitions)
44434
+ .filter(([_, def]) => def.group !== 'style')
44435
+ .map(([key]) => key);
44436
+ const variableMappingKeys = Object.keys(variableMappings || {});
44437
+ const allKeys = [...variableMappingKeys, ...(allowedVariableOverrides || [])];
44438
+ const invalidMappings = allKeys.filter((key) => !nonDesignVariableDefinitionKeys.includes(key));
44439
+ if (invalidMappings.length > 0) {
44440
+ ctx.addIssue({
44441
+ code: z.ZodIssueCode.custom,
44442
+ message: `The following variable mappings or overrides are missing from the variable definitions: ${invalidMappings.map((key) => `"${key}"`).join(', ')}.`,
44443
+ });
44444
+ }
44445
+ };
44446
+ const validateMappingsAgainstParameterDefinitions$1 = (variableMappings, parameterDefinitions, ctx) => {
44447
+ const parameterDefinitionKeys = Object.keys(parameterDefinitions || {});
44448
+ for (const [mappingKey, mappingValue] of Object.entries(variableMappings || {})) {
44449
+ if (!parameterDefinitionKeys.includes(mappingValue.parameterId)) {
44450
+ ctx.addIssue({
44451
+ code: z.ZodIssueCode.custom,
44452
+ message: `The variable mapping with id "${mappingKey}" references a non-existing parameterId "${mappingValue.parameterId}".`,
44453
+ });
44454
+ }
44455
+ }
44456
+ };
44457
+ const validatePassToNodes$1 = (rootChildren, componentSettings, ctx) => {
44458
+ if (!componentSettings.prebindingDefinitions ||
44459
+ componentSettings.prebindingDefinitions.length === 0) {
44460
+ return;
44461
+ }
44462
+ const { parameterDefinitions } = componentSettings.prebindingDefinitions[0];
44463
+ let nodeIds = new Set();
44464
+ for (const paramDef of Object.values(parameterDefinitions || {})) {
44465
+ paramDef.passToNodes?.forEach((n) => nodeIds.add(n.nodeId));
44466
+ }
44467
+ treeVisit$1$1(rootChildren, (node) => {
44468
+ if (!node.id)
44469
+ return;
44470
+ if (nodeIds.has(node.id)) {
44471
+ nodeIds.delete(node.id);
44472
+ }
44473
+ });
44474
+ if (nodeIds.size > 0) {
44475
+ const stringifiedNodeIds = Array.from(nodeIds)
44476
+ .map((id) => `"${id}"`)
44477
+ .join(', ');
44478
+ ctx.addIssue({
44479
+ code: z.ZodIssueCode.custom,
44480
+ message: `The following node IDs referenced in passToNodes are not present in the component tree: ${stringifiedNodeIds}.`,
44481
+ });
44482
+ }
44483
+ };
44358
44484
 
44359
44485
  z
44360
44486
  .object({
@@ -49055,6 +49181,25 @@ z.object({
49055
49181
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
49056
49182
  });
49057
49183
 
49184
+ function treeVisit$1(initialNode, onNode) {
49185
+ const _treeVisit = (currentNode) => {
49186
+ const children = [...currentNode.children];
49187
+ onNode(currentNode);
49188
+ for (const child of children) {
49189
+ _treeVisit(child);
49190
+ }
49191
+ };
49192
+ if (Array.isArray(initialNode)) {
49193
+ for (const node of initialNode) {
49194
+ _treeVisit(node);
49195
+ }
49196
+ }
49197
+ else {
49198
+ _treeVisit(initialNode);
49199
+ }
49200
+ }
49201
+
49202
+ const MAX_ALLOWED_PATHS = 200;
49058
49203
  const THUMBNAIL_IDS = [
49059
49204
  'columns',
49060
49205
  'columnsPlusRight',
@@ -49085,7 +49230,17 @@ const THUMBNAIL_IDS = [
49085
49230
  const VariableMappingSchema = z.object({
49086
49231
  parameterId: propertyKeySchema,
49087
49232
  type: z.literal('ContentTypeMapping'),
49088
- pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
49233
+ pathsByContentType: z
49234
+ .record(z.string(), z.object({ path: z.string() }))
49235
+ .superRefine((paths, ctx) => {
49236
+ const variableId = ctx.path[ctx.path.length - 2];
49237
+ if (Object.keys(paths).length > MAX_ALLOWED_PATHS) {
49238
+ ctx.addIssue({
49239
+ code: z.ZodIssueCode.custom,
49240
+ message: `Too many paths defined for variable mapping with id "${variableId}", maximum allowed is ${MAX_ALLOWED_PATHS}`,
49241
+ });
49242
+ }
49243
+ }),
49089
49244
  });
49090
49245
  const PassToNodeSchema = z
49091
49246
  .object({
@@ -49109,7 +49264,10 @@ const ParameterDefinitionSchema = z.object({
49109
49264
  })
49110
49265
  .optional(),
49111
49266
  contentTypes: z.array(z.string()).min(1),
49112
- passToNodes: z.array(PassToNodeSchema).optional(),
49267
+ passToNodes: z
49268
+ .array(PassToNodeSchema)
49269
+ .max(1, 'At most one "passToNodes" element is allowed per parameter definition.')
49270
+ .optional(), // we might change this to be empty array for native parameter definitions, that's why we don't use .length(1)
49113
49271
  });
49114
49272
  const ParameterDefinitionsSchema = z.record(propertyKeySchema, ParameterDefinitionSchema);
49115
49273
  const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
@@ -49130,14 +49288,108 @@ const ComponentSettingsSchema = z
49130
49288
  category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
49131
49289
  prebindingDefinitions: z.array(PrebindingDefinitionSchema).length(1).optional(),
49132
49290
  })
49133
- .strict();
49134
- z.object({
49291
+ .strict()
49292
+ .superRefine((componentSettings, ctx) => {
49293
+ const { variableDefinitions, prebindingDefinitions } = componentSettings;
49294
+ if (!prebindingDefinitions || prebindingDefinitions.length === 0) {
49295
+ return;
49296
+ }
49297
+ const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions[0];
49298
+ validateAtMostOneNativeParameterDefinition(parameterDefinitions, ctx);
49299
+ validateNoOverlapBetweenMappingAndOverrides(variableMappings, allowedVariableOverrides, ctx);
49300
+ validateMappingsAgainstVariableDefinitions(variableMappings, allowedVariableOverrides, variableDefinitions, ctx);
49301
+ validateMappingsAgainstParameterDefinitions(variableMappings, parameterDefinitions, ctx);
49302
+ });
49303
+ z
49304
+ .object({
49135
49305
  componentTree: localeWrapper(ComponentTreeSchema),
49136
49306
  dataSource: localeWrapper(DataSourceSchema),
49137
49307
  unboundValues: localeWrapper(UnboundValuesSchema),
49138
49308
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
49139
49309
  componentSettings: localeWrapper(ComponentSettingsSchema),
49310
+ })
49311
+ .superRefine((patternFields, ctx) => {
49312
+ const { componentTree, componentSettings } = patternFields;
49313
+ // values at this point are wrapped under locale code
49314
+ const nonLocalisedComponentTree = Object.values(componentTree)[0];
49315
+ const nonLocalisedComponentSettings = Object.values(componentSettings)[0];
49316
+ if (!nonLocalisedComponentSettings || !nonLocalisedComponentTree) {
49317
+ return;
49318
+ }
49319
+ validatePassToNodes(nonLocalisedComponentTree.children || [], nonLocalisedComponentSettings || {}, ctx);
49140
49320
  });
49321
+ const validateAtMostOneNativeParameterDefinition = (parameterDefinitions, ctx) => {
49322
+ const nativeParamDefinitions = Object.values(parameterDefinitions).filter((paramDefinition) => !(paramDefinition.passToNodes && paramDefinition.passToNodes.length > 0));
49323
+ if (nativeParamDefinitions.length > 1) {
49324
+ ctx.addIssue({
49325
+ code: z.ZodIssueCode.custom,
49326
+ message: `Only one native parameter definition (parameter definition without passToNodes) is allowed per prebinding definition.`,
49327
+ });
49328
+ }
49329
+ };
49330
+ const validateNoOverlapBetweenMappingAndOverrides = (variableMappings, allowedVariableOverrides, ctx) => {
49331
+ const variableMappingKeys = Object.keys(variableMappings || {});
49332
+ const overridesSet = new Set(allowedVariableOverrides || []);
49333
+ const overlap = variableMappingKeys.filter((key) => overridesSet.has(key));
49334
+ if (overlap.length > 0) {
49335
+ ctx.addIssue({
49336
+ code: z.ZodIssueCode.custom,
49337
+ message: `Found both variable mapping and allowed override for the following keys: ${overlap.map((key) => `"${key}"`).join(', ')}.`,
49338
+ });
49339
+ }
49340
+ };
49341
+ const validateMappingsAgainstVariableDefinitions = (variableMappings, allowedVariableOverrides, variableDefinitions, ctx) => {
49342
+ const nonDesignVariableDefinitionKeys = Object.entries(variableDefinitions)
49343
+ .filter(([_, def]) => def.group !== 'style')
49344
+ .map(([key]) => key);
49345
+ const variableMappingKeys = Object.keys(variableMappings || {});
49346
+ const allKeys = [...variableMappingKeys, ...(allowedVariableOverrides || [])];
49347
+ const invalidMappings = allKeys.filter((key) => !nonDesignVariableDefinitionKeys.includes(key));
49348
+ if (invalidMappings.length > 0) {
49349
+ ctx.addIssue({
49350
+ code: z.ZodIssueCode.custom,
49351
+ message: `The following variable mappings or overrides are missing from the variable definitions: ${invalidMappings.map((key) => `"${key}"`).join(', ')}.`,
49352
+ });
49353
+ }
49354
+ };
49355
+ const validateMappingsAgainstParameterDefinitions = (variableMappings, parameterDefinitions, ctx) => {
49356
+ const parameterDefinitionKeys = Object.keys(parameterDefinitions || {});
49357
+ for (const [mappingKey, mappingValue] of Object.entries(variableMappings || {})) {
49358
+ if (!parameterDefinitionKeys.includes(mappingValue.parameterId)) {
49359
+ ctx.addIssue({
49360
+ code: z.ZodIssueCode.custom,
49361
+ message: `The variable mapping with id "${mappingKey}" references a non-existing parameterId "${mappingValue.parameterId}".`,
49362
+ });
49363
+ }
49364
+ }
49365
+ };
49366
+ const validatePassToNodes = (rootChildren, componentSettings, ctx) => {
49367
+ if (!componentSettings.prebindingDefinitions ||
49368
+ componentSettings.prebindingDefinitions.length === 0) {
49369
+ return;
49370
+ }
49371
+ const { parameterDefinitions } = componentSettings.prebindingDefinitions[0];
49372
+ let nodeIds = new Set();
49373
+ for (const paramDef of Object.values(parameterDefinitions || {})) {
49374
+ paramDef.passToNodes?.forEach((n) => nodeIds.add(n.nodeId));
49375
+ }
49376
+ treeVisit$1(rootChildren, (node) => {
49377
+ if (!node.id)
49378
+ return;
49379
+ if (nodeIds.has(node.id)) {
49380
+ nodeIds.delete(node.id);
49381
+ }
49382
+ });
49383
+ if (nodeIds.size > 0) {
49384
+ const stringifiedNodeIds = Array.from(nodeIds)
49385
+ .map((id) => `"${id}"`)
49386
+ .join(', ');
49387
+ ctx.addIssue({
49388
+ code: z.ZodIssueCode.custom,
49389
+ message: `The following node IDs referenced in passToNodes are not present in the component tree: ${stringifiedNodeIds}.`,
49390
+ });
49391
+ }
49392
+ };
49141
49393
 
49142
49394
  z
49143
49395
  .object({