@contentful/experiences-core 1.11.0-dev-20240718T2005-1c07c3a.0 → 1.11.0-prerelease-20240726T1510-9e11672.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
@@ -972,21 +972,7 @@ let designTokensRegistry = {};
972
972
  // Therefore only border and in the future text related design tokens are/will be checked in this funciton.
973
973
  // Ensuring values for simple key-value design tokens are not neccessary since they are required via typescript.
974
974
  const ensureValidCompositeValues = (designTokenDefinition) => {
975
- // Text token validation
976
- if (designTokenDefinition.text) {
977
- for (const textKey in designTokenDefinition.text) {
978
- const textValue = designTokenDefinition.text[textKey];
979
- designTokenDefinition.text[textKey] = {
980
- emphasis: textValue.emphasis || 'none',
981
- fontSize: textValue.fontSize || '16px',
982
- case: textValue.case || 'normal',
983
- fontWeight: textValue.fontWeight || '400',
984
- lineHeight: textValue.lineHeight || '20px',
985
- letterSpacing: textValue.letterSpacing || '0px',
986
- color: textValue.color || '#000000',
987
- };
988
- }
989
- }
975
+ // TODO: add validation logic when text related design tokens are added
990
976
  // Border validation
991
977
  if (designTokenDefinition.border) {
992
978
  for (const borderKey in designTokenDefinition.border) {
@@ -1071,17 +1057,13 @@ const DefinitionPropertyTypeSchema = z.enum([
1071
1057
  const DefinitionPropertyKeySchema = z
1072
1058
  .string()
1073
1059
  .regex(/^[a-zA-Z0-9-_]{1,32}$/, { message: 'Property needs to match: /^[a-zA-Z0-9-_]{1,32}$/' });
1074
- z.object({
1075
- id: DefinitionPropertyKeySchema,
1076
- variables: z.record(DefinitionPropertyKeySchema, z.object({
1077
- // TODO - extend with definition of validations and defaultValue
1078
- displayName: z.string().optional(),
1079
- type: DefinitionPropertyTypeSchema,
1080
- description: z.string().optional(),
1081
- group: z.string().optional(),
1082
- })),
1083
- });
1084
-
1060
+ const PrimitiveValueSchema = z.union([
1061
+ z.string(),
1062
+ z.boolean(),
1063
+ z.number(),
1064
+ z.record(z.any(), z.any()),
1065
+ z.undefined(),
1066
+ ]);
1085
1067
  const uuidKeySchema = z
1086
1068
  .string()
1087
1069
  .regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
@@ -1100,13 +1082,6 @@ const DataSourceSchema = z.record(uuidKeySchema, z.object({
1100
1082
  linkType: z.enum(['Entry', 'Asset']),
1101
1083
  }),
1102
1084
  }));
1103
- const PrimitiveValueSchema = z.union([
1104
- z.string(),
1105
- z.boolean(),
1106
- z.number(),
1107
- z.record(z.any(), z.any()),
1108
- z.undefined(),
1109
- ]);
1110
1085
  const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
1111
1086
  const DesignValueSchema = z
1112
1087
  .object({
@@ -1168,27 +1143,29 @@ const BaseComponentTreeNodeSchema = z.object({
1168
1143
  const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
1169
1144
  children: z.lazy(() => ComponentTreeNodeSchema.array()),
1170
1145
  });
1171
- const ComponentSettingsSchema = z.object({
1172
- 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
1173
- z.object({
1174
- displayName: z.string().optional(),
1175
- type: DefinitionPropertyTypeSchema,
1176
- defaultValue: PrimitiveValueSchema.or(ComponentPropertyValueSchema).optional(),
1177
- description: z.string().optional(),
1178
- group: z.string().optional(),
1179
- validations: z
1180
- .object({
1181
- required: z.boolean().optional(),
1182
- format: z.literal('URL').optional(),
1183
- in: z
1184
- .array(z.object({
1185
- value: z.union([z.string(), z.number()]),
1186
- displayName: z.string().optional(),
1187
- }))
1188
- .optional(),
1189
- })
1146
+ const ComponentVariableSchema = z.object({
1147
+ displayName: z.string().optional(),
1148
+ type: DefinitionPropertyTypeSchema,
1149
+ description: z.string().optional(),
1150
+ group: z.string().optional(),
1151
+ defaultValue: PrimitiveValueSchema.or(ComponentPropertyValueSchema).optional(),
1152
+ validations: z
1153
+ .object({
1154
+ required: z.boolean().optional(),
1155
+ format: z.literal('URL').optional(),
1156
+ in: z
1157
+ .array(z.object({
1158
+ value: z.union([z.string(), z.number()]),
1159
+ displayName: z.string().optional(),
1160
+ }))
1190
1161
  .optional(),
1191
- })),
1162
+ })
1163
+ .optional(),
1164
+ });
1165
+ 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
1166
+ ComponentVariableSchema);
1167
+ const ComponentSettingsSchema = z.object({
1168
+ variableDefinitions: ComponentVariablesSchema,
1192
1169
  });
1193
1170
  const UsedComponentsSchema = z.array(z.object({
1194
1171
  sys: z.object({
@@ -1267,6 +1244,115 @@ z
1267
1244
  })
1268
1245
  .superRefine(componentSettingsRefinement);
1269
1246
 
1247
+ z.object({
1248
+ id: DefinitionPropertyKeySchema,
1249
+ variables: z.record(DefinitionPropertyKeySchema, ComponentVariableSchema.extend({
1250
+ defaultValue: PrimitiveValueSchema.optional(),
1251
+ }).superRefine((val, ctx) => {
1252
+ switch (val.type) {
1253
+ case 'Array':
1254
+ if (typeof val.defaultValue !== 'undefined') {
1255
+ ctx.addIssue({
1256
+ code: z.ZodIssueCode.custom,
1257
+ message: `defaultValue is not supported for "Array" type for ${ctx.path.join('.')}`,
1258
+ fatal: false,
1259
+ });
1260
+ }
1261
+ break;
1262
+ case 'Boolean':
1263
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'boolean') {
1264
+ ctx.addIssue({
1265
+ code: z.ZodIssueCode.custom,
1266
+ message: `defaultValue must be a boolean when type is "Boolean" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1267
+ fatal: false,
1268
+ });
1269
+ }
1270
+ break;
1271
+ case 'Date':
1272
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1273
+ ctx.addIssue({
1274
+ code: z.ZodIssueCode.custom,
1275
+ message: `defaultValue must be a string when type is "Date" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1276
+ fatal: false,
1277
+ });
1278
+ }
1279
+ break;
1280
+ case 'Hyperlink':
1281
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1282
+ ctx.addIssue({
1283
+ code: z.ZodIssueCode.custom,
1284
+ message: `defaultValue must be a string when type is "Hyperlink" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1285
+ fatal: false,
1286
+ });
1287
+ }
1288
+ break;
1289
+ case 'Link':
1290
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1291
+ ctx.addIssue({
1292
+ code: z.ZodIssueCode.custom,
1293
+ message: `defaultValue is not supported for "Link" type for ${ctx.path.join('.')}`,
1294
+ fatal: false,
1295
+ });
1296
+ }
1297
+ break;
1298
+ case 'Location':
1299
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1300
+ ctx.addIssue({
1301
+ code: z.ZodIssueCode.custom,
1302
+ message: `defaultValue must be an object when type is "Location" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1303
+ fatal: false,
1304
+ });
1305
+ }
1306
+ break;
1307
+ case 'Media':
1308
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1309
+ ctx.addIssue({
1310
+ code: z.ZodIssueCode.custom,
1311
+ message: `defaultValue must be a string when type is "Media" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1312
+ fatal: false,
1313
+ });
1314
+ }
1315
+ break;
1316
+ case 'Number':
1317
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'number') {
1318
+ ctx.addIssue({
1319
+ code: z.ZodIssueCode.custom,
1320
+ message: `defaultValue must be a number when type is "Number" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1321
+ fatal: false,
1322
+ });
1323
+ }
1324
+ break;
1325
+ case 'Object':
1326
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1327
+ ctx.addIssue({
1328
+ code: z.ZodIssueCode.custom,
1329
+ message: `defaultValue must be an object when type is "Object" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1330
+ fatal: false,
1331
+ });
1332
+ }
1333
+ break;
1334
+ case 'RichText':
1335
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1336
+ ctx.addIssue({
1337
+ code: z.ZodIssueCode.custom,
1338
+ message: `defaultValue must be an object when type is "RichText" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1339
+ fatal: false,
1340
+ });
1341
+ }
1342
+ break;
1343
+ case 'Text':
1344
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1345
+ ctx.addIssue({
1346
+ code: z.ZodIssueCode.custom,
1347
+ message: `defaultValue must be a string when type is "Text" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1348
+ fatal: false,
1349
+ });
1350
+ }
1351
+ break;
1352
+ }
1353
+ })),
1354
+ });
1355
+
1270
1356
  var CodeNames;
1271
1357
  (function (CodeNames) {
1272
1358
  CodeNames["Type"] = "type";
@@ -1367,6 +1453,7 @@ const zodToContentfulError = (issue) => {
1367
1453
  return defaultConversion(issue);
1368
1454
  }
1369
1455
  };
1456
+
1370
1457
  const validateBreakpointsDefinition = (breakpoints) => {
1371
1458
  const result = z
1372
1459
  .array(BreakpointSchema)