@contentful/experiences-core 1.30.0-beta.0 → 1.30.0-dev-20250128T1255-64f728a.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 +6 -35
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3570,22 +3570,22 @@ const fetchReferencedEntities = async ({ client, experienceEntry, locale, }) =>
|
|
|
3570
3570
|
throw new Error('Failed to fetch experience entities. Provided "experienceEntry" does not match experience entry schema');
|
|
3571
3571
|
}
|
|
3572
3572
|
const deepReferences = gatherDeepReferencesFromExperienceEntry(experienceEntry);
|
|
3573
|
-
const entryIds =
|
|
3574
|
-
const assetIds =
|
|
3573
|
+
const entryIds = [];
|
|
3574
|
+
const assetIds = [];
|
|
3575
3575
|
for (const dataBinding of Object.values(experienceEntry.fields.dataSource)) {
|
|
3576
3576
|
if (!('sys' in dataBinding)) {
|
|
3577
3577
|
continue;
|
|
3578
3578
|
}
|
|
3579
3579
|
if (dataBinding.sys.linkType === 'Entry') {
|
|
3580
|
-
entryIds.
|
|
3580
|
+
entryIds.push(dataBinding.sys.id);
|
|
3581
3581
|
}
|
|
3582
3582
|
if (dataBinding.sys.linkType === 'Asset') {
|
|
3583
|
-
assetIds.
|
|
3583
|
+
assetIds.push(dataBinding.sys.id);
|
|
3584
3584
|
}
|
|
3585
3585
|
}
|
|
3586
3586
|
const [entriesResponse, assetsResponse] = await Promise.all([
|
|
3587
|
-
fetchAllEntries({ client, ids:
|
|
3588
|
-
fetchAllAssets({ client, ids:
|
|
3587
|
+
fetchAllEntries({ client, ids: entryIds, locale }),
|
|
3588
|
+
fetchAllAssets({ client, ids: assetIds, locale }),
|
|
3589
3589
|
]);
|
|
3590
3590
|
const { autoFetchedReferentAssets, autoFetchedReferentEntries } = gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse);
|
|
3591
3591
|
// Using client getEntries resolves all linked entry references, so we do not need to resolve entries in usedComponents
|
|
@@ -3640,33 +3640,6 @@ const removeCircularPatternReferences = (experienceEntry, _parentIds) => {
|
|
|
3640
3640
|
// @ts-expect-error - type of usedComponents doesn't yet allow a mixed list of both links and entries
|
|
3641
3641
|
experienceEntry.fields.usedComponents = newUsedComponents;
|
|
3642
3642
|
};
|
|
3643
|
-
/**
|
|
3644
|
-
* The CMA client will automatically replace links with entry references if they are available.
|
|
3645
|
-
* While we're not fetching the data sources, a self reference would be replaced as the entry is
|
|
3646
|
-
* fetched. Any circuar reference in the object breaks SSR where we have to stringify the JSON.
|
|
3647
|
-
* This would fail if the object contains circular references.
|
|
3648
|
-
*/
|
|
3649
|
-
const removeSelfReferencingDataSource = (experienceEntry) => {
|
|
3650
|
-
const dataSources = experienceEntry.fields.dataSource;
|
|
3651
|
-
const newDataSource = Object.entries(dataSources).reduce((acc, [key, linkOrEntry]) => {
|
|
3652
|
-
if ('fields' in linkOrEntry && linkOrEntry.sys.id === experienceEntry.sys.id) {
|
|
3653
|
-
const entry = linkOrEntry;
|
|
3654
|
-
acc[key] = {
|
|
3655
|
-
sys: {
|
|
3656
|
-
id: entry.sys.id,
|
|
3657
|
-
linkType: 'Entry',
|
|
3658
|
-
type: 'Link',
|
|
3659
|
-
},
|
|
3660
|
-
};
|
|
3661
|
-
}
|
|
3662
|
-
else {
|
|
3663
|
-
const link = linkOrEntry;
|
|
3664
|
-
acc[key] = link;
|
|
3665
|
-
}
|
|
3666
|
-
return acc;
|
|
3667
|
-
}, {});
|
|
3668
|
-
experienceEntry.fields.dataSource = newDataSource;
|
|
3669
|
-
};
|
|
3670
3643
|
|
|
3671
3644
|
const errorMessagesWhileFetching$1 = {
|
|
3672
3645
|
experience: 'Failed to fetch experience',
|
|
@@ -3698,7 +3671,6 @@ async function fetchBySlug({ client, experienceTypeId, slug, localeCode, isEdito
|
|
|
3698
3671
|
throw new Error(`No experience entry with slug: ${slug} exists`);
|
|
3699
3672
|
}
|
|
3700
3673
|
removeCircularPatternReferences(experienceEntry);
|
|
3701
|
-
removeSelfReferencingDataSource(experienceEntry);
|
|
3702
3674
|
try {
|
|
3703
3675
|
const { entries, assets } = await fetchReferencedEntities({
|
|
3704
3676
|
client,
|
|
@@ -3752,7 +3724,6 @@ async function fetchById({ client, experienceTypeId, id, localeCode, isEditorMod
|
|
|
3752
3724
|
throw new Error(`No experience entry with id: ${id} exists`);
|
|
3753
3725
|
}
|
|
3754
3726
|
removeCircularPatternReferences(experienceEntry);
|
|
3755
|
-
removeSelfReferencingDataSource(experienceEntry);
|
|
3756
3727
|
try {
|
|
3757
3728
|
const { entries, assets } = await fetchReferencedEntities({
|
|
3758
3729
|
client,
|