@se-studio/contentful-rest-api 1.0.38 → 1.0.40

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.d.ts CHANGED
@@ -59,8 +59,9 @@ type BaseTemplateSkeleton = EntrySkeletonType<BaseTemplateFields, 'template'>;
59
59
 
60
60
  interface BaseArticleTypeFields {
61
61
  name: EntryFieldTypes.Symbol;
62
+ cmsLabel: EntryFieldTypes.Symbol;
62
63
  slug: EntryFieldTypes.Symbol;
63
- indexPageName: EntryFieldTypes.Symbol;
64
+ indexPageTitle: EntryFieldTypes.Symbol;
64
65
  indexPageDescription: EntryFieldTypes.Symbol;
65
66
  featuredImage: EntryFieldTypes.AssetLink;
66
67
  menu?: EntryFieldTypes.EntryLink<BaseNavigationSkeleton>;
@@ -321,8 +322,9 @@ type BaseNavigationSkeleton = EntrySkeletonType<BaseNavigationFields, 'navigatio
321
322
 
322
323
  interface BaseCustomTypeFields {
323
324
  name: EntryFieldTypes.Symbol;
325
+ cmsLabel: EntryFieldTypes.Symbol;
324
326
  slug: EntryFieldTypes.Symbol;
325
- indexPageName: EntryFieldTypes.Symbol;
327
+ indexPageTitle: EntryFieldTypes.Symbol;
326
328
  indexPageDescription: EntryFieldTypes.Symbol;
327
329
  featuredImage: EntryFieldTypes.AssetLink;
328
330
  menu?: EntryFieldTypes.EntryLink<BaseNavigationSkeleton>;
package/dist/index.js CHANGED
@@ -635,6 +635,9 @@ function addPositionMetadata(items) {
635
635
  };
636
636
  });
637
637
  }
638
+ function calculateContentCount(...contents) {
639
+ return contents.reduce((acc, content) => acc + content.length, 0);
640
+ }
638
641
 
639
642
  // src/converters/asset.ts
640
643
  function convertAssetToVisual(context, asset, options) {
@@ -1175,13 +1178,6 @@ async function fetchSingleEntity(context, config, fetchConfig, options) {
1175
1178
  },
1176
1179
  requestOptions
1177
1180
  );
1178
- if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
1179
- console.log(`[Contentful Fetch] ${fetchConfig.contentType}`, {
1180
- query: fetchConfig.query,
1181
- cacheTags,
1182
- total: response.total
1183
- });
1184
- }
1185
1181
  const entry = response.items[0];
1186
1182
  if (!entry || !entry.fields) {
1187
1183
  return { data: null, errors: [] };
@@ -1981,13 +1977,16 @@ function baseArticleConverter(context, entry) {
1981
1977
  collectIconsFromNavigation(finalMenu),
1982
1978
  collectIconsFromNavigation(finalFooter)
1983
1979
  );
1980
+ const articleTitle = makeContentfulTitle(title, sys.id);
1984
1981
  const article = {
1985
1982
  type: "Article",
1986
1983
  id,
1987
1984
  slug,
1988
- title: makeContentfulTitle(title, sys.id),
1985
+ name: articleTitle,
1986
+ title: articleTitle,
1989
1987
  description: makeContentfulDescription(description, sys.id),
1990
1988
  featuredImage: lookupAsset(context, featuredImage),
1989
+ contentCount: calculateContentCount(topContent, articleContent, bottomContent),
1991
1990
  articleType: articleTypeLink,
1992
1991
  tags: tags?.map((tag) => resolveLink(context, id, tag)),
1993
1992
  contents,
@@ -2037,11 +2036,11 @@ function baseArticleTypeLinkConverter(context, entry) {
2037
2036
  `Invalid content type: expected "articleType", got "${sys.contentType.sys.id}"`
2038
2037
  );
2039
2038
  }
2040
- const { name, featuredImage, slug, ...simpleFields } = fields;
2039
+ const { name, cmsLabel, featuredImage, slug, ...simpleFields } = fields;
2041
2040
  return createInternalLink(
2042
2041
  sys.id,
2043
2042
  {
2044
- cmsLabel: name,
2043
+ cmsLabel,
2045
2044
  title: name,
2046
2045
  featuredImage,
2047
2046
  slug,
@@ -2056,8 +2055,9 @@ function baseArticleTypeConverter(context, entry, customTypeEntry) {
2056
2055
  const { sys, fields } = entry;
2057
2056
  const { id } = sys;
2058
2057
  const {
2059
- indexPageName,
2058
+ name,
2060
2059
  indexPageDescription,
2060
+ indexPageTitle,
2061
2061
  featuredImage,
2062
2062
  menu: menuLink,
2063
2063
  footer: footerLink,
@@ -2090,9 +2090,11 @@ function baseArticleTypeConverter(context, entry, customTypeEntry) {
2090
2090
  type: "Article type",
2091
2091
  id,
2092
2092
  slug,
2093
- title: makeContentfulTitle(indexPageName, sys.id),
2093
+ name,
2094
+ title: makeContentfulTitle(indexPageTitle, sys.id),
2094
2095
  description: makeContentfulDescription(indexPageDescription, sys.id),
2095
2096
  featuredImage: lookupAsset(context, featuredImage),
2097
+ contentCount: 0,
2096
2098
  contents,
2097
2099
  icons,
2098
2100
  structuredData: [
@@ -2218,8 +2220,9 @@ function baseCustomTypeConverter(context, entry) {
2218
2220
  const { sys, fields } = entry;
2219
2221
  const { id } = sys;
2220
2222
  const {
2223
+ name,
2221
2224
  slug,
2222
- indexPageName,
2225
+ indexPageTitle,
2223
2226
  indexPageDescription,
2224
2227
  featuredImage,
2225
2228
  menu: menuLink,
@@ -2242,15 +2245,17 @@ function baseCustomTypeConverter(context, entry) {
2242
2245
  collectIconsFromNavigation(menu),
2243
2246
  collectIconsFromNavigation(footer)
2244
2247
  );
2248
+ const title = makeContentfulTitle(indexPageTitle, sys.id);
2249
+ const description = makeContentfulDescription(indexPageDescription, sys.id);
2245
2250
  const customType = {
2246
2251
  type: "Custom type",
2247
2252
  id,
2248
2253
  slug,
2249
- indexPageName: makeContentfulTitle(indexPageName, sys.id),
2250
- indexPageDescription: makeContentfulDescription(indexPageDescription, sys.id),
2251
- title: makeContentfulTitle(indexPageName, sys.id),
2252
- description: makeContentfulDescription(indexPageDescription, sys.id),
2254
+ name,
2255
+ title,
2256
+ description,
2253
2257
  featuredImage: lookupAsset(context, featuredImage),
2258
+ contentCount: 0,
2254
2259
  contents,
2255
2260
  icons,
2256
2261
  structuredData: [
@@ -2274,7 +2279,7 @@ function baseCustomTypeLinkConverter(context, entry) {
2274
2279
  return createInternalLink(
2275
2280
  id,
2276
2281
  {
2277
- cmsLabel: fields.name,
2282
+ cmsLabel: fields.cmsLabel,
2278
2283
  title: fields.name,
2279
2284
  featuredImage: fields.featuredImage,
2280
2285
  backgroundColour: fields.backgroundColour,
@@ -2437,10 +2442,12 @@ function basePageConverter(context, entry) {
2437
2442
  id,
2438
2443
  isHomePage: slug === "index",
2439
2444
  slug,
2445
+ name: title,
2440
2446
  title: makeContentfulTitle(title, id),
2441
2447
  description: makeContentfulDescription(description, id),
2442
2448
  featuredImage: lookupAsset(context, featuredImage),
2443
2449
  tags: tags?.map((tag) => resolveLink(context, id, tag)),
2450
+ contentCount: calculateContentCount(topContent, pageContent, bottomContent),
2444
2451
  contents,
2445
2452
  icons,
2446
2453
  structuredData: structuredData?.map((link) => resolveSchema(context, id, link)).filter((item) => item !== null),
@@ -2586,12 +2593,14 @@ function basePersonConverter(context, entry, customTypeEntry) {
2586
2593
  type: "Person",
2587
2594
  id,
2588
2595
  slug,
2596
+ name,
2589
2597
  title: makeContentfulTitle(name, id),
2590
2598
  description: description ?? `Description for ${id}`,
2591
2599
  featuredImage: lookupAsset(context, media),
2592
2600
  // Person uses 'media' not 'featuredImage'
2593
2601
  href: context.urlCalculators.person(slug),
2594
2602
  bio: resolveRichTextDocument(context, id, bioField) ?? null,
2603
+ contentCount: calculateContentCount(personContent),
2595
2604
  contents,
2596
2605
  menu,
2597
2606
  footer,
@@ -2605,7 +2614,7 @@ function basePersonConverter(context, entry, customTypeEntry) {
2605
2614
  // src/converters/tag.ts
2606
2615
  function baseTagLinkConverter(context, entry) {
2607
2616
  const { sys, fields } = entry;
2608
- const { name, ...simpleFields } = fields;
2617
+ const { name, cmsLabel, ...simpleFields } = fields;
2609
2618
  if (sys.contentType.sys.id !== "tag") {
2610
2619
  throw new Error(`Invalid content type: expected "tag", got "${sys.contentType.sys.id}"`);
2611
2620
  }
@@ -2613,6 +2622,8 @@ function baseTagLinkConverter(context, entry) {
2613
2622
  sys.id,
2614
2623
  {
2615
2624
  ...simpleFields,
2625
+ cmsLabel,
2626
+ useName: false,
2616
2627
  title: name
2617
2628
  },
2618
2629
  context,
@@ -2658,10 +2669,12 @@ function baseTagConverter(context, entry, customTypeEntry) {
2658
2669
  type: "Tag",
2659
2670
  id,
2660
2671
  slug,
2672
+ name,
2661
2673
  title: makeContentfulTitle(name, sys.id),
2662
2674
  description: makeContentfulDescription(description, sys.id),
2663
2675
  featuredImage: lookupAsset(context, featuredImage),
2664
2676
  tagType: tagTypeName ?? null,
2677
+ contentCount: calculateContentCount(topContent),
2665
2678
  contents,
2666
2679
  icons,
2667
2680
  structuredData: structuredData?.map((link) => resolveSchema(context, id, link)).filter((item) => item !== null),