@contentful/experiences-core 3.6.2 → 3.7.0-prerelease-20250915T1724-8825648.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.js +129 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1052,6 +1052,25 @@ z.object({
|
|
|
1052
1052
|
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
1053
1053
|
});
|
|
1054
1054
|
|
|
1055
|
+
function treeVisit$1(initialNode, onNode) {
|
|
1056
|
+
const _treeVisit = (currentNode) => {
|
|
1057
|
+
const children = [...currentNode.children];
|
|
1058
|
+
onNode(currentNode);
|
|
1059
|
+
for (const child of children) {
|
|
1060
|
+
_treeVisit(child);
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
if (Array.isArray(initialNode)) {
|
|
1064
|
+
for (const node of initialNode) {
|
|
1065
|
+
_treeVisit(node);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
else {
|
|
1069
|
+
_treeVisit(initialNode);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
const MAX_ALLOWED_PATHS = 200;
|
|
1055
1074
|
const THUMBNAIL_IDS = [
|
|
1056
1075
|
'columns',
|
|
1057
1076
|
'columnsPlusRight',
|
|
@@ -1082,7 +1101,17 @@ const THUMBNAIL_IDS = [
|
|
|
1082
1101
|
const VariableMappingSchema = z.object({
|
|
1083
1102
|
parameterId: propertyKeySchema,
|
|
1084
1103
|
type: z.literal('ContentTypeMapping'),
|
|
1085
|
-
pathsByContentType: z
|
|
1104
|
+
pathsByContentType: z
|
|
1105
|
+
.record(z.string(), z.object({ path: z.string() }))
|
|
1106
|
+
.superRefine((paths, ctx) => {
|
|
1107
|
+
const variableId = ctx.path[ctx.path.length - 2];
|
|
1108
|
+
if (Object.keys(paths).length > MAX_ALLOWED_PATHS) {
|
|
1109
|
+
ctx.addIssue({
|
|
1110
|
+
code: z.ZodIssueCode.custom,
|
|
1111
|
+
message: `Too many paths defined for variable mapping with id "${variableId}", maximum allowed is ${MAX_ALLOWED_PATHS}`,
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
}),
|
|
1086
1115
|
});
|
|
1087
1116
|
const PassToNodeSchema = z
|
|
1088
1117
|
.object({
|
|
@@ -1106,7 +1135,10 @@ const ParameterDefinitionSchema = z.object({
|
|
|
1106
1135
|
})
|
|
1107
1136
|
.optional(),
|
|
1108
1137
|
contentTypes: z.array(z.string()).min(1),
|
|
1109
|
-
passToNodes: z
|
|
1138
|
+
passToNodes: z
|
|
1139
|
+
.array(PassToNodeSchema)
|
|
1140
|
+
.max(1, 'At most one "passToNodes" element is allowed per parameter definition.')
|
|
1141
|
+
.optional(), // we might change this to be empty array for native parameter definitions, that's why we don't use .length(1)
|
|
1110
1142
|
});
|
|
1111
1143
|
const ParameterDefinitionsSchema = z.record(propertyKeySchema, ParameterDefinitionSchema);
|
|
1112
1144
|
const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
|
|
@@ -1127,14 +1159,107 @@ const ComponentSettingsSchema = z
|
|
|
1127
1159
|
category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
|
|
1128
1160
|
prebindingDefinitions: z.array(PrebindingDefinitionSchema).length(1).optional(),
|
|
1129
1161
|
})
|
|
1130
|
-
.strict()
|
|
1131
|
-
|
|
1162
|
+
.strict()
|
|
1163
|
+
.superRefine((componentSettings, ctx) => {
|
|
1164
|
+
const { variableDefinitions, prebindingDefinitions } = componentSettings;
|
|
1165
|
+
if (!prebindingDefinitions || prebindingDefinitions.length === 0) {
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions[0];
|
|
1169
|
+
validateAtMostOneNativeParameterDefinition(parameterDefinitions, ctx);
|
|
1170
|
+
validateNoOverlapBetweenMappingAndOverrides(variableMappings, allowedVariableOverrides, ctx);
|
|
1171
|
+
validateMappingsAgainstVariableDefinitions(variableMappings, allowedVariableOverrides, variableDefinitions, ctx);
|
|
1172
|
+
validateMappingsAgainstParameterDefinitions(variableMappings, parameterDefinitions, ctx);
|
|
1173
|
+
});
|
|
1174
|
+
z
|
|
1175
|
+
.object({
|
|
1132
1176
|
componentTree: localeWrapper(ComponentTreeSchema),
|
|
1133
1177
|
dataSource: localeWrapper(DataSourceSchema),
|
|
1134
1178
|
unboundValues: localeWrapper(UnboundValuesSchema),
|
|
1135
1179
|
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
1136
1180
|
componentSettings: localeWrapper(ComponentSettingsSchema),
|
|
1181
|
+
})
|
|
1182
|
+
.superRefine((patternFields, ctx) => {
|
|
1183
|
+
const { componentTree, componentSettings } = patternFields;
|
|
1184
|
+
// values at this point are wrapped under locale code
|
|
1185
|
+
const nonLocalisedComponentTree = Object.values(componentTree)[0];
|
|
1186
|
+
const nonLocalisedComponentSettings = Object.values(componentSettings)[0];
|
|
1187
|
+
if (!nonLocalisedComponentSettings || !nonLocalisedComponentTree) {
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
validatePassToNodes(nonLocalisedComponentTree.children || [], nonLocalisedComponentSettings || {}, ctx);
|
|
1137
1191
|
});
|
|
1192
|
+
const validateAtMostOneNativeParameterDefinition = (parameterDefinitions, ctx) => {
|
|
1193
|
+
const nativeParamDefinitions = Object.values(parameterDefinitions).filter((paramDefinition) => !(paramDefinition.passToNodes && paramDefinition.passToNodes.length > 0));
|
|
1194
|
+
if (nativeParamDefinitions.length > 1) {
|
|
1195
|
+
ctx.addIssue({
|
|
1196
|
+
code: z.ZodIssueCode.custom,
|
|
1197
|
+
message: `Only one native parameter definition (parameter definition without passToNodes) is allowed per prebinding definition.`,
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
const validateNoOverlapBetweenMappingAndOverrides = (variableMappings, allowedVariableOverrides, ctx) => {
|
|
1202
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
1203
|
+
const overlap = variableMappingKeys.filter((key) => allowedVariableOverrides?.includes(key));
|
|
1204
|
+
if (overlap.length > 0) {
|
|
1205
|
+
ctx.addIssue({
|
|
1206
|
+
code: z.ZodIssueCode.custom,
|
|
1207
|
+
message: `Found both variable mapping and allowed override for the following keys: ${overlap.map((key) => `"${key}"`).join(', ')}.`,
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
const validateMappingsAgainstVariableDefinitions = (variableMappings, allowedVariableOverrides, variableDefinitions, ctx) => {
|
|
1212
|
+
const nonDesignVariableDefinitionKeys = Object.entries(variableDefinitions)
|
|
1213
|
+
.filter(([_, def]) => def.group !== 'style')
|
|
1214
|
+
.map(([key]) => key);
|
|
1215
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
1216
|
+
const allKeys = [...variableMappingKeys, ...(allowedVariableOverrides || [])];
|
|
1217
|
+
const invalidMappings = allKeys.filter((key) => !nonDesignVariableDefinitionKeys.includes(key));
|
|
1218
|
+
if (invalidMappings.length > 0) {
|
|
1219
|
+
ctx.addIssue({
|
|
1220
|
+
code: z.ZodIssueCode.custom,
|
|
1221
|
+
message: `The following variable mappings or overrides are missing from the variable definitions: ${invalidMappings.map((key) => `"${key}"`).join(', ')}.`,
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
const validateMappingsAgainstParameterDefinitions = (variableMappings, parameterDefinitions, ctx) => {
|
|
1226
|
+
const parameterDefinitionKeys = Object.keys(parameterDefinitions || {});
|
|
1227
|
+
for (const [mappingKey, mappingValue] of Object.entries(variableMappings || {})) {
|
|
1228
|
+
if (!parameterDefinitionKeys.includes(mappingValue.parameterId)) {
|
|
1229
|
+
ctx.addIssue({
|
|
1230
|
+
code: z.ZodIssueCode.custom,
|
|
1231
|
+
message: `The variable mapping with id "${mappingKey}" references a non-existing parameterId "${mappingValue.parameterId}".`,
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
const validatePassToNodes = (rootChildren, componentSettings, ctx) => {
|
|
1237
|
+
if (!componentSettings.prebindingDefinitions ||
|
|
1238
|
+
componentSettings.prebindingDefinitions.length === 0) {
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
const { parameterDefinitions } = componentSettings.prebindingDefinitions[0];
|
|
1242
|
+
let nodeIds = new Set();
|
|
1243
|
+
for (const paramDef of Object.values(parameterDefinitions || {})) {
|
|
1244
|
+
paramDef.passToNodes?.forEach((n) => nodeIds.add(n.nodeId));
|
|
1245
|
+
}
|
|
1246
|
+
treeVisit$1(rootChildren, (node) => {
|
|
1247
|
+
if (!node.id)
|
|
1248
|
+
return;
|
|
1249
|
+
if (nodeIds.has(node.id)) {
|
|
1250
|
+
nodeIds.delete(node.id);
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
if (nodeIds.size > 0) {
|
|
1254
|
+
const stringifiedNodeIds = Array.from(nodeIds)
|
|
1255
|
+
.map((id) => `"${id}"`)
|
|
1256
|
+
.join(', ');
|
|
1257
|
+
ctx.addIssue({
|
|
1258
|
+
code: z.ZodIssueCode.custom,
|
|
1259
|
+
message: `The following node IDs referenced in passToNodes are not present in the component tree: ${stringifiedNodeIds}.`,
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1138
1263
|
|
|
1139
1264
|
z
|
|
1140
1265
|
.object({
|