@contentful/experiences-core 1.20.1 → 1.21.0-beta.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 +53 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2047,7 +2047,7 @@ const getBoundValue = (entryOrAsset, path) => {
|
|
|
2047
2047
|
: value;
|
|
2048
2048
|
};
|
|
2049
2049
|
|
|
2050
|
-
const transformRichText = (entryOrAsset, path) => {
|
|
2050
|
+
const transformRichText = (entryOrAsset, entityStore, path) => {
|
|
2051
2051
|
const value = getBoundValue(entryOrAsset, path);
|
|
2052
2052
|
if (typeof value === 'string') {
|
|
2053
2053
|
return {
|
|
@@ -2070,6 +2070,17 @@ const transformRichText = (entryOrAsset, path) => {
|
|
|
2070
2070
|
};
|
|
2071
2071
|
}
|
|
2072
2072
|
if (typeof value === 'object' && value.nodeType === BLOCKS.DOCUMENT) {
|
|
2073
|
+
//resolve any embedded links - we currently only support resolving embedded in the first entry
|
|
2074
|
+
const richTextDocument = value;
|
|
2075
|
+
richTextDocument.content.forEach((node) => {
|
|
2076
|
+
if ((node.nodeType === BLOCKS.EMBEDDED_ENTRY || node.nodeType === BLOCKS.EMBEDDED_ASSET) &&
|
|
2077
|
+
node.data.target.sys.type === 'Link') {
|
|
2078
|
+
const entity = entityStore.getEntityFromLink(node.data.target);
|
|
2079
|
+
if (entity) {
|
|
2080
|
+
node.data.target = entity;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
2073
2084
|
return value;
|
|
2074
2085
|
}
|
|
2075
2086
|
return undefined;
|
|
@@ -2229,6 +2240,30 @@ function getResolvedEntryFromLink(entryOrAsset, path, entityStore) {
|
|
|
2229
2240
|
}
|
|
2230
2241
|
//Look up the reference in the entity store
|
|
2231
2242
|
const resolvedEntity = entityStore.getEntityFromLink(value);
|
|
2243
|
+
if (!resolvedEntity) {
|
|
2244
|
+
return;
|
|
2245
|
+
}
|
|
2246
|
+
//resolve any embedded links - we currently only support 2 levels deep
|
|
2247
|
+
const fields = resolvedEntity.fields || {};
|
|
2248
|
+
Object.entries(fields).forEach(([fieldKey, field]) => {
|
|
2249
|
+
if (field && field.sys?.type === 'Link') {
|
|
2250
|
+
const entity = entityStore.getEntityFromLink(field);
|
|
2251
|
+
if (entity) {
|
|
2252
|
+
resolvedEntity.fields[fieldKey] = entity;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
else if (field && Array.isArray(field)) {
|
|
2256
|
+
resolvedEntity.fields[fieldKey] = field.map((innerField) => {
|
|
2257
|
+
if (innerField && innerField.sys?.type === 'Link') {
|
|
2258
|
+
const entity = entityStore.getEntityFromLink(innerField);
|
|
2259
|
+
if (entity) {
|
|
2260
|
+
return entity;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
return innerField;
|
|
2264
|
+
});
|
|
2265
|
+
}
|
|
2266
|
+
});
|
|
2232
2267
|
return resolvedEntity;
|
|
2233
2268
|
}
|
|
2234
2269
|
|
|
@@ -2246,7 +2281,21 @@ function getArrayValue(entryOrAsset, path, entityStore) {
|
|
|
2246
2281
|
return value;
|
|
2247
2282
|
}
|
|
2248
2283
|
else if (value?.sys?.type === 'Link') {
|
|
2249
|
-
|
|
2284
|
+
const resolvedEntity = entityStore.getEntityFromLink(value);
|
|
2285
|
+
if (!resolvedEntity) {
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
//resolve any embedded links - we currently only support 2 levels deep
|
|
2289
|
+
const fields = resolvedEntity.fields || {};
|
|
2290
|
+
Object.entries(fields).forEach(([fieldKey, field]) => {
|
|
2291
|
+
if (field && field.sys?.type === 'Link') {
|
|
2292
|
+
const entity = entityStore.getEntityFromLink(field);
|
|
2293
|
+
if (entity) {
|
|
2294
|
+
resolvedEntity.fields[fieldKey] = entity;
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
});
|
|
2298
|
+
return resolvedEntity;
|
|
2250
2299
|
}
|
|
2251
2300
|
else {
|
|
2252
2301
|
console.warn(`Expected value to be a string or Link, but got: ${JSON.stringify(value)}`);
|
|
@@ -2268,7 +2317,7 @@ const transformBoundContentValue = (variables, entityStore, binding, resolveDesi
|
|
|
2268
2317
|
}
|
|
2269
2318
|
return transformMedia(entityOrAsset, variables, resolveDesignValue, variableName, path);
|
|
2270
2319
|
case 'RichText':
|
|
2271
|
-
return transformRichText(entityOrAsset, path);
|
|
2320
|
+
return transformRichText(entityOrAsset, entityStore, path);
|
|
2272
2321
|
case 'Array':
|
|
2273
2322
|
return getArrayValue(entityOrAsset, path, entityStore);
|
|
2274
2323
|
case 'Link':
|
|
@@ -3417,7 +3466,7 @@ const fetchAllEntries = async ({ client, ids, locale, skip = 0, limit = 100, res
|
|
|
3417
3466
|
},
|
|
3418
3467
|
};
|
|
3419
3468
|
}
|
|
3420
|
-
const query = { 'sys.id[in]': ids, locale, limit, skip };
|
|
3469
|
+
const query = { 'sys.id[in]': ids, locale, limit, skip, include: 2 };
|
|
3421
3470
|
const { items, includes, total: responseTotal, } = await client.withoutLinkResolution.getEntries({ ...query });
|
|
3422
3471
|
responseItems.push(...items);
|
|
3423
3472
|
responseIncludes?.Entry?.push(...(includes?.Entry || []));
|