@se-studio/contentful-rest-api 1.0.17 → 1.0.18

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
@@ -427,6 +427,21 @@ interface IArticleLinkWithMetadata extends IInternalLink {
427
427
  author?: IInternalLink;
428
428
  articleType?: IInternalLink;
429
429
  }
430
+ type SitemapChangeFrequency = 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
431
+ interface ISitemapEntry {
432
+ url: string;
433
+ lastModified?: Date;
434
+ changeFrequency?: SitemapChangeFrequency;
435
+ priority?: number;
436
+ }
437
+ interface SitemapContentTypeConfig {
438
+ priority?: number;
439
+ changeFrequency?: SitemapChangeFrequency;
440
+ }
441
+ type SitemapEntryProvider = (context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions) => Promise<CmsResponse<ISitemapEntry[]>>;
442
+ interface SitemapConfig {
443
+ providers: SitemapEntryProvider[];
444
+ }
430
445
  interface RelatedArticlesOptions {
431
446
  articleTypeId?: string;
432
447
  tagIds?: string[];
@@ -443,6 +458,13 @@ declare function contentfulAllTagLinks(context: BaseConverterContext, config: Co
443
458
  declare function contentfulAllPersonLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<IInternalLink[]>>;
444
459
  declare function contentfulAllArticleTypeLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<IInternalLink[]>>;
445
460
  declare function filterRelatedArticles(articles: IArticleLinkWithMetadata[], options: RelatedArticlesOptions): IInternalLink[];
461
+ declare function contentfulPageSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
462
+ declare function contentfulArticleSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
463
+ declare function contentfulArticleTypeSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
464
+ declare function contentfulTagSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
465
+ declare function contentfulPersonSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
466
+ declare function getAllSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig: SitemapConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
467
+ declare function createSitemapProvider(fetcher: (context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions) => Promise<CmsResponse<ISitemapEntry[]>>, sitemapConfig?: SitemapContentTypeConfig): SitemapEntryProvider;
446
468
 
447
469
  interface ContentfulResponse<T = any> {
448
470
  sys: {
@@ -565,4 +587,4 @@ declare class RateLimiter {
565
587
  getAvailableTokens(): number;
566
588
  }
567
589
 
568
- export { AllTags, ArticleTag, ArticleTypeTag, AssetTag, AuthenticationError, BannerTag, type BaseConverterContext, type CmsError, type CmsResponse, type ContentResolverFunction, ContentfulFetchClient as ContentfulClient, type ContentfulConfig, ContentfulError, ContentfulFetchClient, type ConverterContext, CustomTypeTag, type DefaultChainModifier, EntryNotFoundError, type FetchOptions, GlobalTag, type IArticleLinkWithMetadata, type IContentfulRichText, LocationTag, NavigationTag, PageTag, PersonTag, RateLimitError, RateLimiter, type RelatedArticlesOptions, type RetryConfig, type RevalidationConfig, TagTag, TemplateTag, ValidationError, arrayOrUndefined, articleTag, articleTypeIndexTag, articleTypeTag, assetTag, basePageConverter, calculateBackoffDelay, contentfulAllArticleLinks, contentfulAllArticleTypeLinks, contentfulAllPageLinks, contentfulAllPersonLinks, contentfulAllTagLinks, contentfulArticleRest, contentfulArticleTypeRest, contentfulPageRest, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createResponsiveVisual, createRevalidationHandler, customTypeTag, filterRelatedArticles, getAllArticlesForRelated, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getRetryAfter, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, withRetry };
590
+ export { AllTags, ArticleTag, ArticleTypeTag, AssetTag, AuthenticationError, BannerTag, type BaseConverterContext, type CmsError, type CmsResponse, type ContentResolverFunction, ContentfulFetchClient as ContentfulClient, type ContentfulConfig, ContentfulError, ContentfulFetchClient, type ConverterContext, CustomTypeTag, type DefaultChainModifier, EntryNotFoundError, type FetchOptions, GlobalTag, type IArticleLinkWithMetadata, type IContentfulRichText, type ISitemapEntry, LocationTag, NavigationTag, PageTag, PersonTag, RateLimitError, RateLimiter, type RelatedArticlesOptions, type RetryConfig, type RevalidationConfig, type SitemapChangeFrequency, type SitemapConfig, type SitemapContentTypeConfig, type SitemapEntryProvider, TagTag, TemplateTag, ValidationError, arrayOrUndefined, articleTag, articleTypeIndexTag, articleTypeTag, assetTag, basePageConverter, calculateBackoffDelay, contentfulAllArticleLinks, contentfulAllArticleTypeLinks, contentfulAllPageLinks, contentfulAllPersonLinks, contentfulAllTagLinks, contentfulArticleRest, contentfulArticleSitemapEntries, contentfulArticleTypeRest, contentfulArticleTypeSitemapEntries, contentfulPageRest, contentfulPageSitemapEntries, contentfulPersonSitemapEntries, contentfulTagSitemapEntries, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createResponsiveVisual, createRevalidationHandler, createSitemapProvider, customTypeTag, filterRelatedArticles, getAllArticlesForRelated, getAllSitemapEntries, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getRetryAfter, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, withRetry };
package/dist/index.js CHANGED
@@ -1604,6 +1604,12 @@ function baseTagLinkConverter(context, entry) {
1604
1604
 
1605
1605
  // src/api.ts
1606
1606
  init_utils();
1607
+ var PAGE_LINK_FIELDS = "sys,fields.cmsLabel,fields.title,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden,fields.tags";
1608
+ var ARTICLE_LINK_FIELDS = "sys,fields.cmsLabel,fields.title,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden,fields.tags,fields.articleType";
1609
+ var ARTICLE_RELATED_FIELDS = "sys,fields.cmsLabel,fields.title,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden,fields.tags,fields.articleType,fields.date,fields.author";
1610
+ var ARTICLE_TYPE_LINK_FIELDS = "sys,fields.name,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden";
1611
+ var TAG_LINK_FIELDS = "sys,fields.cmsLabel,fields.name,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden";
1612
+ var PERSON_LINK_FIELDS = "sys,fields.name,fields.slug,fields.media,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden";
1607
1613
  function convertAllAssets(response, context) {
1608
1614
  const visuals = /* @__PURE__ */ new Map();
1609
1615
  const assets = response.includes?.Asset;
@@ -1883,7 +1889,8 @@ async function getAllArticlesForRelated(context, config, options) {
1883
1889
  // Shallow include - just enough for tags, articleType, author
1884
1890
  locale: options?.locale,
1885
1891
  limit: pageSize,
1886
- skip
1892
+ skip,
1893
+ select: ARTICLE_RELATED_FIELDS
1887
1894
  },
1888
1895
  requestOptions
1889
1896
  );
@@ -1928,7 +1935,7 @@ async function getAllArticlesForRelated(context, config, options) {
1928
1935
  }
1929
1936
  return await fetchFn();
1930
1937
  }
1931
- async function fetchAllLinks(contentType, client, requestOptions, converter, context, pageSize = 100) {
1938
+ async function fetchAllLinks(contentType, client, requestOptions, converter, context, pageSize = 100, select) {
1932
1939
  const allLinks = [];
1933
1940
  const errors = [];
1934
1941
  let skip = 0;
@@ -1943,7 +1950,8 @@ async function fetchAllLinks(contentType, client, requestOptions, converter, con
1943
1950
  // Minimal include for link-only fetching
1944
1951
  locale: requestOptions?.locale,
1945
1952
  limit: pageSize,
1946
- skip
1953
+ skip,
1954
+ ...select && { select }
1947
1955
  },
1948
1956
  requestOptions
1949
1957
  );
@@ -1966,6 +1974,7 @@ async function fetchAllLinks(contentType, client, requestOptions, converter, con
1966
1974
  fullContext,
1967
1975
  entry
1968
1976
  );
1977
+ converted.lastModified = entry.sys.updatedAt ? new Date(entry.sys.updatedAt) : void 0;
1969
1978
  allLinks.push(converted);
1970
1979
  } catch (error) {
1971
1980
  const entryId = entry.sys.id;
@@ -2002,7 +2011,15 @@ async function contentfulAllPageLinks(context, config, options) {
2002
2011
  tags: cacheTags
2003
2012
  }
2004
2013
  };
2005
- const fetchFn = () => fetchAllLinks("page", client, requestOptions, basePageLinkConverter, context);
2014
+ const fetchFn = () => fetchAllLinks(
2015
+ "page",
2016
+ client,
2017
+ requestOptions,
2018
+ basePageLinkConverter,
2019
+ context,
2020
+ 100,
2021
+ PAGE_LINK_FIELDS
2022
+ );
2006
2023
  if (options?.retry) {
2007
2024
  return await withRetry(fetchFn, options.retry);
2008
2025
  }
@@ -2018,7 +2035,15 @@ async function contentfulAllArticleLinks(context, config, options) {
2018
2035
  tags: cacheTags
2019
2036
  }
2020
2037
  };
2021
- const fetchFn = () => fetchAllLinks("article", client, requestOptions, baseArticleLinkConverter, context);
2038
+ const fetchFn = () => fetchAllLinks(
2039
+ "article",
2040
+ client,
2041
+ requestOptions,
2042
+ baseArticleLinkConverter,
2043
+ context,
2044
+ 100,
2045
+ ARTICLE_LINK_FIELDS
2046
+ );
2022
2047
  if (options?.retry) {
2023
2048
  return await withRetry(fetchFn, options.retry);
2024
2049
  }
@@ -2034,7 +2059,15 @@ async function contentfulAllTagLinks(context, config, options) {
2034
2059
  tags: cacheTags
2035
2060
  }
2036
2061
  };
2037
- const fetchFn = () => fetchAllLinks("tag", client, requestOptions, baseTagLinkConverter, context);
2062
+ const fetchFn = () => fetchAllLinks(
2063
+ "tag",
2064
+ client,
2065
+ requestOptions,
2066
+ baseTagLinkConverter,
2067
+ context,
2068
+ 100,
2069
+ TAG_LINK_FIELDS
2070
+ );
2038
2071
  if (options?.retry) {
2039
2072
  return await withRetry(fetchFn, options.retry);
2040
2073
  }
@@ -2050,7 +2083,15 @@ async function contentfulAllPersonLinks(context, config, options) {
2050
2083
  tags: cacheTags
2051
2084
  }
2052
2085
  };
2053
- const fetchFn = () => fetchAllLinks("person", client, requestOptions, basePersonLinkConverter, context);
2086
+ const fetchFn = () => fetchAllLinks(
2087
+ "person",
2088
+ client,
2089
+ requestOptions,
2090
+ basePersonLinkConverter,
2091
+ context,
2092
+ 100,
2093
+ PERSON_LINK_FIELDS
2094
+ );
2054
2095
  if (options?.retry) {
2055
2096
  return await withRetry(fetchFn, options.retry);
2056
2097
  }
@@ -2066,7 +2107,15 @@ async function contentfulAllArticleTypeLinks(context, config, options) {
2066
2107
  tags: cacheTags
2067
2108
  }
2068
2109
  };
2069
- const fetchFn = () => fetchAllLinks("articleType", client, requestOptions, baseArticleTypeLinkConverter, context);
2110
+ const fetchFn = () => fetchAllLinks(
2111
+ "articleType",
2112
+ client,
2113
+ requestOptions,
2114
+ baseArticleTypeLinkConverter,
2115
+ context,
2116
+ 100,
2117
+ ARTICLE_TYPE_LINK_FIELDS
2118
+ );
2070
2119
  if (options?.retry) {
2071
2120
  return await withRetry(fetchFn, options.retry);
2072
2121
  }
@@ -2118,6 +2167,64 @@ function filterRelatedArticles(articles, options) {
2118
2167
  return cleanLink;
2119
2168
  });
2120
2169
  }
2170
+ function linksToSitemapEntries(links, sitemapConfig) {
2171
+ return links.filter((link) => link.indexed !== false && link.hidden !== true && link.href).map((link) => ({
2172
+ url: link.href,
2173
+ lastModified: link.lastModified,
2174
+ changeFrequency: sitemapConfig?.changeFrequency,
2175
+ priority: sitemapConfig?.priority
2176
+ }));
2177
+ }
2178
+ async function contentfulPageSitemapEntries(context, config, sitemapConfig, options) {
2179
+ const response = await contentfulAllPageLinks(context, config, options);
2180
+ return {
2181
+ data: linksToSitemapEntries(response.data, sitemapConfig),
2182
+ errors: response.errors
2183
+ };
2184
+ }
2185
+ async function contentfulArticleSitemapEntries(context, config, sitemapConfig, options) {
2186
+ const response = await contentfulAllArticleLinks(context, config, options);
2187
+ return {
2188
+ data: linksToSitemapEntries(response.data, sitemapConfig),
2189
+ errors: response.errors
2190
+ };
2191
+ }
2192
+ async function contentfulArticleTypeSitemapEntries(context, config, sitemapConfig, options) {
2193
+ const response = await contentfulAllArticleTypeLinks(context, config, options);
2194
+ return {
2195
+ data: linksToSitemapEntries(response.data, sitemapConfig),
2196
+ errors: response.errors
2197
+ };
2198
+ }
2199
+ async function contentfulTagSitemapEntries(context, config, sitemapConfig, options) {
2200
+ const response = await contentfulAllTagLinks(context, config, options);
2201
+ return {
2202
+ data: linksToSitemapEntries(response.data, sitemapConfig),
2203
+ errors: response.errors
2204
+ };
2205
+ }
2206
+ async function contentfulPersonSitemapEntries(context, config, sitemapConfig, options) {
2207
+ const response = await contentfulAllPersonLinks(context, config, options);
2208
+ return {
2209
+ data: linksToSitemapEntries(response.data, sitemapConfig),
2210
+ errors: response.errors
2211
+ };
2212
+ }
2213
+ async function getAllSitemapEntries(context, config, sitemapConfig, options) {
2214
+ const allEntries = [];
2215
+ const allErrors = [];
2216
+ const results = await Promise.all(
2217
+ sitemapConfig.providers.map((provider) => provider(context, config, options))
2218
+ );
2219
+ for (const result of results) {
2220
+ allEntries.push(...result.data);
2221
+ allErrors.push(...result.errors);
2222
+ }
2223
+ return { data: allEntries, errors: allErrors };
2224
+ }
2225
+ function createSitemapProvider(fetcher, sitemapConfig) {
2226
+ return (context, config, options) => fetcher(context, config, sitemapConfig, options);
2227
+ }
2121
2228
 
2122
2229
  // src/revalidation/handlers.ts
2123
2230
  init_tags();
@@ -2339,6 +2446,6 @@ function createRevalidationHandler(config = {}) {
2339
2446
  init_tags();
2340
2447
  init_utils();
2341
2448
 
2342
- export { AllTags, ArticleTag, ArticleTypeTag, AssetTag, AuthenticationError, BannerTag, ContentfulError, CustomTypeTag, EntryNotFoundError, GlobalTag, LocationTag, NavigationTag, PageTag, PersonTag, RateLimitError, RateLimiter, TagTag, TemplateTag, ValidationError, arrayOrUndefined, articleTag, articleTypeIndexTag, articleTypeTag, assetTag, basePageConverter, calculateBackoffDelay, contentfulAllArticleLinks, contentfulAllArticleTypeLinks, contentfulAllPageLinks, contentfulAllPersonLinks, contentfulAllTagLinks, contentfulArticleRest, contentfulArticleTypeRest, contentfulPageRest, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createResponsiveVisual, createRevalidationHandler, customTypeTag, filterRelatedArticles, getAllArticlesForRelated, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getRetryAfter, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, withRetry };
2449
+ export { AllTags, ArticleTag, ArticleTypeTag, AssetTag, AuthenticationError, BannerTag, ContentfulError, CustomTypeTag, EntryNotFoundError, GlobalTag, LocationTag, NavigationTag, PageTag, PersonTag, RateLimitError, RateLimiter, TagTag, TemplateTag, ValidationError, arrayOrUndefined, articleTag, articleTypeIndexTag, articleTypeTag, assetTag, basePageConverter, calculateBackoffDelay, contentfulAllArticleLinks, contentfulAllArticleTypeLinks, contentfulAllPageLinks, contentfulAllPersonLinks, contentfulAllTagLinks, contentfulArticleRest, contentfulArticleSitemapEntries, contentfulArticleTypeRest, contentfulArticleTypeSitemapEntries, contentfulPageRest, contentfulPageSitemapEntries, contentfulPersonSitemapEntries, contentfulTagSitemapEntries, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createResponsiveVisual, createRevalidationHandler, createSitemapProvider, customTypeTag, filterRelatedArticles, getAllArticlesForRelated, getAllSitemapEntries, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getRetryAfter, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, withRetry };
2343
2450
  //# sourceMappingURL=index.js.map
2344
2451
  //# sourceMappingURL=index.js.map