@contentful/experiences-core 1.7.0-dev-20240605T1950-080b5d2.0 → 1.7.0-dev-20240607T0931-3af8e08.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.
@@ -17,7 +17,6 @@ declare class DeepReference {
17
17
  /**
18
18
  * Extracts referent from the path, using EntityStore as source of
19
19
  * entities during the resolution path.
20
- * TODO: should it be called `extractLeafReferent` ? or `followToLeafReferent`
21
20
  */
22
21
  extractReferent(entityStore: EntityStoreBase): Link<'Asset' | 'Entry'> | undefined;
23
22
  static from(opt: DeepReferenceOpts): DeepReference;
@@ -22,7 +22,7 @@ declare class EntityStore extends EntityStoreBase {
22
22
  displayName: string;
23
23
  query: string;
24
24
  previewSize: string;
25
- displayIconUrl?: string | undefined;
25
+ displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
26
26
  }[];
27
27
  get dataSource(): Record<string, {
28
28
  sys: {
package/dist/index.js CHANGED
@@ -215,7 +215,6 @@ const transformBorderStyle = (value) => {
215
215
  // Just accept the passed value
216
216
  if (parts.length < 3)
217
217
  return { border: value };
218
- // Replace the second part always with `solid` and set the box sizing accordingly
219
218
  const [borderSize, borderStyle, ...borderColorParts] = parts;
220
219
  const borderColor = borderColorParts.join(' ');
221
220
  return {
@@ -1362,7 +1361,7 @@ const BreakpointSchema = z
1362
1361
  query: z.string().regex(/^\*$|^<[0-9*]+px$/),
1363
1362
  previewSize: z.string(),
1364
1363
  displayName: z.string(),
1365
- displayIconUrl: z.string().optional(),
1364
+ displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
1366
1365
  })
1367
1366
  .strict();
1368
1367
  const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
@@ -2518,11 +2517,10 @@ class DeepReference {
2518
2517
  /**
2519
2518
  * Extracts referent from the path, using EntityStore as source of
2520
2519
  * entities during the resolution path.
2521
- * TODO: should it be called `extractLeafReferent` ? or `followToLeafReferent`
2522
2520
  */
2523
2521
  extractReferent(entityStore) {
2524
2522
  const headEntity = entityStore.getEntityFromLink(this.entityLink);
2525
- const maybeReferentLink = headEntity.fields[this.field];
2523
+ const maybeReferentLink = headEntity?.fields[this.field];
2526
2524
  if (undefined === maybeReferentLink) {
2527
2525
  // field references nothing (or even field doesn't exist)
2528
2526
  return undefined;
@@ -2611,27 +2609,20 @@ function gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse)
2611
2609
  console.debug(`[experiences-sdk-react::gatherAutoFetchedReferentsFromIncludes] Non-link value in headEntity. Probably broken path '${reference.originalPath}'`);
2612
2610
  continue;
2613
2611
  }
2614
- if (linkToReferent.sys.linkType === 'Entry') {
2615
- const referentEntry = entriesResponse.includes?.Entry?.find((entry) => entry.sys.id === linkToReferent.sys.id);
2616
- if (!referentEntry) {
2617
- throw new Error(`Logic Error: L2-referent Entry was not found within .includes (${JSON.stringify({
2618
- linkToReferent,
2619
- })})`);
2620
- }
2621
- autoFetchedReferentEntries.push(referentEntry);
2622
- }
2623
- else if (linkToReferent.sys.linkType === 'Asset') {
2624
- const referentAsset = entriesResponse.includes?.Asset?.find((entry) => entry.sys.id === linkToReferent.sys.id);
2625
- if (!referentAsset) {
2626
- throw new Error(`Logic Error: L2-referent Asset was not found within includes (${JSON.stringify({
2627
- linkToReferent,
2628
- })})`);
2629
- }
2630
- autoFetchedReferentAssets.push(referentAsset);
2631
- }
2632
- else {
2612
+ const linkType = linkToReferent.sys.linkType;
2613
+ if (!['Entry', 'Asset'].includes(linkType)) {
2633
2614
  console.debug(`[experiences-sdk-react::gatherAutoFetchedReferentsFromIncludes] Unhandled linkType :${JSON.stringify(linkToReferent)}`);
2615
+ continue;
2616
+ }
2617
+ const referentEntity = entriesResponse.includes?.[linkType]?.find((entity) => entity.sys.id === linkToReferent.sys.id);
2618
+ if (!referentEntity) {
2619
+ throw new Error(`Logic Error: L2-referent ${linkType} was not found within .includes (${JSON.stringify({
2620
+ linkToReferent,
2621
+ })})`);
2634
2622
  }
2623
+ linkType === 'Entry'
2624
+ ? autoFetchedReferentEntries.push(referentEntity)
2625
+ : autoFetchedReferentAssets.push(referentEntity);
2635
2626
  } // for (reference of deepReferences)
2636
2627
  return { autoFetchedReferentAssets, autoFetchedReferentEntries };
2637
2628
  }
@@ -2768,10 +2759,10 @@ const fetchReferencedEntities = async ({ client, experienceEntry, locale, }) =>
2768
2759
  assetIds.push(dataBinding.sys.id);
2769
2760
  }
2770
2761
  }
2771
- const [entriesResponse, assetsResponse] = (await Promise.all([
2762
+ const [entriesResponse, assetsResponse] = await Promise.all([
2772
2763
  fetchAllEntries({ client, ids: entryIds, locale }),
2773
2764
  fetchAllAssets({ client, ids: assetIds, locale }),
2774
- ]));
2765
+ ]);
2775
2766
  const { autoFetchedReferentAssets, autoFetchedReferentEntries } = gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse);
2776
2767
  // Using client getEntries resolves all linked entry references, so we do not need to resolve entries in usedComponents
2777
2768
  const allResolvedEntries = [