@contentful/experiences-core 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
@@ -828,17 +828,16 @@ const PrimitiveValueSchema = z.union([
828
828
  z.record(z.any(), z.any()),
829
829
  z.undefined(),
830
830
  ]);
831
+ const UsedComponentsSchema = z.array(z.object({
832
+ sys: z.object({
833
+ type: z.literal('Link'),
834
+ id: z.string(),
835
+ linkType: z.literal('Entry'),
836
+ }),
837
+ }));
831
838
  const uuidKeySchema = z
832
839
  .string()
833
840
  .regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
834
- /**
835
- * Property keys for imported components have a limit of 32 characters (to be implemented) while
836
- * property keys for patterns have a limit of 54 characters (<32-char-variabl-name>_<21-char-nanoid-id>).
837
- * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
838
- */
839
- const propertyKeySchema = z
840
- .string()
841
- .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
842
841
  const DataSourceSchema = z.record(uuidKeySchema, z.object({
843
842
  sys: z.object({
844
843
  type: z.literal('Link'),
@@ -846,7 +845,62 @@ const DataSourceSchema = z.record(uuidKeySchema, z.object({
846
845
  linkType: z.enum(['Entry', 'Asset']),
847
846
  }),
848
847
  }));
848
+ const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
849
+ value: PrimitiveValueSchema,
850
+ }));
851
+ /**
852
+ * Property keys for imported components have a limit of 32 characters (to be implemented) while
853
+ * property keys for patterns have a limit of 54 characters (<32-char-variable-name>_<21-char-nanoid-id>).
854
+ * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
855
+ */
856
+ const propertyKeySchema = z
857
+ .string()
858
+ .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
859
+ const ComponentTreeNodeIdSchema = z
860
+ .string()
861
+ .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
862
+ const breakpointsRefinement = (value, ctx) => {
863
+ if (!value.length || value[0].query !== '*') {
864
+ ctx.addIssue({
865
+ code: z.ZodIssueCode.custom,
866
+ message: `The first breakpoint should include the following attributes: { "query": "*" }`,
867
+ });
868
+ }
869
+ const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
870
+ // check if the current breakpoint id is found in the rest of the array
871
+ const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
872
+ return breakpointIndex !== currentBreakpointIndex;
873
+ });
874
+ if (hasDuplicateIds) {
875
+ ctx.addIssue({
876
+ code: z.ZodIssueCode.custom,
877
+ message: `Breakpoint IDs must be unique`,
878
+ });
879
+ }
880
+ // Extract the queries boundary by removing the special characters around it
881
+ const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
882
+ // sort updates queries array in place so we need to create a copy
883
+ const originalQueries = [...queries];
884
+ queries.sort((q1, q2) => {
885
+ if (q1 === '*') {
886
+ return -1;
887
+ }
888
+ if (q2 === '*') {
889
+ return 1;
890
+ }
891
+ return q1 > q2 ? -1 : 1;
892
+ });
893
+ if (originalQueries.join('') !== queries.join('')) {
894
+ ctx.addIssue({
895
+ code: z.ZodIssueCode.custom,
896
+ message: `Breakpoints should be ordered from largest to smallest pixel value`,
897
+ });
898
+ }
899
+ };
849
900
  const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
901
+ const BindingSourceTypeEnumSchema = z
902
+ .array(z.enum(['entry', 'asset', 'manual', 'experience']))
903
+ .nonempty();
850
904
  const DesignValueSchema = z
851
905
  .object({
852
906
  type: z.literal('DesignValue'),
@@ -879,8 +933,6 @@ const ComponentValueSchema = z
879
933
  key: z.string(),
880
934
  })
881
935
  .strict();
882
- // TODO: finalize schema structure before release
883
- // https://contentful.atlassian.net/browse/LUMOS-523
884
936
  const NoValueSchema = z.object({ type: z.literal('NoValue') }).strict();
885
937
  const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
886
938
  DesignValueSchema,
@@ -892,41 +944,12 @@ const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
892
944
  ]);
893
945
  // TODO: finalize schema structure before release
894
946
  // https://contentful.atlassian.net/browse/LUMOS-523
895
- const VariableMappingSchema = z.object({
896
- patternPropertyDefinitionId: propertyKeySchema,
897
- type: z.literal('ContentTypeMapping'),
898
- pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
899
- });
900
- const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
901
- // TODO: finalize schema structure before release
902
- // https://contentful.atlassian.net/browse/LUMOS-523
903
- const PatternPropertyDefinitionSchema = z.object({
904
- defaultValue: z
905
- .record(z.string(), z.object({
906
- sys: z.object({
907
- type: z.literal('Link'),
908
- id: z.string(),
909
- linkType: z.enum(['Entry']),
910
- }),
911
- }))
912
- .optional(),
913
- contentTypes: z.record(z.string(), z.object({
914
- sys: z.object({
915
- type: z.literal('Link'),
916
- id: z.string(),
917
- linkType: z.enum(['ContentType']),
918
- }),
919
- })),
920
- });
921
- const PatternPropertyDefinitionsSchema = z.record(propertyKeySchema, PatternPropertyDefinitionSchema);
922
- // TODO: finalize schema structure before release
923
- // https://contentful.atlassian.net/browse/LUMOS-523
924
947
  const PatternPropertySchema = z.object({
925
948
  type: z.literal('BoundValue'),
926
949
  path: z.string(),
927
950
  contentType: z.string(),
928
951
  });
929
- const PatternPropertysSchema = z.record(propertyKeySchema, PatternPropertySchema);
952
+ const PatternPropertiesSchema = z.record(propertyKeySchema, PatternPropertySchema);
930
953
  const BreakpointSchema = z
931
954
  .object({
932
955
  id: propertyKeySchema,
@@ -936,12 +959,6 @@ const BreakpointSchema = z
936
959
  displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
937
960
  })
938
961
  .strict();
939
- const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
940
- value: PrimitiveValueSchema,
941
- }));
942
- const ComponentTreeNodeIdSchema = z
943
- .string()
944
- .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
945
962
  // Use helper schema to define a recursive schema with its type correctly below
946
963
  const BaseComponentTreeNodeSchema = z.object({
947
964
  id: ComponentTreeNodeIdSchema.optional(),
@@ -949,14 +966,8 @@ const BaseComponentTreeNodeSchema = z.object({
949
966
  displayName: z.string().optional(),
950
967
  slotId: z.string().optional(),
951
968
  variables: z.record(propertyKeySchema, ComponentPropertyValueSchema),
952
- patternProperties: PatternPropertysSchema.optional(),
953
- });
954
- const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
955
- children: z.lazy(() => ComponentTreeNodeSchema.array()),
969
+ patternProperties: PatternPropertiesSchema.optional(),
956
970
  });
957
- const BindingSourceTypeEnumSchema = z
958
- .array(z.enum(['entry', 'asset', 'manual', 'experience']))
959
- .nonempty();
960
971
  const ComponentVariableSchema = z.object({
961
972
  displayName: z.string().optional(),
962
973
  type: DefinitionPropertyTypeSchema,
@@ -977,8 +988,25 @@ const ComponentVariableSchema = z.object({
977
988
  })
978
989
  .optional(),
979
990
  });
980
- 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
981
- ComponentVariableSchema);
991
+ const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
992
+ children: z.lazy(() => ComponentTreeNodeSchema.array()),
993
+ });
994
+ const ComponentTreeSchema = z
995
+ .object({
996
+ breakpoints: z.array(BreakpointSchema).superRefine(breakpointsRefinement),
997
+ children: z.array(ComponentTreeNodeSchema),
998
+ schemaVersion: SchemaVersions,
999
+ })
1000
+ .strict();
1001
+ const localeWrapper = (fieldSchema) => z.record(z.string(), fieldSchema);
1002
+
1003
+ z.object({
1004
+ componentTree: localeWrapper(ComponentTreeSchema),
1005
+ dataSource: localeWrapper(DataSourceSchema),
1006
+ unboundValues: localeWrapper(UnboundValuesSchema),
1007
+ usedComponents: localeWrapper(UsedComponentsSchema).optional(),
1008
+ });
1009
+
982
1010
  const THUMBNAIL_IDS = [
983
1011
  'columns',
984
1012
  'columnsPlusRight',
@@ -1004,6 +1032,37 @@ const THUMBNAIL_IDS = [
1004
1032
  'textColumns',
1005
1033
  'duplex',
1006
1034
  ];
1035
+ // TODO: finalize schema structure before release
1036
+ // https://contentful.atlassian.net/browse/LUMOS-523
1037
+ const VariableMappingSchema = z.object({
1038
+ patternPropertyDefinitionId: propertyKeySchema,
1039
+ type: z.literal('ContentTypeMapping'),
1040
+ pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
1041
+ });
1042
+ // TODO: finalize schema structure before release
1043
+ // https://contentful.atlassian.net/browse/LUMOS-523
1044
+ const PatternPropertyDefinitionSchema = z.object({
1045
+ defaultValue: z
1046
+ .record(z.string(), z.object({
1047
+ sys: z.object({
1048
+ type: z.literal('Link'),
1049
+ id: z.string(),
1050
+ linkType: z.enum(['Entry']),
1051
+ }),
1052
+ }))
1053
+ .optional(),
1054
+ contentTypes: z.record(z.string(), z.object({
1055
+ sys: z.object({
1056
+ type: z.literal('Link'),
1057
+ id: z.string(),
1058
+ linkType: z.enum(['ContentType']),
1059
+ }),
1060
+ })),
1061
+ });
1062
+ const PatternPropertyDefinitionsSchema = z.record(propertyKeySchema, PatternPropertyDefinitionSchema);
1063
+ const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
1064
+ 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
1065
+ ComponentVariableSchema);
1007
1066
  const ComponentSettingsSchema = z.object({
1008
1067
  variableDefinitions: ComponentVariablesSchema,
1009
1068
  thumbnailId: z.enum(THUMBNAIL_IDS).optional(),
@@ -1011,65 +1070,12 @@ const ComponentSettingsSchema = z.object({
1011
1070
  variableMappings: VariableMappingsSchema.optional(),
1012
1071
  patternPropertyDefinitions: PatternPropertyDefinitionsSchema.optional(),
1013
1072
  });
1014
- const UsedComponentsSchema = z.array(z.object({
1015
- sys: z.object({
1016
- type: z.literal('Link'),
1017
- id: z.string(),
1018
- linkType: z.literal('Entry'),
1019
- }),
1020
- }));
1021
- const breakpointsRefinement = (value, ctx) => {
1022
- if (!value.length || value[0].query !== '*') {
1023
- ctx.addIssue({
1024
- code: z.ZodIssueCode.custom,
1025
- message: `The first breakpoint should include the following attributes: { "query": "*" }`,
1026
- });
1027
- }
1028
- const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
1029
- // check if the current breakpoint id is found in the rest of the array
1030
- const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
1031
- return breakpointIndex !== currentBreakpointIndex;
1032
- });
1033
- if (hasDuplicateIds) {
1034
- ctx.addIssue({
1035
- code: z.ZodIssueCode.custom,
1036
- message: `Breakpoint IDs must be unique`,
1037
- });
1038
- }
1039
- // Extract the queries boundary by removing the special characters around it
1040
- const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
1041
- // sort updates queries array in place so we need to create a copy
1042
- const originalQueries = [...queries];
1043
- queries.sort((q1, q2) => {
1044
- if (q1 === '*') {
1045
- return -1;
1046
- }
1047
- if (q2 === '*') {
1048
- return 1;
1049
- }
1050
- return q1 > q2 ? -1 : 1;
1051
- });
1052
- if (originalQueries.join('') !== queries.join('')) {
1053
- ctx.addIssue({
1054
- code: z.ZodIssueCode.custom,
1055
- message: `Breakpoints should be ordered from largest to smallest pixel value`,
1056
- });
1057
- }
1058
- };
1059
- const ComponentTreeSchema = z
1060
- .object({
1061
- breakpoints: z.array(BreakpointSchema).superRefine(breakpointsRefinement),
1062
- children: z.array(ComponentTreeNodeSchema),
1063
- schemaVersion: SchemaVersions,
1064
- })
1065
- .strict();
1066
- const localeWrapper = (fieldSchema) => z.record(z.string(), fieldSchema);
1067
1073
  z.object({
1068
1074
  componentTree: localeWrapper(ComponentTreeSchema),
1069
1075
  dataSource: localeWrapper(DataSourceSchema),
1070
1076
  unboundValues: localeWrapper(UnboundValuesSchema),
1071
1077
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
1072
- componentSettings: localeWrapper(ComponentSettingsSchema).optional(),
1078
+ componentSettings: localeWrapper(ComponentSettingsSchema),
1073
1079
  });
1074
1080
 
1075
1081
  z.object({