@contentful/experiences-core 1.12.0-dev-20240809T1542-35242c4.0 → 1.12.0-dev-20240816T2200-8ea4d09.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.
@@ -19,9 +19,9 @@ declare class EntityStore extends EntityStoreBase {
19
19
  get schemaVersion(): "2023-09-28" | undefined;
20
20
  get breakpoints(): {
21
21
  id: string;
22
- displayName: string;
23
22
  query: string;
24
23
  previewSize: string;
24
+ displayName: string;
25
25
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
26
26
  }[];
27
27
  get dataSource(): Record<string, {
package/dist/index.js CHANGED
@@ -1069,17 +1069,13 @@ const DefinitionPropertyTypeSchema = z.enum([
1069
1069
  const DefinitionPropertyKeySchema = z
1070
1070
  .string()
1071
1071
  .regex(/^[a-zA-Z0-9-_]{1,32}$/, { message: 'Property needs to match: /^[a-zA-Z0-9-_]{1,32}$/' });
1072
- z.object({
1073
- id: DefinitionPropertyKeySchema,
1074
- variables: z.record(DefinitionPropertyKeySchema, z.object({
1075
- // TODO - extend with definition of validations and defaultValue
1076
- displayName: z.string().optional(),
1077
- type: DefinitionPropertyTypeSchema,
1078
- description: z.string().optional(),
1079
- group: z.string().optional(),
1080
- })),
1081
- });
1082
-
1072
+ const PrimitiveValueSchema = z.union([
1073
+ z.string(),
1074
+ z.boolean(),
1075
+ z.number(),
1076
+ z.record(z.any(), z.any()),
1077
+ z.undefined(),
1078
+ ]);
1083
1079
  const uuidKeySchema = z
1084
1080
  .string()
1085
1081
  .regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
@@ -1098,13 +1094,6 @@ const DataSourceSchema = z.record(uuidKeySchema, z.object({
1098
1094
  linkType: z.enum(['Entry', 'Asset']),
1099
1095
  }),
1100
1096
  }));
1101
- const PrimitiveValueSchema = z.union([
1102
- z.string(),
1103
- z.boolean(),
1104
- z.number(),
1105
- z.record(z.any(), z.any()),
1106
- z.undefined(),
1107
- ]);
1108
1097
  const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
1109
1098
  const DesignValueSchema = z
1110
1099
  .object({
@@ -1166,27 +1155,29 @@ const BaseComponentTreeNodeSchema = z.object({
1166
1155
  const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
1167
1156
  children: z.lazy(() => ComponentTreeNodeSchema.array()),
1168
1157
  });
1169
- const ComponentSettingsSchema = z.object({
1170
- variableDefinitions: 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
1171
- z.object({
1172
- displayName: z.string().optional(),
1173
- type: DefinitionPropertyTypeSchema,
1174
- defaultValue: PrimitiveValueSchema.or(ComponentPropertyValueSchema).optional(),
1175
- description: z.string().optional(),
1176
- group: z.string().optional(),
1177
- validations: z
1178
- .object({
1179
- required: z.boolean().optional(),
1180
- format: z.literal('URL').optional(),
1181
- in: z
1182
- .array(z.object({
1183
- value: z.union([z.string(), z.number()]),
1184
- displayName: z.string().optional(),
1185
- }))
1186
- .optional(),
1187
- })
1158
+ const ComponentVariableSchema = z.object({
1159
+ displayName: z.string().optional(),
1160
+ type: DefinitionPropertyTypeSchema,
1161
+ description: z.string().optional(),
1162
+ group: z.string().optional(),
1163
+ defaultValue: PrimitiveValueSchema.or(ComponentPropertyValueSchema).optional(),
1164
+ validations: z
1165
+ .object({
1166
+ required: z.boolean().optional(),
1167
+ format: z.literal('URL').optional(),
1168
+ in: z
1169
+ .array(z.object({
1170
+ value: z.union([z.string(), z.number()]),
1171
+ displayName: z.string().optional(),
1172
+ }))
1188
1173
  .optional(),
1189
- })),
1174
+ })
1175
+ .optional(),
1176
+ });
1177
+ 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
1178
+ ComponentVariableSchema);
1179
+ const ComponentSettingsSchema = z.object({
1180
+ variableDefinitions: ComponentVariablesSchema,
1190
1181
  });
1191
1182
  const UsedComponentsSchema = z.array(z.object({
1192
1183
  sys: z.object({
@@ -1265,6 +1256,115 @@ z
1265
1256
  })
1266
1257
  .superRefine(componentSettingsRefinement);
1267
1258
 
1259
+ z.object({
1260
+ id: DefinitionPropertyKeySchema,
1261
+ variables: z.record(DefinitionPropertyKeySchema, ComponentVariableSchema.extend({
1262
+ defaultValue: PrimitiveValueSchema.optional(),
1263
+ }).superRefine((val, ctx) => {
1264
+ switch (val.type) {
1265
+ case 'Array':
1266
+ if (typeof val.defaultValue !== 'undefined') {
1267
+ ctx.addIssue({
1268
+ code: z.ZodIssueCode.custom,
1269
+ message: `defaultValue is not supported for "Array" type for ${ctx.path.join('.')}`,
1270
+ fatal: false,
1271
+ });
1272
+ }
1273
+ break;
1274
+ case 'Boolean':
1275
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'boolean') {
1276
+ ctx.addIssue({
1277
+ code: z.ZodIssueCode.custom,
1278
+ message: `defaultValue must be a boolean when type is "Boolean" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1279
+ fatal: false,
1280
+ });
1281
+ }
1282
+ break;
1283
+ case 'Date':
1284
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1285
+ ctx.addIssue({
1286
+ code: z.ZodIssueCode.custom,
1287
+ message: `defaultValue must be a string when type is "Date" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1288
+ fatal: false,
1289
+ });
1290
+ }
1291
+ break;
1292
+ case 'Hyperlink':
1293
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1294
+ ctx.addIssue({
1295
+ code: z.ZodIssueCode.custom,
1296
+ message: `defaultValue must be a string when type is "Hyperlink" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1297
+ fatal: false,
1298
+ });
1299
+ }
1300
+ break;
1301
+ case 'Link':
1302
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1303
+ ctx.addIssue({
1304
+ code: z.ZodIssueCode.custom,
1305
+ message: `defaultValue is not supported for "Link" type for ${ctx.path.join('.')}`,
1306
+ fatal: false,
1307
+ });
1308
+ }
1309
+ break;
1310
+ case 'Location':
1311
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1312
+ ctx.addIssue({
1313
+ code: z.ZodIssueCode.custom,
1314
+ message: `defaultValue must be an object when type is "Location" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1315
+ fatal: false,
1316
+ });
1317
+ }
1318
+ break;
1319
+ case 'Media':
1320
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1321
+ ctx.addIssue({
1322
+ code: z.ZodIssueCode.custom,
1323
+ message: `defaultValue must be a string when type is "Media" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1324
+ fatal: false,
1325
+ });
1326
+ }
1327
+ break;
1328
+ case 'Number':
1329
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'number') {
1330
+ ctx.addIssue({
1331
+ code: z.ZodIssueCode.custom,
1332
+ message: `defaultValue must be a number when type is "Number" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1333
+ fatal: false,
1334
+ });
1335
+ }
1336
+ break;
1337
+ case 'Object':
1338
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1339
+ ctx.addIssue({
1340
+ code: z.ZodIssueCode.custom,
1341
+ message: `defaultValue must be an object when type is "Object" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1342
+ fatal: false,
1343
+ });
1344
+ }
1345
+ break;
1346
+ case 'RichText':
1347
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1348
+ ctx.addIssue({
1349
+ code: z.ZodIssueCode.custom,
1350
+ message: `defaultValue must be an object when type is "RichText" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1351
+ fatal: false,
1352
+ });
1353
+ }
1354
+ break;
1355
+ case 'Text':
1356
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1357
+ ctx.addIssue({
1358
+ code: z.ZodIssueCode.custom,
1359
+ message: `defaultValue must be a string when type is "Text" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1360
+ fatal: false,
1361
+ });
1362
+ }
1363
+ break;
1364
+ }
1365
+ })),
1366
+ });
1367
+
1268
1368
  var CodeNames;
1269
1369
  (function (CodeNames) {
1270
1370
  CodeNames["Type"] = "type";
@@ -1365,6 +1465,7 @@ const zodToContentfulError = (issue) => {
1365
1465
  return defaultConversion(issue);
1366
1466
  }
1367
1467
  };
1468
+
1368
1469
  const validateBreakpointsDefinition = (breakpoints) => {
1369
1470
  const result = z
1370
1471
  .array(BreakpointSchema)