@contentful/experiences-visual-editor-react 1.39.0-alpha-20250528T1342-e28bc3d.0 → 1.39.0-alpha-20250528T1549-bd210e1.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
@@ -867,17 +867,16 @@ const PrimitiveValueSchema$1 = z.union([
867
867
  z.record(z.any(), z.any()),
868
868
  z.undefined(),
869
869
  ]);
870
+ const UsedComponentsSchema$1 = z.array(z.object({
871
+ sys: z.object({
872
+ type: z.literal('Link'),
873
+ id: z.string(),
874
+ linkType: z.literal('Entry'),
875
+ }),
876
+ }));
870
877
  const uuidKeySchema$1 = z
871
878
  .string()
872
879
  .regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
873
- /**
874
- * Property keys for imported components have a limit of 32 characters (to be implemented) while
875
- * property keys for patterns have a limit of 54 characters (<32-char-variabl-name>_<21-char-nanoid-id>).
876
- * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
877
- */
878
- const propertyKeySchema$1 = z
879
- .string()
880
- .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
881
880
  const DataSourceSchema$1 = z.record(uuidKeySchema$1, z.object({
882
881
  sys: z.object({
883
882
  type: z.literal('Link'),
@@ -885,7 +884,62 @@ const DataSourceSchema$1 = z.record(uuidKeySchema$1, z.object({
885
884
  linkType: z.enum(['Entry', 'Asset']),
886
885
  }),
887
886
  }));
887
+ const UnboundValuesSchema$1 = z.record(uuidKeySchema$1, z.object({
888
+ value: PrimitiveValueSchema$1,
889
+ }));
890
+ /**
891
+ * Property keys for imported components have a limit of 32 characters (to be implemented) while
892
+ * property keys for patterns have a limit of 54 characters (<32-char-variable-name>_<21-char-nanoid-id>).
893
+ * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
894
+ */
895
+ const propertyKeySchema$1 = z
896
+ .string()
897
+ .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
898
+ const ComponentTreeNodeIdSchema$1 = z
899
+ .string()
900
+ .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
901
+ const breakpointsRefinement$1 = (value, ctx) => {
902
+ if (!value.length || value[0].query !== '*') {
903
+ ctx.addIssue({
904
+ code: z.ZodIssueCode.custom,
905
+ message: `The first breakpoint should include the following attributes: { "query": "*" }`,
906
+ });
907
+ }
908
+ const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
909
+ // check if the current breakpoint id is found in the rest of the array
910
+ const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
911
+ return breakpointIndex !== currentBreakpointIndex;
912
+ });
913
+ if (hasDuplicateIds) {
914
+ ctx.addIssue({
915
+ code: z.ZodIssueCode.custom,
916
+ message: `Breakpoint IDs must be unique`,
917
+ });
918
+ }
919
+ // Extract the queries boundary by removing the special characters around it
920
+ const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
921
+ // sort updates queries array in place so we need to create a copy
922
+ const originalQueries = [...queries];
923
+ queries.sort((q1, q2) => {
924
+ if (q1 === '*') {
925
+ return -1;
926
+ }
927
+ if (q2 === '*') {
928
+ return 1;
929
+ }
930
+ return q1 > q2 ? -1 : 1;
931
+ });
932
+ if (originalQueries.join('') !== queries.join('')) {
933
+ ctx.addIssue({
934
+ code: z.ZodIssueCode.custom,
935
+ message: `Breakpoints should be ordered from largest to smallest pixel value`,
936
+ });
937
+ }
938
+ };
888
939
  const ValuesByBreakpointSchema$1 = z.record(z.lazy(() => PrimitiveValueSchema$1));
940
+ const BindingSourceTypeEnumSchema$1 = z
941
+ .array(z.enum(['entry', 'asset', 'manual', 'experience']))
942
+ .nonempty();
889
943
  const DesignValueSchema$1 = z
890
944
  .object({
891
945
  type: z.literal('DesignValue'),
@@ -918,8 +972,6 @@ const ComponentValueSchema$1 = z
918
972
  key: z.string(),
919
973
  })
920
974
  .strict();
921
- // TODO: finalize schema structure before release
922
- // https://contentful.atlassian.net/browse/LUMOS-523
923
975
  const NoValueSchema$1 = z.object({ type: z.literal('NoValue') }).strict();
924
976
  const ComponentPropertyValueSchema$1 = z.discriminatedUnion('type', [
925
977
  DesignValueSchema$1,
@@ -931,41 +983,12 @@ const ComponentPropertyValueSchema$1 = z.discriminatedUnion('type', [
931
983
  ]);
932
984
  // TODO: finalize schema structure before release
933
985
  // https://contentful.atlassian.net/browse/LUMOS-523
934
- const VariableMappingSchema$1 = z.object({
935
- patternPropertyDefinitionId: propertyKeySchema$1,
936
- type: z.literal('ContentTypeMapping'),
937
- pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
938
- });
939
- const VariableMappingsSchema$1 = z.record(propertyKeySchema$1, VariableMappingSchema$1);
940
- // TODO: finalize schema structure before release
941
- // https://contentful.atlassian.net/browse/LUMOS-523
942
- const PatternPropertyDefinitionSchema$1 = z.object({
943
- defaultValue: z
944
- .record(z.string(), z.object({
945
- sys: z.object({
946
- type: z.literal('Link'),
947
- id: z.string(),
948
- linkType: z.enum(['Entry']),
949
- }),
950
- }))
951
- .optional(),
952
- contentTypes: z.record(z.string(), z.object({
953
- sys: z.object({
954
- type: z.literal('Link'),
955
- id: z.string(),
956
- linkType: z.enum(['ContentType']),
957
- }),
958
- })),
959
- });
960
- const PatternPropertyDefinitionsSchema$1 = z.record(propertyKeySchema$1, PatternPropertyDefinitionSchema$1);
961
- // TODO: finalize schema structure before release
962
- // https://contentful.atlassian.net/browse/LUMOS-523
963
986
  const PatternPropertySchema$1 = z.object({
964
987
  type: z.literal('BoundValue'),
965
988
  path: z.string(),
966
989
  contentType: z.string(),
967
990
  });
968
- const PatternPropertysSchema$1 = z.record(propertyKeySchema$1, PatternPropertySchema$1);
991
+ const PatternPropertiesSchema$1 = z.record(propertyKeySchema$1, PatternPropertySchema$1);
969
992
  const BreakpointSchema$1 = z
970
993
  .object({
971
994
  id: propertyKeySchema$1,
@@ -975,12 +998,6 @@ const BreakpointSchema$1 = z
975
998
  displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
976
999
  })
977
1000
  .strict();
978
- const UnboundValuesSchema$1 = z.record(uuidKeySchema$1, z.object({
979
- value: PrimitiveValueSchema$1,
980
- }));
981
- const ComponentTreeNodeIdSchema$1 = z
982
- .string()
983
- .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
984
1001
  // Use helper schema to define a recursive schema with its type correctly below
985
1002
  const BaseComponentTreeNodeSchema$1 = z.object({
986
1003
  id: ComponentTreeNodeIdSchema$1.optional(),
@@ -988,14 +1005,8 @@ const BaseComponentTreeNodeSchema$1 = z.object({
988
1005
  displayName: z.string().optional(),
989
1006
  slotId: z.string().optional(),
990
1007
  variables: z.record(propertyKeySchema$1, ComponentPropertyValueSchema$1),
991
- patternProperties: PatternPropertysSchema$1.optional(),
992
- });
993
- const ComponentTreeNodeSchema$1 = BaseComponentTreeNodeSchema$1.extend({
994
- children: z.lazy(() => ComponentTreeNodeSchema$1.array()),
1008
+ patternProperties: PatternPropertiesSchema$1.optional(),
995
1009
  });
996
- const BindingSourceTypeEnumSchema$1 = z
997
- .array(z.enum(['entry', 'asset', 'manual', 'experience']))
998
- .nonempty();
999
1010
  const ComponentVariableSchema$1 = z.object({
1000
1011
  displayName: z.string().optional(),
1001
1012
  type: DefinitionPropertyTypeSchema$1,
@@ -1016,8 +1027,25 @@ const ComponentVariableSchema$1 = z.object({
1016
1027
  })
1017
1028
  .optional(),
1018
1029
  });
1019
- const ComponentVariablesSchema$1 = 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
1020
- ComponentVariableSchema$1);
1030
+ const ComponentTreeNodeSchema$1 = BaseComponentTreeNodeSchema$1.extend({
1031
+ children: z.lazy(() => ComponentTreeNodeSchema$1.array()),
1032
+ });
1033
+ const ComponentTreeSchema$1 = z
1034
+ .object({
1035
+ breakpoints: z.array(BreakpointSchema$1).superRefine(breakpointsRefinement$1),
1036
+ children: z.array(ComponentTreeNodeSchema$1),
1037
+ schemaVersion: SchemaVersions$1,
1038
+ })
1039
+ .strict();
1040
+ const localeWrapper$1 = (fieldSchema) => z.record(z.string(), fieldSchema);
1041
+
1042
+ z.object({
1043
+ componentTree: localeWrapper$1(ComponentTreeSchema$1),
1044
+ dataSource: localeWrapper$1(DataSourceSchema$1),
1045
+ unboundValues: localeWrapper$1(UnboundValuesSchema$1),
1046
+ usedComponents: localeWrapper$1(UsedComponentsSchema$1).optional(),
1047
+ });
1048
+
1021
1049
  const THUMBNAIL_IDS$1 = [
1022
1050
  'columns',
1023
1051
  'columnsPlusRight',
@@ -1043,6 +1071,37 @@ const THUMBNAIL_IDS$1 = [
1043
1071
  'textColumns',
1044
1072
  'duplex',
1045
1073
  ];
1074
+ // TODO: finalize schema structure before release
1075
+ // https://contentful.atlassian.net/browse/LUMOS-523
1076
+ const VariableMappingSchema$1 = z.object({
1077
+ patternPropertyDefinitionId: propertyKeySchema$1,
1078
+ type: z.literal('ContentTypeMapping'),
1079
+ pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
1080
+ });
1081
+ // TODO: finalize schema structure before release
1082
+ // https://contentful.atlassian.net/browse/LUMOS-523
1083
+ const PatternPropertyDefinitionSchema$1 = z.object({
1084
+ defaultValue: z
1085
+ .record(z.string(), z.object({
1086
+ sys: z.object({
1087
+ type: z.literal('Link'),
1088
+ id: z.string(),
1089
+ linkType: z.enum(['Entry']),
1090
+ }),
1091
+ }))
1092
+ .optional(),
1093
+ contentTypes: z.record(z.string(), z.object({
1094
+ sys: z.object({
1095
+ type: z.literal('Link'),
1096
+ id: z.string(),
1097
+ linkType: z.enum(['ContentType']),
1098
+ }),
1099
+ })),
1100
+ });
1101
+ const PatternPropertyDefinitionsSchema$1 = z.record(propertyKeySchema$1, PatternPropertyDefinitionSchema$1);
1102
+ const VariableMappingsSchema$1 = z.record(propertyKeySchema$1, VariableMappingSchema$1);
1103
+ const ComponentVariablesSchema$1 = 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
1104
+ ComponentVariableSchema$1);
1046
1105
  const ComponentSettingsSchema$1 = z.object({
1047
1106
  variableDefinitions: ComponentVariablesSchema$1,
1048
1107
  thumbnailId: z.enum(THUMBNAIL_IDS$1).optional(),
@@ -1050,65 +1109,12 @@ const ComponentSettingsSchema$1 = z.object({
1050
1109
  variableMappings: VariableMappingsSchema$1.optional(),
1051
1110
  patternPropertyDefinitions: PatternPropertyDefinitionsSchema$1.optional(),
1052
1111
  });
1053
- const UsedComponentsSchema$1 = z.array(z.object({
1054
- sys: z.object({
1055
- type: z.literal('Link'),
1056
- id: z.string(),
1057
- linkType: z.literal('Entry'),
1058
- }),
1059
- }));
1060
- const breakpointsRefinement$1 = (value, ctx) => {
1061
- if (!value.length || value[0].query !== '*') {
1062
- ctx.addIssue({
1063
- code: z.ZodIssueCode.custom,
1064
- message: `The first breakpoint should include the following attributes: { "query": "*" }`,
1065
- });
1066
- }
1067
- const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
1068
- // check if the current breakpoint id is found in the rest of the array
1069
- const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
1070
- return breakpointIndex !== currentBreakpointIndex;
1071
- });
1072
- if (hasDuplicateIds) {
1073
- ctx.addIssue({
1074
- code: z.ZodIssueCode.custom,
1075
- message: `Breakpoint IDs must be unique`,
1076
- });
1077
- }
1078
- // Extract the queries boundary by removing the special characters around it
1079
- const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
1080
- // sort updates queries array in place so we need to create a copy
1081
- const originalQueries = [...queries];
1082
- queries.sort((q1, q2) => {
1083
- if (q1 === '*') {
1084
- return -1;
1085
- }
1086
- if (q2 === '*') {
1087
- return 1;
1088
- }
1089
- return q1 > q2 ? -1 : 1;
1090
- });
1091
- if (originalQueries.join('') !== queries.join('')) {
1092
- ctx.addIssue({
1093
- code: z.ZodIssueCode.custom,
1094
- message: `Breakpoints should be ordered from largest to smallest pixel value`,
1095
- });
1096
- }
1097
- };
1098
- const ComponentTreeSchema$1 = z
1099
- .object({
1100
- breakpoints: z.array(BreakpointSchema$1).superRefine(breakpointsRefinement$1),
1101
- children: z.array(ComponentTreeNodeSchema$1),
1102
- schemaVersion: SchemaVersions$1,
1103
- })
1104
- .strict();
1105
- const localeWrapper$1 = (fieldSchema) => z.record(z.string(), fieldSchema);
1106
1112
  z.object({
1107
1113
  componentTree: localeWrapper$1(ComponentTreeSchema$1),
1108
1114
  dataSource: localeWrapper$1(DataSourceSchema$1),
1109
1115
  unboundValues: localeWrapper$1(UnboundValuesSchema$1),
1110
1116
  usedComponents: localeWrapper$1(UsedComponentsSchema$1).optional(),
1111
- componentSettings: localeWrapper$1(ComponentSettingsSchema$1).optional(),
1117
+ componentSettings: localeWrapper$1(ComponentSettingsSchema$1),
1112
1118
  });
1113
1119
 
1114
1120
  z.object({
@@ -3026,17 +3032,16 @@ const PrimitiveValueSchema = z.union([
3026
3032
  z.record(z.any(), z.any()),
3027
3033
  z.undefined(),
3028
3034
  ]);
3035
+ const UsedComponentsSchema = z.array(z.object({
3036
+ sys: z.object({
3037
+ type: z.literal('Link'),
3038
+ id: z.string(),
3039
+ linkType: z.literal('Entry'),
3040
+ }),
3041
+ }));
3029
3042
  const uuidKeySchema = z
3030
3043
  .string()
3031
3044
  .regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
3032
- /**
3033
- * Property keys for imported components have a limit of 32 characters (to be implemented) while
3034
- * property keys for patterns have a limit of 54 characters (<32-char-variabl-name>_<21-char-nanoid-id>).
3035
- * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
3036
- */
3037
- const propertyKeySchema = z
3038
- .string()
3039
- .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
3040
3045
  const DataSourceSchema = z.record(uuidKeySchema, z.object({
3041
3046
  sys: z.object({
3042
3047
  type: z.literal('Link'),
@@ -3044,7 +3049,62 @@ const DataSourceSchema = z.record(uuidKeySchema, z.object({
3044
3049
  linkType: z.enum(['Entry', 'Asset']),
3045
3050
  }),
3046
3051
  }));
3052
+ const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
3053
+ value: PrimitiveValueSchema,
3054
+ }));
3055
+ /**
3056
+ * Property keys for imported components have a limit of 32 characters (to be implemented) while
3057
+ * property keys for patterns have a limit of 54 characters (<32-char-variable-name>_<21-char-nanoid-id>).
3058
+ * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
3059
+ */
3060
+ const propertyKeySchema = z
3061
+ .string()
3062
+ .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
3063
+ const ComponentTreeNodeIdSchema = z
3064
+ .string()
3065
+ .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
3066
+ const breakpointsRefinement = (value, ctx) => {
3067
+ if (!value.length || value[0].query !== '*') {
3068
+ ctx.addIssue({
3069
+ code: z.ZodIssueCode.custom,
3070
+ message: `The first breakpoint should include the following attributes: { "query": "*" }`,
3071
+ });
3072
+ }
3073
+ const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
3074
+ // check if the current breakpoint id is found in the rest of the array
3075
+ const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
3076
+ return breakpointIndex !== currentBreakpointIndex;
3077
+ });
3078
+ if (hasDuplicateIds) {
3079
+ ctx.addIssue({
3080
+ code: z.ZodIssueCode.custom,
3081
+ message: `Breakpoint IDs must be unique`,
3082
+ });
3083
+ }
3084
+ // Extract the queries boundary by removing the special characters around it
3085
+ const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
3086
+ // sort updates queries array in place so we need to create a copy
3087
+ const originalQueries = [...queries];
3088
+ queries.sort((q1, q2) => {
3089
+ if (q1 === '*') {
3090
+ return -1;
3091
+ }
3092
+ if (q2 === '*') {
3093
+ return 1;
3094
+ }
3095
+ return q1 > q2 ? -1 : 1;
3096
+ });
3097
+ if (originalQueries.join('') !== queries.join('')) {
3098
+ ctx.addIssue({
3099
+ code: z.ZodIssueCode.custom,
3100
+ message: `Breakpoints should be ordered from largest to smallest pixel value`,
3101
+ });
3102
+ }
3103
+ };
3047
3104
  const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
3105
+ const BindingSourceTypeEnumSchema = z
3106
+ .array(z.enum(['entry', 'asset', 'manual', 'experience']))
3107
+ .nonempty();
3048
3108
  const DesignValueSchema = z
3049
3109
  .object({
3050
3110
  type: z.literal('DesignValue'),
@@ -3077,8 +3137,6 @@ const ComponentValueSchema = z
3077
3137
  key: z.string(),
3078
3138
  })
3079
3139
  .strict();
3080
- // TODO: finalize schema structure before release
3081
- // https://contentful.atlassian.net/browse/LUMOS-523
3082
3140
  const NoValueSchema = z.object({ type: z.literal('NoValue') }).strict();
3083
3141
  const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
3084
3142
  DesignValueSchema,
@@ -3090,41 +3148,12 @@ const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
3090
3148
  ]);
3091
3149
  // TODO: finalize schema structure before release
3092
3150
  // https://contentful.atlassian.net/browse/LUMOS-523
3093
- const VariableMappingSchema = z.object({
3094
- patternPropertyDefinitionId: propertyKeySchema,
3095
- type: z.literal('ContentTypeMapping'),
3096
- pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
3097
- });
3098
- const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
3099
- // TODO: finalize schema structure before release
3100
- // https://contentful.atlassian.net/browse/LUMOS-523
3101
- const PatternPropertyDefinitionSchema = z.object({
3102
- defaultValue: z
3103
- .record(z.string(), z.object({
3104
- sys: z.object({
3105
- type: z.literal('Link'),
3106
- id: z.string(),
3107
- linkType: z.enum(['Entry']),
3108
- }),
3109
- }))
3110
- .optional(),
3111
- contentTypes: z.record(z.string(), z.object({
3112
- sys: z.object({
3113
- type: z.literal('Link'),
3114
- id: z.string(),
3115
- linkType: z.enum(['ContentType']),
3116
- }),
3117
- })),
3118
- });
3119
- const PatternPropertyDefinitionsSchema = z.record(propertyKeySchema, PatternPropertyDefinitionSchema);
3120
- // TODO: finalize schema structure before release
3121
- // https://contentful.atlassian.net/browse/LUMOS-523
3122
3151
  const PatternPropertySchema = z.object({
3123
3152
  type: z.literal('BoundValue'),
3124
3153
  path: z.string(),
3125
3154
  contentType: z.string(),
3126
3155
  });
3127
- const PatternPropertysSchema = z.record(propertyKeySchema, PatternPropertySchema);
3156
+ const PatternPropertiesSchema = z.record(propertyKeySchema, PatternPropertySchema);
3128
3157
  const BreakpointSchema = z
3129
3158
  .object({
3130
3159
  id: propertyKeySchema,
@@ -3134,12 +3163,6 @@ const BreakpointSchema = z
3134
3163
  displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
3135
3164
  })
3136
3165
  .strict();
3137
- const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
3138
- value: PrimitiveValueSchema,
3139
- }));
3140
- const ComponentTreeNodeIdSchema = z
3141
- .string()
3142
- .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
3143
3166
  // Use helper schema to define a recursive schema with its type correctly below
3144
3167
  const BaseComponentTreeNodeSchema = z.object({
3145
3168
  id: ComponentTreeNodeIdSchema.optional(),
@@ -3147,14 +3170,8 @@ const BaseComponentTreeNodeSchema = z.object({
3147
3170
  displayName: z.string().optional(),
3148
3171
  slotId: z.string().optional(),
3149
3172
  variables: z.record(propertyKeySchema, ComponentPropertyValueSchema),
3150
- patternProperties: PatternPropertysSchema.optional(),
3151
- });
3152
- const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
3153
- children: z.lazy(() => ComponentTreeNodeSchema.array()),
3173
+ patternProperties: PatternPropertiesSchema.optional(),
3154
3174
  });
3155
- const BindingSourceTypeEnumSchema = z
3156
- .array(z.enum(['entry', 'asset', 'manual', 'experience']))
3157
- .nonempty();
3158
3175
  const ComponentVariableSchema = z.object({
3159
3176
  displayName: z.string().optional(),
3160
3177
  type: DefinitionPropertyTypeSchema,
@@ -3175,8 +3192,25 @@ const ComponentVariableSchema = z.object({
3175
3192
  })
3176
3193
  .optional(),
3177
3194
  });
3178
- 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
3179
- ComponentVariableSchema);
3195
+ const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
3196
+ children: z.lazy(() => ComponentTreeNodeSchema.array()),
3197
+ });
3198
+ const ComponentTreeSchema = z
3199
+ .object({
3200
+ breakpoints: z.array(BreakpointSchema).superRefine(breakpointsRefinement),
3201
+ children: z.array(ComponentTreeNodeSchema),
3202
+ schemaVersion: SchemaVersions,
3203
+ })
3204
+ .strict();
3205
+ const localeWrapper = (fieldSchema) => z.record(z.string(), fieldSchema);
3206
+
3207
+ z.object({
3208
+ componentTree: localeWrapper(ComponentTreeSchema),
3209
+ dataSource: localeWrapper(DataSourceSchema),
3210
+ unboundValues: localeWrapper(UnboundValuesSchema),
3211
+ usedComponents: localeWrapper(UsedComponentsSchema).optional(),
3212
+ });
3213
+
3180
3214
  const THUMBNAIL_IDS = [
3181
3215
  'columns',
3182
3216
  'columnsPlusRight',
@@ -3202,6 +3236,37 @@ const THUMBNAIL_IDS = [
3202
3236
  'textColumns',
3203
3237
  'duplex',
3204
3238
  ];
3239
+ // TODO: finalize schema structure before release
3240
+ // https://contentful.atlassian.net/browse/LUMOS-523
3241
+ const VariableMappingSchema = z.object({
3242
+ patternPropertyDefinitionId: propertyKeySchema,
3243
+ type: z.literal('ContentTypeMapping'),
3244
+ pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
3245
+ });
3246
+ // TODO: finalize schema structure before release
3247
+ // https://contentful.atlassian.net/browse/LUMOS-523
3248
+ const PatternPropertyDefinitionSchema = z.object({
3249
+ defaultValue: z
3250
+ .record(z.string(), z.object({
3251
+ sys: z.object({
3252
+ type: z.literal('Link'),
3253
+ id: z.string(),
3254
+ linkType: z.enum(['Entry']),
3255
+ }),
3256
+ }))
3257
+ .optional(),
3258
+ contentTypes: z.record(z.string(), z.object({
3259
+ sys: z.object({
3260
+ type: z.literal('Link'),
3261
+ id: z.string(),
3262
+ linkType: z.enum(['ContentType']),
3263
+ }),
3264
+ })),
3265
+ });
3266
+ const PatternPropertyDefinitionsSchema = z.record(propertyKeySchema, PatternPropertyDefinitionSchema);
3267
+ const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
3268
+ 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
3269
+ ComponentVariableSchema);
3205
3270
  const ComponentSettingsSchema = z.object({
3206
3271
  variableDefinitions: ComponentVariablesSchema,
3207
3272
  thumbnailId: z.enum(THUMBNAIL_IDS).optional(),
@@ -3209,65 +3274,12 @@ const ComponentSettingsSchema = z.object({
3209
3274
  variableMappings: VariableMappingsSchema.optional(),
3210
3275
  patternPropertyDefinitions: PatternPropertyDefinitionsSchema.optional(),
3211
3276
  });
3212
- const UsedComponentsSchema = z.array(z.object({
3213
- sys: z.object({
3214
- type: z.literal('Link'),
3215
- id: z.string(),
3216
- linkType: z.literal('Entry'),
3217
- }),
3218
- }));
3219
- const breakpointsRefinement = (value, ctx) => {
3220
- if (!value.length || value[0].query !== '*') {
3221
- ctx.addIssue({
3222
- code: z.ZodIssueCode.custom,
3223
- message: `The first breakpoint should include the following attributes: { "query": "*" }`,
3224
- });
3225
- }
3226
- const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
3227
- // check if the current breakpoint id is found in the rest of the array
3228
- const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
3229
- return breakpointIndex !== currentBreakpointIndex;
3230
- });
3231
- if (hasDuplicateIds) {
3232
- ctx.addIssue({
3233
- code: z.ZodIssueCode.custom,
3234
- message: `Breakpoint IDs must be unique`,
3235
- });
3236
- }
3237
- // Extract the queries boundary by removing the special characters around it
3238
- const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
3239
- // sort updates queries array in place so we need to create a copy
3240
- const originalQueries = [...queries];
3241
- queries.sort((q1, q2) => {
3242
- if (q1 === '*') {
3243
- return -1;
3244
- }
3245
- if (q2 === '*') {
3246
- return 1;
3247
- }
3248
- return q1 > q2 ? -1 : 1;
3249
- });
3250
- if (originalQueries.join('') !== queries.join('')) {
3251
- ctx.addIssue({
3252
- code: z.ZodIssueCode.custom,
3253
- message: `Breakpoints should be ordered from largest to smallest pixel value`,
3254
- });
3255
- }
3256
- };
3257
- const ComponentTreeSchema = z
3258
- .object({
3259
- breakpoints: z.array(BreakpointSchema).superRefine(breakpointsRefinement),
3260
- children: z.array(ComponentTreeNodeSchema),
3261
- schemaVersion: SchemaVersions,
3262
- })
3263
- .strict();
3264
- const localeWrapper = (fieldSchema) => z.record(z.string(), fieldSchema);
3265
3277
  z.object({
3266
3278
  componentTree: localeWrapper(ComponentTreeSchema),
3267
3279
  dataSource: localeWrapper(DataSourceSchema),
3268
3280
  unboundValues: localeWrapper(UnboundValuesSchema),
3269
3281
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
3270
- componentSettings: localeWrapper(ComponentSettingsSchema).optional(),
3282
+ componentSettings: localeWrapper(ComponentSettingsSchema),
3271
3283
  });
3272
3284
 
3273
3285
  z.object({