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

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
@@ -233,8 +233,12 @@ interface BaseExternalComponentFields {
233
233
  externalComponentType: EntryFieldTypes.Symbol<string>;
234
234
  heading?: EntryFieldTypes.Symbol;
235
235
  data: EntryFieldTypes.Object;
236
+ html: EntryFieldTypes.Text;
236
237
  backgroundColour?: EntryFieldTypes.Symbol<string>;
237
238
  textColour?: EntryFieldTypes.Symbol<string>;
239
+ backgroundVisual?: EntryFieldTypes.AssetLink;
240
+ mobileBackgroundVisual?: EntryFieldTypes.AssetLink;
241
+ backgroundOverlayOpacity?: EntryFieldTypes.Number;
238
242
  }
239
243
  type BaseExternalComponentSkeleton = EntrySkeletonType<BaseExternalComponentFields, 'externalComponent'>;
240
244
 
package/dist/index.js CHANGED
@@ -591,6 +591,7 @@ function createInternalLink(id, fields, context, href, internalType, additionalP
591
591
  const {
592
592
  cmsLabel,
593
593
  title,
594
+ name,
594
595
  useName,
595
596
  featuredImage,
596
597
  backgroundColour,
@@ -605,7 +606,7 @@ function createInternalLink(id, fields, context, href, internalType, additionalP
605
606
  type: "Internal link",
606
607
  internalType,
607
608
  id,
608
- name: cmsLabel ?? "",
609
+ name: name ?? cmsLabel ?? "",
609
610
  useName,
610
611
  text,
611
612
  visual: lookupAsset(context, featuredImage),
@@ -986,19 +987,42 @@ function collectIconsFromNavigation(navigation) {
986
987
  }
987
988
  return icons;
988
989
  }
990
+ function collectIconsFromRichText(richText, processContent) {
991
+ if (!richText?.json) {
992
+ return;
993
+ }
994
+ const traverseNode = (node) => {
995
+ if (node.data?.target && typeof node.data.target === "object" && "type" in node.data.target && "id" in node.data.target) {
996
+ processContent(node.data.target);
997
+ }
998
+ if ("content" in node && Array.isArray(node.content)) {
999
+ for (const child of node.content) {
1000
+ if (typeof child === "object" && child !== null && "nodeType" in child) {
1001
+ traverseNode(child);
1002
+ }
1003
+ }
1004
+ }
1005
+ };
1006
+ traverseNode(richText.json);
1007
+ }
989
1008
  function collectIconsFromContent(contents) {
990
1009
  if (!contents) {
991
1010
  return [];
992
1011
  }
993
1012
  const icons = [];
994
1013
  const seenIds = /* @__PURE__ */ new Set();
1014
+ const processedIds = /* @__PURE__ */ new Set();
995
1015
  function addIcon(icon) {
996
1016
  if (!seenIds.has(icon.id)) {
997
1017
  seenIds.add(icon.id);
998
1018
  icons.push(icon);
999
1019
  }
1000
1020
  }
1001
- for (const content of contents) {
1021
+ function processContentItem(content) {
1022
+ if (processedIds.has(content.id)) {
1023
+ return;
1024
+ }
1025
+ processedIds.add(content.id);
1002
1026
  if (content.type === "Component") {
1003
1027
  const componentIcons = collectIconsFromComponent(content);
1004
1028
  for (const icon of componentIcons) {
@@ -1006,11 +1030,12 @@ function collectIconsFromContent(contents) {
1006
1030
  }
1007
1031
  const component = content;
1008
1032
  if (component.contents) {
1009
- const nestedIcons = collectIconsFromContent(component.contents);
1010
- for (const icon of nestedIcons) {
1011
- addIcon(icon);
1033
+ for (const nested of component.contents) {
1034
+ processContentItem(nested);
1012
1035
  }
1013
1036
  }
1037
+ collectIconsFromRichText(component.body, processContentItem);
1038
+ collectIconsFromRichText(component.additionalCopy, processContentItem);
1014
1039
  }
1015
1040
  if (content.type === "Collection") {
1016
1041
  const collectionIcons = collectIconsFromCollection(content);
@@ -1019,11 +1044,14 @@ function collectIconsFromContent(contents) {
1019
1044
  }
1020
1045
  const collection = content;
1021
1046
  if (collection.contents) {
1022
- const nestedIcons = collectIconsFromContent(collection.contents);
1023
- for (const icon of nestedIcons) {
1024
- addIcon(icon);
1047
+ for (const nested of collection.contents) {
1048
+ if (typeof nested === "object" && nested !== null && "type" in nested && "id" in nested) {
1049
+ processContentItem(nested);
1050
+ }
1025
1051
  }
1026
1052
  }
1053
+ collectIconsFromRichText(collection.body, processContentItem);
1054
+ collectIconsFromRichText(collection.additionalCopy, processContentItem);
1027
1055
  }
1028
1056
  if (content.type === "Internal link" || content.type === "External link" || content.type === "Download link" || content.type === "Blank link") {
1029
1057
  const link = content;
@@ -1035,6 +1063,9 @@ function collectIconsFromContent(contents) {
1035
1063
  }
1036
1064
  }
1037
1065
  }
1066
+ for (const content of contents) {
1067
+ processContentItem(content);
1068
+ }
1038
1069
  return icons;
1039
1070
  }
1040
1071
  function deduplicateIcons(...iconArrays) {
@@ -2020,14 +2051,21 @@ function baseArticleLinkConverter(context, entry) {
2020
2051
  const author = fieldsAuthor ? resolveLink(context, sys.id, fieldsAuthor) : void 0;
2021
2052
  const download = lookupDownloadAsset(context, fieldsDownload);
2022
2053
  const href = externalLink ? externalLink : context.urlCalculators.article(articleType.slug, fields.slug, primaryTag?.slug);
2023
- return createInternalLink(sys.id, simpleFields, context, href, "Article", {
2024
- tags,
2025
- primaryTag,
2026
- articleType,
2027
- date,
2028
- author,
2029
- download
2030
- });
2054
+ return createInternalLink(
2055
+ sys.id,
2056
+ { ...simpleFields, name: fields.cmsLabel },
2057
+ context,
2058
+ href,
2059
+ "Article",
2060
+ {
2061
+ tags,
2062
+ primaryTag,
2063
+ articleType,
2064
+ date,
2065
+ author,
2066
+ download
2067
+ }
2068
+ );
2031
2069
  }
2032
2070
  function baseArticleTypeLinkConverter(context, entry) {
2033
2071
  const { sys, fields } = entry;
@@ -2041,6 +2079,7 @@ function baseArticleTypeLinkConverter(context, entry) {
2041
2079
  sys.id,
2042
2080
  {
2043
2081
  cmsLabel,
2082
+ name,
2044
2083
  title: name,
2045
2084
  featuredImage,
2046
2085
  slug,
@@ -2278,16 +2317,7 @@ function baseCustomTypeLinkConverter(context, entry) {
2278
2317
  }
2279
2318
  return createInternalLink(
2280
2319
  id,
2281
- {
2282
- cmsLabel: fields.cmsLabel,
2283
- title: fields.name,
2284
- featuredImage: fields.featuredImage,
2285
- backgroundColour: fields.backgroundColour,
2286
- textColour: fields.textColour,
2287
- indexed: fields.indexed,
2288
- hidden: fields.hidden,
2289
- slug: fields.slug
2290
- },
2320
+ fields,
2291
2321
  context,
2292
2322
  context.urlCalculators.customType(fields.slug),
2293
2323
  "CustomType"
@@ -2295,9 +2325,18 @@ function baseCustomTypeLinkConverter(context, entry) {
2295
2325
  }
2296
2326
 
2297
2327
  // src/converters/externalComponent.ts
2298
- function baseExternalComponentConverter(_context, entry) {
2328
+ function baseExternalComponentConverter(context, entry) {
2299
2329
  const { sys, fields } = entry;
2300
- const { cmsLabel, ...simpleFields } = fields;
2330
+ const {
2331
+ cmsLabel,
2332
+ backgroundVisual: bgVisual,
2333
+ mobileBackgroundVisual: mobileBgVisual,
2334
+ ...simpleFields
2335
+ } = fields;
2336
+ const backgroundVisual = createResponsiveVisual(
2337
+ lookupAsset(context, bgVisual),
2338
+ lookupAsset(context, mobileBgVisual)
2339
+ );
2301
2340
  const externalComponent = {
2302
2341
  type: "External component",
2303
2342
  id: sys.id,
@@ -2305,8 +2344,7 @@ function baseExternalComponentConverter(_context, entry) {
2305
2344
  cmsLabel,
2306
2345
  ...DEFAULT_POSITION_FIELDS,
2307
2346
  ...simpleFields,
2308
- backgroundOverlayOpacity: null,
2309
- backgroundVisual: void 0
2347
+ backgroundVisual
2310
2348
  };
2311
2349
  return externalComponent;
2312
2350
  }
@@ -2474,14 +2512,8 @@ function basePageLinkConverter(context, entry) {
2474
2512
  return createInternalLink(
2475
2513
  id,
2476
2514
  {
2477
- cmsLabel: fields.cmsLabel,
2478
- title: fields.title,
2479
- featuredImage: fields.featuredImage,
2480
- backgroundColour: fields.backgroundColour,
2481
- textColour: fields.textColour,
2482
- indexed: fields.indexed,
2483
- hidden: fields.hidden,
2484
- slug: fields.slug
2515
+ ...fields,
2516
+ name: fields.cmsLabel
2485
2517
  },
2486
2518
  context,
2487
2519
  context.urlCalculators.page(fields.slug),
@@ -2503,14 +2535,8 @@ function basePageVariantLinkConverter(context, entry) {
2503
2535
  return createInternalLink(
2504
2536
  id,
2505
2537
  {
2506
- cmsLabel: fields.cmsLabel,
2507
- title: fields.title,
2508
- featuredImage: fields.featuredImage,
2509
- backgroundColour: fields.backgroundColour,
2510
- textColour: fields.textColour,
2511
- indexed: fields.indexed,
2512
- hidden: fields.hidden,
2513
- slug: fields.slug
2538
+ ...fields,
2539
+ name: fields.cmsLabel
2514
2540
  },
2515
2541
  context,
2516
2542
  context.urlCalculators.pageVariant(fields.slug),
@@ -2541,6 +2567,7 @@ function basePersonLinkConverter(context, entry) {
2541
2567
  sys.id,
2542
2568
  {
2543
2569
  ...simpleFields,
2570
+ name,
2544
2571
  title,
2545
2572
  featuredImage: media,
2546
2573
  cmsLabel: title
@@ -2623,6 +2650,7 @@ function baseTagLinkConverter(context, entry) {
2623
2650
  {
2624
2651
  ...simpleFields,
2625
2652
  cmsLabel,
2653
+ name,
2626
2654
  useName: false,
2627
2655
  title: name
2628
2656
  },