@contentful/experiences-components-react 1.39.0-alpha-20250528T1342-e28bc3d.0 → 1.39.0-alpha-20250603T1404-5a5eb4e.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 CHANGED
@@ -1162,17 +1162,16 @@ const PrimitiveValueSchema = z.union([
1162
1162
  z.record(z.any(), z.any()),
1163
1163
  z.undefined(),
1164
1164
  ]);
1165
+ const UsedComponentsSchema = z.array(z.object({
1166
+ sys: z.object({
1167
+ type: z.literal('Link'),
1168
+ id: z.string(),
1169
+ linkType: z.literal('Entry'),
1170
+ }),
1171
+ }));
1165
1172
  const uuidKeySchema = z
1166
1173
  .string()
1167
1174
  .regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
1168
- /**
1169
- * Property keys for imported components have a limit of 32 characters (to be implemented) while
1170
- * property keys for patterns have a limit of 54 characters (<32-char-variabl-name>_<21-char-nanoid-id>).
1171
- * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
1172
- */
1173
- const propertyKeySchema = z
1174
- .string()
1175
- .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
1176
1175
  const DataSourceSchema = z.record(uuidKeySchema, z.object({
1177
1176
  sys: z.object({
1178
1177
  type: z.literal('Link'),
@@ -1180,7 +1179,62 @@ const DataSourceSchema = z.record(uuidKeySchema, z.object({
1180
1179
  linkType: z.enum(['Entry', 'Asset']),
1181
1180
  }),
1182
1181
  }));
1182
+ const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
1183
+ value: PrimitiveValueSchema,
1184
+ }));
1185
+ /**
1186
+ * Property keys for imported components have a limit of 32 characters (to be implemented) while
1187
+ * property keys for patterns have a limit of 54 characters (<32-char-variable-name>_<21-char-nanoid-id>).
1188
+ * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
1189
+ */
1190
+ const propertyKeySchema = z
1191
+ .string()
1192
+ .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
1193
+ const ComponentTreeNodeIdSchema = z
1194
+ .string()
1195
+ .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
1196
+ const breakpointsRefinement = (value, ctx) => {
1197
+ if (!value.length || value[0].query !== '*') {
1198
+ ctx.addIssue({
1199
+ code: z.ZodIssueCode.custom,
1200
+ message: `The first breakpoint should include the following attributes: { "query": "*" }`,
1201
+ });
1202
+ }
1203
+ const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
1204
+ // check if the current breakpoint id is found in the rest of the array
1205
+ const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
1206
+ return breakpointIndex !== currentBreakpointIndex;
1207
+ });
1208
+ if (hasDuplicateIds) {
1209
+ ctx.addIssue({
1210
+ code: z.ZodIssueCode.custom,
1211
+ message: `Breakpoint IDs must be unique`,
1212
+ });
1213
+ }
1214
+ // Extract the queries boundary by removing the special characters around it
1215
+ const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
1216
+ // sort updates queries array in place so we need to create a copy
1217
+ const originalQueries = [...queries];
1218
+ queries.sort((q1, q2) => {
1219
+ if (q1 === '*') {
1220
+ return -1;
1221
+ }
1222
+ if (q2 === '*') {
1223
+ return 1;
1224
+ }
1225
+ return q1 > q2 ? -1 : 1;
1226
+ });
1227
+ if (originalQueries.join('') !== queries.join('')) {
1228
+ ctx.addIssue({
1229
+ code: z.ZodIssueCode.custom,
1230
+ message: `Breakpoints should be ordered from largest to smallest pixel value`,
1231
+ });
1232
+ }
1233
+ };
1183
1234
  const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
1235
+ const BindingSourceTypeEnumSchema = z
1236
+ .array(z.enum(['entry', 'asset', 'manual', 'experience']))
1237
+ .nonempty();
1184
1238
  const DesignValueSchema = z
1185
1239
  .object({
1186
1240
  type: z.literal('DesignValue'),
@@ -1213,8 +1267,6 @@ const ComponentValueSchema = z
1213
1267
  key: z.string(),
1214
1268
  })
1215
1269
  .strict();
1216
- // TODO: finalize schema structure before release
1217
- // https://contentful.atlassian.net/browse/LUMOS-523
1218
1270
  const NoValueSchema = z.object({ type: z.literal('NoValue') }).strict();
1219
1271
  const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
1220
1272
  DesignValueSchema,
@@ -1226,41 +1278,12 @@ const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
1226
1278
  ]);
1227
1279
  // TODO: finalize schema structure before release
1228
1280
  // https://contentful.atlassian.net/browse/LUMOS-523
1229
- const VariableMappingSchema = z.object({
1230
- patternPropertyDefinitionId: propertyKeySchema,
1231
- type: z.literal('ContentTypeMapping'),
1232
- pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
1233
- });
1234
- const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
1235
- // TODO: finalize schema structure before release
1236
- // https://contentful.atlassian.net/browse/LUMOS-523
1237
- const PatternPropertyDefinitionSchema = z.object({
1238
- defaultValue: z
1239
- .record(z.string(), z.object({
1240
- sys: z.object({
1241
- type: z.literal('Link'),
1242
- id: z.string(),
1243
- linkType: z.enum(['Entry']),
1244
- }),
1245
- }))
1246
- .optional(),
1247
- contentTypes: z.record(z.string(), z.object({
1248
- sys: z.object({
1249
- type: z.literal('Link'),
1250
- id: z.string(),
1251
- linkType: z.enum(['ContentType']),
1252
- }),
1253
- })),
1254
- });
1255
- const PatternPropertyDefinitionsSchema = z.record(propertyKeySchema, PatternPropertyDefinitionSchema);
1256
- // TODO: finalize schema structure before release
1257
- // https://contentful.atlassian.net/browse/LUMOS-523
1258
1281
  const PatternPropertySchema = z.object({
1259
1282
  type: z.literal('BoundValue'),
1260
1283
  path: z.string(),
1261
1284
  contentType: z.string(),
1262
1285
  });
1263
- const PatternPropertysSchema = z.record(propertyKeySchema, PatternPropertySchema);
1286
+ const PatternPropertiesSchema = z.record(propertyKeySchema, PatternPropertySchema);
1264
1287
  const BreakpointSchema = z
1265
1288
  .object({
1266
1289
  id: propertyKeySchema,
@@ -1270,12 +1293,6 @@ const BreakpointSchema = z
1270
1293
  displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
1271
1294
  })
1272
1295
  .strict();
1273
- const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
1274
- value: PrimitiveValueSchema,
1275
- }));
1276
- const ComponentTreeNodeIdSchema = z
1277
- .string()
1278
- .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
1279
1296
  // Use helper schema to define a recursive schema with its type correctly below
1280
1297
  const BaseComponentTreeNodeSchema = z.object({
1281
1298
  id: ComponentTreeNodeIdSchema.optional(),
@@ -1283,14 +1300,8 @@ const BaseComponentTreeNodeSchema = z.object({
1283
1300
  displayName: z.string().optional(),
1284
1301
  slotId: z.string().optional(),
1285
1302
  variables: z.record(propertyKeySchema, ComponentPropertyValueSchema),
1286
- patternProperties: PatternPropertysSchema.optional(),
1287
- });
1288
- const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
1289
- children: z.lazy(() => ComponentTreeNodeSchema.array()),
1303
+ patternProperties: PatternPropertiesSchema.optional(),
1290
1304
  });
1291
- const BindingSourceTypeEnumSchema = z
1292
- .array(z.enum(['entry', 'asset', 'manual', 'experience']))
1293
- .nonempty();
1294
1305
  const ComponentVariableSchema = z.object({
1295
1306
  displayName: z.string().optional(),
1296
1307
  type: DefinitionPropertyTypeSchema,
@@ -1311,8 +1322,25 @@ const ComponentVariableSchema = z.object({
1311
1322
  })
1312
1323
  .optional(),
1313
1324
  });
1314
- const ComponentVariablesSchema = z.record(z.string().regex(/^[a-zA-Z0-9-_]{1,54}$/), // Here the key is <variableName>_<nanoidId> so we need to allow for a longer length
1315
- ComponentVariableSchema);
1325
+ const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
1326
+ children: z.lazy(() => ComponentTreeNodeSchema.array()),
1327
+ });
1328
+ const ComponentTreeSchema = z
1329
+ .object({
1330
+ breakpoints: z.array(BreakpointSchema).superRefine(breakpointsRefinement),
1331
+ children: z.array(ComponentTreeNodeSchema),
1332
+ schemaVersion: SchemaVersions,
1333
+ })
1334
+ .strict();
1335
+ const localeWrapper = (fieldSchema) => z.record(z.string(), fieldSchema);
1336
+
1337
+ z.object({
1338
+ componentTree: localeWrapper(ComponentTreeSchema),
1339
+ dataSource: localeWrapper(DataSourceSchema),
1340
+ unboundValues: localeWrapper(UnboundValuesSchema),
1341
+ usedComponents: localeWrapper(UsedComponentsSchema).optional(),
1342
+ });
1343
+
1316
1344
  const THUMBNAIL_IDS = [
1317
1345
  'columns',
1318
1346
  'columnsPlusRight',
@@ -1338,6 +1366,37 @@ const THUMBNAIL_IDS = [
1338
1366
  'textColumns',
1339
1367
  'duplex',
1340
1368
  ];
1369
+ // TODO: finalize schema structure before release
1370
+ // https://contentful.atlassian.net/browse/LUMOS-523
1371
+ const VariableMappingSchema = z.object({
1372
+ patternPropertyDefinitionId: propertyKeySchema,
1373
+ type: z.literal('ContentTypeMapping'),
1374
+ pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
1375
+ });
1376
+ // TODO: finalize schema structure before release
1377
+ // https://contentful.atlassian.net/browse/LUMOS-523
1378
+ const PatternPropertyDefinitionSchema = z.object({
1379
+ defaultValue: z
1380
+ .record(z.string(), z.object({
1381
+ sys: z.object({
1382
+ type: z.literal('Link'),
1383
+ id: z.string(),
1384
+ linkType: z.enum(['Entry']),
1385
+ }),
1386
+ }))
1387
+ .optional(),
1388
+ contentTypes: z.record(z.string(), z.object({
1389
+ sys: z.object({
1390
+ type: z.literal('Link'),
1391
+ id: z.string(),
1392
+ linkType: z.enum(['ContentType']),
1393
+ }),
1394
+ })),
1395
+ });
1396
+ const PatternPropertyDefinitionsSchema = z.record(propertyKeySchema, PatternPropertyDefinitionSchema);
1397
+ const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
1398
+ const ComponentVariablesSchema = z.record(z.string().regex(/^[a-zA-Z0-9-_]{1,54}$/), // Here the key is <variableName>_<nanoidId> so we need to allow for a longer length
1399
+ ComponentVariableSchema);
1341
1400
  const ComponentSettingsSchema = z.object({
1342
1401
  variableDefinitions: ComponentVariablesSchema,
1343
1402
  thumbnailId: z.enum(THUMBNAIL_IDS).optional(),
@@ -1345,65 +1404,12 @@ const ComponentSettingsSchema = z.object({
1345
1404
  variableMappings: VariableMappingsSchema.optional(),
1346
1405
  patternPropertyDefinitions: PatternPropertyDefinitionsSchema.optional(),
1347
1406
  });
1348
- const UsedComponentsSchema = z.array(z.object({
1349
- sys: z.object({
1350
- type: z.literal('Link'),
1351
- id: z.string(),
1352
- linkType: z.literal('Entry'),
1353
- }),
1354
- }));
1355
- const breakpointsRefinement = (value, ctx) => {
1356
- if (!value.length || value[0].query !== '*') {
1357
- ctx.addIssue({
1358
- code: z.ZodIssueCode.custom,
1359
- message: `The first breakpoint should include the following attributes: { "query": "*" }`,
1360
- });
1361
- }
1362
- const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
1363
- // check if the current breakpoint id is found in the rest of the array
1364
- const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
1365
- return breakpointIndex !== currentBreakpointIndex;
1366
- });
1367
- if (hasDuplicateIds) {
1368
- ctx.addIssue({
1369
- code: z.ZodIssueCode.custom,
1370
- message: `Breakpoint IDs must be unique`,
1371
- });
1372
- }
1373
- // Extract the queries boundary by removing the special characters around it
1374
- const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
1375
- // sort updates queries array in place so we need to create a copy
1376
- const originalQueries = [...queries];
1377
- queries.sort((q1, q2) => {
1378
- if (q1 === '*') {
1379
- return -1;
1380
- }
1381
- if (q2 === '*') {
1382
- return 1;
1383
- }
1384
- return q1 > q2 ? -1 : 1;
1385
- });
1386
- if (originalQueries.join('') !== queries.join('')) {
1387
- ctx.addIssue({
1388
- code: z.ZodIssueCode.custom,
1389
- message: `Breakpoints should be ordered from largest to smallest pixel value`,
1390
- });
1391
- }
1392
- };
1393
- const ComponentTreeSchema = z
1394
- .object({
1395
- breakpoints: z.array(BreakpointSchema).superRefine(breakpointsRefinement),
1396
- children: z.array(ComponentTreeNodeSchema),
1397
- schemaVersion: SchemaVersions,
1398
- })
1399
- .strict();
1400
- const localeWrapper = (fieldSchema) => z.record(z.string(), fieldSchema);
1401
1407
  z.object({
1402
1408
  componentTree: localeWrapper(ComponentTreeSchema),
1403
1409
  dataSource: localeWrapper(DataSourceSchema),
1404
1410
  unboundValues: localeWrapper(UnboundValuesSchema),
1405
1411
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
1406
- componentSettings: localeWrapper(ComponentSettingsSchema).optional(),
1412
+ componentSettings: localeWrapper(ComponentSettingsSchema),
1407
1413
  });
1408
1414
 
1409
1415
  z.object({