@contentful/experiences-core 3.7.0-prerelease-20250915T1724-8825648.0 → 3.7.0-prerelease-20250917T1034-42f0486.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 +17 -129
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1035,6 +1035,19 @@ const ComponentVariableSchema = z.object({
|
|
|
1035
1035
|
});
|
|
1036
1036
|
const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
|
|
1037
1037
|
children: z.lazy(() => ComponentTreeNodeSchema.array()),
|
|
1038
|
+
}).superRefine(({ id, prebindingId, parameters }, ctx) => {
|
|
1039
|
+
if (prebindingId && !parameters) {
|
|
1040
|
+
ctx.addIssue({
|
|
1041
|
+
code: z.ZodIssueCode.custom,
|
|
1042
|
+
message: `Found "prebindingId" but no "parameters" for node with id: "${id}"`,
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
if (parameters && !prebindingId) {
|
|
1046
|
+
ctx.addIssue({
|
|
1047
|
+
code: z.ZodIssueCode.custom,
|
|
1048
|
+
message: `Found "parameters" but no "prebindingId" for node with id: "${id}"`,
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1038
1051
|
});
|
|
1039
1052
|
const ComponentTreeSchema = z
|
|
1040
1053
|
.object({
|
|
@@ -1052,25 +1065,6 @@ z.object({
|
|
|
1052
1065
|
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
1053
1066
|
});
|
|
1054
1067
|
|
|
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;
|
|
1074
1068
|
const THUMBNAIL_IDS = [
|
|
1075
1069
|
'columns',
|
|
1076
1070
|
'columnsPlusRight',
|
|
@@ -1101,17 +1095,7 @@ const THUMBNAIL_IDS = [
|
|
|
1101
1095
|
const VariableMappingSchema = z.object({
|
|
1102
1096
|
parameterId: propertyKeySchema,
|
|
1103
1097
|
type: z.literal('ContentTypeMapping'),
|
|
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
|
-
}),
|
|
1098
|
+
pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
|
|
1115
1099
|
});
|
|
1116
1100
|
const PassToNodeSchema = z
|
|
1117
1101
|
.object({
|
|
@@ -1135,10 +1119,7 @@ const ParameterDefinitionSchema = z.object({
|
|
|
1135
1119
|
})
|
|
1136
1120
|
.optional(),
|
|
1137
1121
|
contentTypes: z.array(z.string()).min(1),
|
|
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)
|
|
1122
|
+
passToNodes: z.array(PassToNodeSchema).optional(),
|
|
1142
1123
|
});
|
|
1143
1124
|
const ParameterDefinitionsSchema = z.record(propertyKeySchema, ParameterDefinitionSchema);
|
|
1144
1125
|
const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
|
|
@@ -1159,107 +1140,14 @@ const ComponentSettingsSchema = z
|
|
|
1159
1140
|
category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
|
|
1160
1141
|
prebindingDefinitions: z.array(PrebindingDefinitionSchema).length(1).optional(),
|
|
1161
1142
|
})
|
|
1162
|
-
.strict()
|
|
1163
|
-
|
|
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({
|
|
1143
|
+
.strict();
|
|
1144
|
+
z.object({
|
|
1176
1145
|
componentTree: localeWrapper(ComponentTreeSchema),
|
|
1177
1146
|
dataSource: localeWrapper(DataSourceSchema),
|
|
1178
1147
|
unboundValues: localeWrapper(UnboundValuesSchema),
|
|
1179
1148
|
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
1180
1149
|
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);
|
|
1191
1150
|
});
|
|
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
|
-
};
|
|
1263
1151
|
|
|
1264
1152
|
z
|
|
1265
1153
|
.object({
|