@contentful/experiences-core 3.3.0 → 3.3.1-dev-20250825T0658-5f2fae7.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
@@ -1,5 +1,5 @@
1
1
  import { z, ZodIssueCode } from 'zod';
2
- import { omit, isArray, uniqBy } from 'lodash-es';
2
+ import { cloneDeep, omit, isArray, uniqBy } from 'lodash-es';
3
3
  import md5 from 'md5';
4
4
  import { BLOCKS } from '@contentful/rich-text-types';
5
5
  import { create } from 'zustand';
@@ -1743,7 +1743,7 @@ function localizeEntity(entity, locale) {
1743
1743
  if (entity.sys.locale) {
1744
1744
  return entity;
1745
1745
  }
1746
- const cloned = structuredClone(entity);
1746
+ const cloned = cloneDeep(entity);
1747
1747
  // Set the requested locale as entry locale to follow the API shape:
1748
1748
  // https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/common-resource-attributes
1749
1749
  cloned.sys.locale = locale;
@@ -2894,7 +2894,7 @@ const transformRichText = (entryOrAsset, entityStore, path) => {
2894
2894
  // resolve any links to assets/entries/hyperlinks
2895
2895
  // we need to clone, as we want to keep the original Entity in the EntityStore intact,
2896
2896
  // and resolveLinks() is mutating the node object.
2897
- const richTextDocument = structuredClone(value);
2897
+ const richTextDocument = cloneDeep(value);
2898
2898
  resolveLinks(richTextDocument, entityStore);
2899
2899
  return richTextDocument;
2900
2900
  }
@@ -3558,11 +3558,11 @@ class EntityStoreBase {
3558
3558
  addEntity(entity) {
3559
3559
  if (isAsset(entity)) {
3560
3560
  // cloned and frozen
3561
- this.assetMap.set(entity.sys.id, deepFreeze(structuredClone(entity)));
3561
+ this.assetMap.set(entity.sys.id, deepFreeze(cloneDeep(entity)));
3562
3562
  }
3563
3563
  else if (isEntry(entity)) {
3564
3564
  // cloned and frozen
3565
- this.entryMap.set(entity.sys.id, deepFreeze(structuredClone(entity)));
3565
+ this.entryMap.set(entity.sys.id, deepFreeze(cloneDeep(entity)));
3566
3566
  }
3567
3567
  else {
3568
3568
  throw new Error(`Attempted to add an entity to the store that is neither Asset nor Entry: '${JSON.stringify(entity)}'`);
@@ -4656,6 +4656,19 @@ const sideloadPrebindingDefaultValues = (patternEntry) => {
4656
4656
  return sideloadedCount;
4657
4657
  };
4658
4658
 
4659
+ /**
4660
+ * Run additional checks on the references used in the experience entry and
4661
+ * process data required for prebinding. This must be used after fetching an
4662
+ * experience entry.
4663
+ *
4664
+ * The changes made to the passed experience entry are done inplace.
4665
+ **/
4666
+ const prepareExperienceEntry = (experienceEntry) => {
4667
+ removeCircularPatternReferences(experienceEntry);
4668
+ removeSelfReferencingDataSource(experienceEntry);
4669
+ sideloadPrebindingDefaultValues(experienceEntry);
4670
+ };
4671
+
4659
4672
  const errorMessagesWhileFetching$1 = {
4660
4673
  experience: 'Failed to fetch experience',
4661
4674
  experienceReferences: 'Failed to fetch entities, referenced in experience',
@@ -4689,9 +4702,7 @@ async function fetchBySlug({ client, experienceTypeId, slug, localeCode, isEdito
4689
4702
  if (!experienceEntry) {
4690
4703
  throw new Error(`No experience entry with slug: ${slug} exists`);
4691
4704
  }
4692
- removeCircularPatternReferences(experienceEntry);
4693
- removeSelfReferencingDataSource(experienceEntry);
4694
- sideloadPrebindingDefaultValues(experienceEntry);
4705
+ prepareExperienceEntry(experienceEntry);
4695
4706
  try {
4696
4707
  const { entries, assets } = await fetchReferencedEntities({
4697
4708
  client,
@@ -4748,9 +4759,7 @@ async function fetchById({ client, experienceTypeId, id, localeCode, isEditorMod
4748
4759
  if (!experienceEntry) {
4749
4760
  throw new Error(`No experience entry with id: ${id} exists`);
4750
4761
  }
4751
- removeCircularPatternReferences(experienceEntry);
4752
- removeSelfReferencingDataSource(experienceEntry);
4753
- sideloadPrebindingDefaultValues(experienceEntry);
4762
+ prepareExperienceEntry(experienceEntry);
4754
4763
  try {
4755
4764
  const { entries, assets } = await fetchReferencedEntities({
4756
4765
  client,