@contentful/experiences-core 1.11.0-dev-20240718T1445-7c1c865.0 → 1.11.0-prerelease-20240723T1849-cedcf84.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
@@ -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) {
@@ -1055,6 +1041,13 @@ z.union([
1055
1041
  z.literal('2023-06-27'),
1056
1042
  ]);
1057
1043
 
1044
+ const PrimitiveValueSchema = z.union([
1045
+ z.string(),
1046
+ z.boolean(),
1047
+ z.number(),
1048
+ z.record(z.any(), z.any()),
1049
+ z.undefined(),
1050
+ ]);
1058
1051
  const DefinitionPropertyTypeSchema = z.enum([
1059
1052
  'Text',
1060
1053
  'RichText',
@@ -1073,12 +1066,117 @@ const DefinitionPropertyKeySchema = z
1073
1066
  .regex(/^[a-zA-Z0-9-_]{1,32}$/, { message: 'Property needs to match: /^[a-zA-Z0-9-_]{1,32}$/' });
1074
1067
  z.object({
1075
1068
  id: DefinitionPropertyKeySchema,
1076
- variables: z.record(DefinitionPropertyKeySchema, z.object({
1069
+ variables: z.record(DefinitionPropertyKeySchema, z
1070
+ .object({
1077
1071
  // TODO - extend with definition of validations and defaultValue
1078
1072
  displayName: z.string().optional(),
1079
1073
  type: DefinitionPropertyTypeSchema,
1080
1074
  description: z.string().optional(),
1081
1075
  group: z.string().optional(),
1076
+ defaultValue: PrimitiveValueSchema.optional(),
1077
+ })
1078
+ .superRefine((val, ctx) => {
1079
+ switch (val.type) {
1080
+ case 'Array':
1081
+ if (typeof val.defaultValue !== 'undefined') {
1082
+ ctx.addIssue({
1083
+ code: z.ZodIssueCode.custom,
1084
+ message: `defaultValue is not supported for "Array" type for ${ctx.path.join('.')}`,
1085
+ fatal: false,
1086
+ });
1087
+ }
1088
+ break;
1089
+ case 'Boolean':
1090
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'boolean') {
1091
+ ctx.addIssue({
1092
+ code: z.ZodIssueCode.custom,
1093
+ message: `defaultValue must be a boolean when type is "Boolean" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1094
+ fatal: false,
1095
+ });
1096
+ }
1097
+ break;
1098
+ case 'Date':
1099
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1100
+ ctx.addIssue({
1101
+ code: z.ZodIssueCode.custom,
1102
+ message: `defaultValue must be a string when type is "Date" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1103
+ fatal: false,
1104
+ });
1105
+ }
1106
+ break;
1107
+ case 'Hyperlink':
1108
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1109
+ ctx.addIssue({
1110
+ code: z.ZodIssueCode.custom,
1111
+ message: `defaultValue must be a string when type is "Hyperlink" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1112
+ fatal: false,
1113
+ });
1114
+ }
1115
+ break;
1116
+ case 'Link':
1117
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1118
+ ctx.addIssue({
1119
+ code: z.ZodIssueCode.custom,
1120
+ message: `defaultValue is not supported for "Link" type for ${ctx.path.join('.')}`,
1121
+ fatal: false,
1122
+ });
1123
+ }
1124
+ break;
1125
+ case 'Location':
1126
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1127
+ ctx.addIssue({
1128
+ code: z.ZodIssueCode.custom,
1129
+ message: `defaultValue must be an object when type is "Location" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1130
+ fatal: false,
1131
+ });
1132
+ }
1133
+ break;
1134
+ case 'Media':
1135
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1136
+ ctx.addIssue({
1137
+ code: z.ZodIssueCode.custom,
1138
+ message: `defaultValue must be a string when type is "Media" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1139
+ fatal: false,
1140
+ });
1141
+ }
1142
+ break;
1143
+ case 'Number':
1144
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'number') {
1145
+ ctx.addIssue({
1146
+ code: z.ZodIssueCode.custom,
1147
+ message: `defaultValue must be a number when type is "Number" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1148
+ fatal: false,
1149
+ });
1150
+ }
1151
+ break;
1152
+ case 'Object':
1153
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1154
+ ctx.addIssue({
1155
+ code: z.ZodIssueCode.custom,
1156
+ message: `defaultValue must be an object when type is "Object" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1157
+ fatal: false,
1158
+ });
1159
+ }
1160
+ break;
1161
+ case 'RichText':
1162
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
1163
+ ctx.addIssue({
1164
+ code: z.ZodIssueCode.custom,
1165
+ message: `defaultValue must be an object when type is "RichText" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1166
+ fatal: false,
1167
+ });
1168
+ }
1169
+ break;
1170
+ case 'Text':
1171
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
1172
+ ctx.addIssue({
1173
+ code: z.ZodIssueCode.custom,
1174
+ message: `defaultValue must be a string when type is "Text" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
1175
+ fatal: false,
1176
+ });
1177
+ }
1178
+ break;
1179
+ }
1082
1180
  })),
1083
1181
  });
1084
1182
 
@@ -1100,13 +1198,6 @@ const DataSourceSchema = z.record(uuidKeySchema, z.object({
1100
1198
  linkType: z.enum(['Entry', 'Asset']),
1101
1199
  }),
1102
1200
  }));
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
1201
  const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
1111
1202
  const DesignValueSchema = z
1112
1203
  .object({
@@ -1367,6 +1458,7 @@ const zodToContentfulError = (issue) => {
1367
1458
  return defaultConversion(issue);
1368
1459
  }
1369
1460
  };
1461
+
1370
1462
  const validateBreakpointsDefinition = (breakpoints) => {
1371
1463
  const result = z
1372
1464
  .array(BreakpointSchema)