@se-studio/contentful-rest-api 1.0.37 → 1.0.39

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,9 +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
- indexPageSlug: EntryFieldTypes.Symbol;
64
+ indexPageTitle: EntryFieldTypes.Symbol;
65
65
  indexPageDescription: EntryFieldTypes.Symbol;
66
66
  featuredImage: EntryFieldTypes.AssetLink;
67
67
  menu?: EntryFieldTypes.EntryLink<BaseNavigationSkeleton>;
@@ -322,9 +322,9 @@ type BaseNavigationSkeleton = EntrySkeletonType<BaseNavigationFields, 'navigatio
322
322
 
323
323
  interface BaseCustomTypeFields {
324
324
  name: EntryFieldTypes.Symbol;
325
+ cmsLabel: EntryFieldTypes.Symbol;
325
326
  slug: EntryFieldTypes.Symbol;
326
- indexPageName: EntryFieldTypes.Symbol;
327
- indexPageSlug: EntryFieldTypes.Symbol;
327
+ indexPageTitle: EntryFieldTypes.Symbol;
328
328
  indexPageDescription: EntryFieldTypes.Symbol;
329
329
  featuredImage: EntryFieldTypes.AssetLink;
330
330
  menu?: EntryFieldTypes.EntryLink<BaseNavigationSkeleton>;
@@ -448,7 +448,7 @@ declare function contentfulArticleRest(context: BaseConverterContext, config: Co
448
448
  interface ArticleTypeFetchOptions extends FetchOptions {
449
449
  customType?: string;
450
450
  }
451
- declare function contentfulArticleTypeRest(context: BaseConverterContext, config: ContentfulConfig, indexPageSlug: string, options?: ArticleTypeFetchOptions): Promise<CmsResponse<IBaseArticleType | null>>;
451
+ declare function contentfulArticleTypeRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, options?: ArticleTypeFetchOptions): Promise<CmsResponse<IBaseArticleType | null>>;
452
452
 
453
453
  interface ContentfulResponse<T = any> {
454
454
  sys: {
@@ -526,7 +526,7 @@ declare function createDownloadHandler(config: DownloadHandlerConfig): (_request
526
526
 
527
527
  declare function createBaseConverterContext(urlCalculators: UrlCalculators): BaseConverterContext;
528
528
 
529
- declare function contentfulCustomTypeRest(context: BaseConverterContext, config: ContentfulConfig, indexPageSlug: string, options?: FetchOptions): Promise<CmsResponse<IBaseCustomType | null>>;
529
+ declare function contentfulCustomTypeRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, options?: FetchOptions): Promise<CmsResponse<IBaseCustomType | null>>;
530
530
 
531
531
  type DefaultChainModifier = 'WITHOUT_LINK_RESOLUTION';
532
532
  interface IContentfulRichText {
package/dist/index.js CHANGED
@@ -1175,13 +1175,6 @@ async function fetchSingleEntity(context, config, fetchConfig, options) {
1175
1175
  },
1176
1176
  requestOptions
1177
1177
  );
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
1178
  const entry = response.items[0];
1186
1179
  if (!entry || !entry.fields) {
1187
1180
  return { data: null, errors: [] };
@@ -1323,9 +1316,9 @@ async function contentfulArticleRest(context, config, slug, articleTypeSlug, opt
1323
1316
 
1324
1317
  // src/api/article-type.ts
1325
1318
  init_utils();
1326
- async function contentfulArticleTypeRest(context, config, indexPageSlug, options) {
1319
+ async function contentfulArticleTypeRest(context, config, slug, options) {
1327
1320
  const client = getContentfulClient(config, options?.preview);
1328
- const articleTypeCacheTags = getCacheTags("articleType", indexPageSlug, options?.preview);
1321
+ const articleTypeCacheTags = getCacheTags("articleType", slug, options?.preview);
1329
1322
  const customTypeCacheTags = options?.customType ? getCacheTags("customType", options.customType, options?.preview) : [];
1330
1323
  const requestOptions = {
1331
1324
  ...options,
@@ -1338,7 +1331,7 @@ async function contentfulArticleTypeRest(context, config, indexPageSlug, options
1338
1331
  const articleTypePromise = client.getEntries(
1339
1332
  {
1340
1333
  content_type: "articleType",
1341
- "fields.indexPageSlug": indexPageSlug,
1334
+ "fields.slug": slug,
1342
1335
  include: 10,
1343
1336
  locale: options?.locale,
1344
1337
  limit: 1
@@ -1391,7 +1384,7 @@ async function contentfulArticleTypeRest(context, config, indexPageSlug, options
1391
1384
  if (fullContext.errors.length > 0 && typeof process !== "undefined" && process.env?.NODE_ENV === "production") {
1392
1385
  console.error(`CMS conversion errors for articleType:`, {
1393
1386
  entryId: articleTypeEntry.sys.id,
1394
- indexPageSlug,
1387
+ slug,
1395
1388
  errors: fullContext.errors
1396
1389
  });
1397
1390
  }
@@ -1981,11 +1974,13 @@ function baseArticleConverter(context, entry) {
1981
1974
  collectIconsFromNavigation(finalMenu),
1982
1975
  collectIconsFromNavigation(finalFooter)
1983
1976
  );
1977
+ const articleTitle = makeContentfulTitle(title, sys.id);
1984
1978
  const article = {
1985
1979
  type: "Article",
1986
1980
  id,
1987
1981
  slug,
1988
- title: makeContentfulTitle(title, sys.id),
1982
+ name: articleTitle,
1983
+ title: articleTitle,
1989
1984
  description: makeContentfulDescription(description, sys.id),
1990
1985
  featuredImage: lookupAsset(context, featuredImage),
1991
1986
  articleType: articleTypeLink,
@@ -2037,31 +2032,28 @@ function baseArticleTypeLinkConverter(context, entry) {
2037
2032
  `Invalid content type: expected "articleType", got "${sys.contentType.sys.id}"`
2038
2033
  );
2039
2034
  }
2035
+ const { name, cmsLabel, featuredImage, slug, ...simpleFields } = fields;
2040
2036
  return createInternalLink(
2041
2037
  sys.id,
2042
2038
  {
2043
- cmsLabel: fields.name,
2044
- title: fields.name,
2045
- featuredImage: fields.featuredImage,
2046
- backgroundColour: fields.backgroundColour,
2047
- textColour: fields.textColour,
2048
- indexed: fields.indexed,
2049
- hidden: fields.hidden,
2050
- slug: fields.slug
2039
+ cmsLabel,
2040
+ title: name,
2041
+ featuredImage,
2042
+ slug,
2043
+ ...simpleFields
2051
2044
  },
2052
2045
  context,
2053
- context.urlCalculators.articleType(fields.slug),
2054
- "ArticleType",
2055
- { indexPageSlug: fields.indexPageSlug }
2046
+ context.urlCalculators.articleType(slug),
2047
+ "ArticleType"
2056
2048
  );
2057
2049
  }
2058
2050
  function baseArticleTypeConverter(context, entry, customTypeEntry) {
2059
2051
  const { sys, fields } = entry;
2060
2052
  const { id } = sys;
2061
2053
  const {
2062
- indexPageSlug,
2063
- indexPageName,
2054
+ name,
2064
2055
  indexPageDescription,
2056
+ indexPageTitle,
2065
2057
  featuredImage,
2066
2058
  menu: menuLink,
2067
2059
  footer: footerLink,
@@ -2069,13 +2061,13 @@ function baseArticleTypeConverter(context, entry, customTypeEntry) {
2069
2061
  indexPageTopContent: topContentLinks,
2070
2062
  structuredData,
2071
2063
  indexPageStructuredData,
2072
- slug: _slug,
2064
+ slug,
2073
2065
  ...other
2074
2066
  } = fields;
2075
2067
  const customType = customTypeEntry ? context.customTypeResolver(context, customTypeEntry) : void 0;
2076
2068
  let template = templateLink ? resolveTemplate(context, templateLink) : null;
2077
- if (!template && customTypeEntry?.fields.indexPageTemplate) {
2078
- template = resolveTemplate(context, customTypeEntry.fields.indexPageTemplate);
2069
+ if (!template && customTypeEntry?.fields.template) {
2070
+ template = resolveTemplate(context, customTypeEntry.fields.template);
2079
2071
  }
2080
2072
  const menu = menuLink ? resolveNavigation(context, menuLink) : customTypeEntry?.fields.menu ? resolveNavigation(context, customTypeEntry.fields.menu) : template?.menu;
2081
2073
  const footer = footerLink ? resolveNavigation(context, footerLink) : customTypeEntry?.fields.footer ? resolveNavigation(context, customTypeEntry.fields.footer) : template?.footer;
@@ -2093,8 +2085,9 @@ function baseArticleTypeConverter(context, entry, customTypeEntry) {
2093
2085
  const articleType = {
2094
2086
  type: "Article type",
2095
2087
  id,
2096
- slug: indexPageSlug,
2097
- title: makeContentfulTitle(indexPageName, sys.id),
2088
+ slug,
2089
+ name,
2090
+ title: makeContentfulTitle(indexPageTitle, sys.id),
2098
2091
  description: makeContentfulDescription(indexPageDescription, sys.id),
2099
2092
  featuredImage: lookupAsset(context, featuredImage),
2100
2093
  contents,
@@ -2222,9 +2215,9 @@ function baseCustomTypeConverter(context, entry) {
2222
2215
  const { sys, fields } = entry;
2223
2216
  const { id } = sys;
2224
2217
  const {
2218
+ name,
2225
2219
  slug,
2226
- indexPageSlug,
2227
- indexPageName,
2220
+ indexPageTitle,
2228
2221
  indexPageDescription,
2229
2222
  featuredImage,
2230
2223
  menu: menuLink,
@@ -2247,15 +2240,15 @@ function baseCustomTypeConverter(context, entry) {
2247
2240
  collectIconsFromNavigation(menu),
2248
2241
  collectIconsFromNavigation(footer)
2249
2242
  );
2243
+ const title = makeContentfulTitle(indexPageTitle, sys.id);
2244
+ const description = makeContentfulDescription(indexPageDescription, sys.id);
2250
2245
  const customType = {
2251
2246
  type: "Custom type",
2252
2247
  id,
2253
2248
  slug,
2254
- indexPageSlug,
2255
- indexPageName: makeContentfulTitle(indexPageName, sys.id),
2256
- indexPageDescription: makeContentfulDescription(indexPageDescription, sys.id),
2257
- title: makeContentfulTitle(indexPageName, sys.id),
2258
- description: makeContentfulDescription(indexPageDescription, sys.id),
2249
+ name,
2250
+ title,
2251
+ description,
2259
2252
  featuredImage: lookupAsset(context, featuredImage),
2260
2253
  contents,
2261
2254
  icons,
@@ -2280,17 +2273,17 @@ function baseCustomTypeLinkConverter(context, entry) {
2280
2273
  return createInternalLink(
2281
2274
  id,
2282
2275
  {
2283
- cmsLabel: fields.name,
2276
+ cmsLabel: fields.cmsLabel,
2284
2277
  title: fields.name,
2285
2278
  featuredImage: fields.featuredImage,
2286
2279
  backgroundColour: fields.backgroundColour,
2287
2280
  textColour: fields.textColour,
2288
2281
  indexed: fields.indexed,
2289
2282
  hidden: fields.hidden,
2290
- slug: fields.indexPageSlug
2283
+ slug: fields.slug
2291
2284
  },
2292
2285
  context,
2293
- context.urlCalculators.customType(fields.indexPageSlug),
2286
+ context.urlCalculators.customType(fields.slug),
2294
2287
  "CustomType"
2295
2288
  );
2296
2289
  }
@@ -2443,6 +2436,7 @@ function basePageConverter(context, entry) {
2443
2436
  id,
2444
2437
  isHomePage: slug === "index",
2445
2438
  slug,
2439
+ name: title,
2446
2440
  title: makeContentfulTitle(title, id),
2447
2441
  description: makeContentfulDescription(description, id),
2448
2442
  featuredImage: lookupAsset(context, featuredImage),
@@ -2592,6 +2586,7 @@ function basePersonConverter(context, entry, customTypeEntry) {
2592
2586
  type: "Person",
2593
2587
  id,
2594
2588
  slug,
2589
+ name,
2595
2590
  title: makeContentfulTitle(name, id),
2596
2591
  description: description ?? `Description for ${id}`,
2597
2592
  featuredImage: lookupAsset(context, media),
@@ -2611,7 +2606,7 @@ function basePersonConverter(context, entry, customTypeEntry) {
2611
2606
  // src/converters/tag.ts
2612
2607
  function baseTagLinkConverter(context, entry) {
2613
2608
  const { sys, fields } = entry;
2614
- const { name, ...simpleFields } = fields;
2609
+ const { name, cmsLabel, ...simpleFields } = fields;
2615
2610
  if (sys.contentType.sys.id !== "tag") {
2616
2611
  throw new Error(`Invalid content type: expected "tag", got "${sys.contentType.sys.id}"`);
2617
2612
  }
@@ -2619,6 +2614,8 @@ function baseTagLinkConverter(context, entry) {
2619
2614
  sys.id,
2620
2615
  {
2621
2616
  ...simpleFields,
2617
+ cmsLabel,
2618
+ useName: false,
2622
2619
  title: name
2623
2620
  },
2624
2621
  context,
@@ -2664,6 +2661,7 @@ function baseTagConverter(context, entry, customTypeEntry) {
2664
2661
  type: "Tag",
2665
2662
  id,
2666
2663
  slug,
2664
+ name,
2667
2665
  title: makeContentfulTitle(name, sys.id),
2668
2666
  description: makeContentfulDescription(description, sys.id),
2669
2667
  featuredImage: lookupAsset(context, featuredImage),
@@ -2720,17 +2718,17 @@ function createBaseConverterContext(urlCalculators) {
2720
2718
  }
2721
2719
 
2722
2720
  // src/api/custom-type.ts
2723
- async function contentfulCustomTypeRest(context, config, indexPageSlug, options) {
2721
+ async function contentfulCustomTypeRest(context, config, slug, options) {
2724
2722
  return fetchSingleEntity(
2725
2723
  context,
2726
2724
  config,
2727
2725
  {
2728
2726
  contentType: "customType",
2729
2727
  cacheTagType: "customType",
2730
- cacheTagIdentifier: indexPageSlug,
2731
- query: { "fields.indexPageSlug": indexPageSlug },
2728
+ cacheTagIdentifier: slug,
2729
+ query: { "fields.slug": slug },
2732
2730
  resolver: (ctx, entry) => ctx.customTypeResolver(ctx, entry),
2733
- errorLogContext: { indexPageSlug }
2731
+ errorLogContext: { slug }
2734
2732
  },
2735
2733
  options
2736
2734
  );
@@ -3024,7 +3022,7 @@ async function getPreviewEntryInfo(context, config, entryId, options) {
3024
3022
  };
3025
3023
  }
3026
3024
  case "articleType": {
3027
- const slug = fields.indexPageSlug ?? fields.slug;
3025
+ const slug = fields.slug;
3028
3026
  if (!slug) return null;
3029
3027
  return {
3030
3028
  contentType: "articleType",
@@ -3054,7 +3052,7 @@ async function getPreviewEntryInfo(context, config, entryId, options) {
3054
3052
  };
3055
3053
  }
3056
3054
  case "customType": {
3057
- const slug = fields.indexPageSlug ?? fields.slug;
3055
+ const slug = fields.slug;
3058
3056
  if (!slug) return null;
3059
3057
  return {
3060
3058
  contentType: "customType",
@@ -3351,13 +3349,9 @@ init_utils();
3351
3349
  var defaultLocale = "en-US";
3352
3350
  var articleTypeHandler = {
3353
3351
  extract: (data) => ({
3354
- slug: data.fields?.slug?.[defaultLocale],
3355
- indexPageSlug: data.fields?.indexPageSlug?.[defaultLocale]
3352
+ slug: data.fields?.slug?.[defaultLocale]
3356
3353
  }),
3357
- makeTags: (extracted) => [
3358
- extracted.slug ? articleTypeTag(extracted.slug) : void 0,
3359
- extracted.indexPageSlug ? articleTypeIndexTag(extracted.indexPageSlug) : void 0
3360
- ],
3354
+ makeTags: (extracted) => [extracted.slug ? articleTypeIndexTag(extracted.slug) : void 0],
3361
3355
  getGlobalTags: () => [ArticleTypeTag, ArticleTypeIndexTag]
3362
3356
  };
3363
3357
  var articleHandler = {