@se-studio/contentful-rest-api 1.0.35 → 1.0.36
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 +46 -37
- package/dist/index.js +137 -26
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBaseArticle, IBaseArticleType, BaseCollectionContent, IBaseCollection, IBaseComponent, IBaseCustomType, INavigationItem, IBasePage, IBaseTag, IInternalLink, IVisual,
|
|
1
|
+
import { IBasePerson, IBaseArticle, IBaseArticleType, BaseCollectionContent, IBaseCollection, IBaseComponent, IBaseCustomType, INavigationItem, IBasePage, IBaseTag, IInternalLink, IVisual, INavigation, IArticleLink, IArticleTypeLink, ITyped, ISvgImage, IResponsiveVisual } from '@se-studio/core-data-types';
|
|
2
2
|
import * as contentful from 'contentful';
|
|
3
3
|
import { EntrySkeletonType, EntryFieldTypes, Entry, Asset, UnresolvedLink } from 'contentful';
|
|
4
4
|
import { Document } from '@contentful/rich-text-types';
|
|
@@ -39,34 +39,6 @@ interface BaseMediaFields {
|
|
|
39
39
|
}
|
|
40
40
|
type BaseMediaSkeleton = EntrySkeletonType<BaseMediaFields, 'media'>;
|
|
41
41
|
|
|
42
|
-
interface BaseNavigationItemFields {
|
|
43
|
-
title: EntryFieldTypes.Symbol;
|
|
44
|
-
useTitle: EntryFieldTypes.Boolean;
|
|
45
|
-
navigationItems?: EntryFieldTypes.Array<EntryFieldTypes.EntryLink<BaseNavigationItemSkeleton>>;
|
|
46
|
-
text?: EntryFieldTypes.Symbol;
|
|
47
|
-
internal?: EntryFieldTypes.EntryLink<BaseLink>;
|
|
48
|
-
link?: EntryFieldTypes.Symbol;
|
|
49
|
-
isButton?: EntryFieldTypes.Boolean;
|
|
50
|
-
isOutlined?: EntryFieldTypes.Boolean;
|
|
51
|
-
backgroundColour?: EntryFieldTypes.Symbol<string>;
|
|
52
|
-
textColour?: EntryFieldTypes.Symbol<string>;
|
|
53
|
-
icon?: EntryFieldTypes.AssetLink;
|
|
54
|
-
mobileIcon?: EntryFieldTypes.AssetLink;
|
|
55
|
-
variant?: EntryFieldTypes.Symbol<string>;
|
|
56
|
-
size?: EntryFieldTypes.Symbol<string>;
|
|
57
|
-
longText?: EntryFieldTypes.RichText;
|
|
58
|
-
}
|
|
59
|
-
type BaseNavigationItemSkeleton = EntrySkeletonType<BaseNavigationItemFields, 'navigationItem'>;
|
|
60
|
-
|
|
61
|
-
interface BaseNavigationFields {
|
|
62
|
-
adminLabel: EntryFieldTypes.Symbol;
|
|
63
|
-
name: EntryFieldTypes.Symbol;
|
|
64
|
-
backgroundColour?: EntryFieldTypes.Symbol<string>;
|
|
65
|
-
textColour?: EntryFieldTypes.Symbol<string>;
|
|
66
|
-
entries?: EntryFieldTypes.Array<EntryFieldTypes.EntryLink<BaseNavigationItemSkeleton>>;
|
|
67
|
-
}
|
|
68
|
-
type BaseNavigationSkeleton = EntrySkeletonType<BaseNavigationFields, 'navigation'>;
|
|
69
|
-
|
|
70
42
|
interface BaseSchemaFields {
|
|
71
43
|
cmsLabel: EntryFieldTypes.Symbol;
|
|
72
44
|
markup: EntryFieldTypes.Object;
|
|
@@ -317,6 +289,37 @@ interface BasePageVariantFields {
|
|
|
317
289
|
}
|
|
318
290
|
type BasePageVariantSkeleton = EntrySkeletonType<BasePageVariantFields, 'pageVariant'>;
|
|
319
291
|
|
|
292
|
+
type BaseContent = BaseCollectionSkeleton | BaseComponentSkeleton | BaseExternalComponentSkeleton | BaseExternalVideoSkeleton | BaseMediaSkeleton | BasePersonSkeleton;
|
|
293
|
+
type BaseLink = BaseArticleSkeleton | BaseArticleTypeSkeleton | BaseLinkSkeleton | BasePageSkeleton | BasePageVariantSkeleton | BasePersonSkeleton | BaseTagSkeleton | BaseCustomTypeSkeleton;
|
|
294
|
+
|
|
295
|
+
interface BaseNavigationItemFields {
|
|
296
|
+
title: EntryFieldTypes.Symbol;
|
|
297
|
+
useTitle: EntryFieldTypes.Boolean;
|
|
298
|
+
navigationItems?: EntryFieldTypes.Array<EntryFieldTypes.EntryLink<BaseNavigationItemSkeleton>>;
|
|
299
|
+
text?: EntryFieldTypes.Symbol;
|
|
300
|
+
internal?: EntryFieldTypes.EntryLink<BaseLink>;
|
|
301
|
+
link?: EntryFieldTypes.Symbol;
|
|
302
|
+
isButton?: EntryFieldTypes.Boolean;
|
|
303
|
+
isOutlined?: EntryFieldTypes.Boolean;
|
|
304
|
+
backgroundColour?: EntryFieldTypes.Symbol<string>;
|
|
305
|
+
textColour?: EntryFieldTypes.Symbol<string>;
|
|
306
|
+
icon?: EntryFieldTypes.AssetLink;
|
|
307
|
+
mobileIcon?: EntryFieldTypes.AssetLink;
|
|
308
|
+
variant?: EntryFieldTypes.Symbol<string>;
|
|
309
|
+
size?: EntryFieldTypes.Symbol<string>;
|
|
310
|
+
longText?: EntryFieldTypes.RichText;
|
|
311
|
+
}
|
|
312
|
+
type BaseNavigationItemSkeleton = EntrySkeletonType<BaseNavigationItemFields, 'navigationItem'>;
|
|
313
|
+
|
|
314
|
+
interface BaseNavigationFields {
|
|
315
|
+
adminLabel: EntryFieldTypes.Symbol;
|
|
316
|
+
name: EntryFieldTypes.Symbol;
|
|
317
|
+
backgroundColour?: EntryFieldTypes.Symbol<string>;
|
|
318
|
+
textColour?: EntryFieldTypes.Symbol<string>;
|
|
319
|
+
entries?: EntryFieldTypes.Array<EntryFieldTypes.EntryLink<BaseNavigationItemSkeleton>>;
|
|
320
|
+
}
|
|
321
|
+
type BaseNavigationSkeleton = EntrySkeletonType<BaseNavigationFields, 'navigation'>;
|
|
322
|
+
|
|
320
323
|
interface BaseCustomTypeFields {
|
|
321
324
|
name: EntryFieldTypes.Symbol;
|
|
322
325
|
slug: EntryFieldTypes.Symbol;
|
|
@@ -340,8 +343,10 @@ interface BaseCustomTypeFields {
|
|
|
340
343
|
}
|
|
341
344
|
type BaseCustomTypeSkeleton = EntrySkeletonType<BaseCustomTypeFields, 'customType'>;
|
|
342
345
|
|
|
343
|
-
type
|
|
344
|
-
|
|
346
|
+
type IContentfulPerson = IBasePerson & {
|
|
347
|
+
bio?: IContentfulRichText | null;
|
|
348
|
+
};
|
|
349
|
+
declare function basePersonConverter(context: ConverterContext, entry: Entry<BasePersonSkeleton, DefaultChainModifier, string>, customTypeEntry?: Entry<BaseCustomTypeSkeleton, DefaultChainModifier, string>): IContentfulPerson;
|
|
345
350
|
|
|
346
351
|
interface ContentfulConfig {
|
|
347
352
|
spaceId: string;
|
|
@@ -397,6 +402,8 @@ declare function baseCustomTypeConverter(context: ConverterContext, entry: Entry
|
|
|
397
402
|
declare function baseNavigationItemConverter(context: ConverterContext, entry: Entry<BaseNavigationItemSkeleton, DefaultChainModifier, string>): INavigationItem;
|
|
398
403
|
|
|
399
404
|
declare function basePageConverter(context: ConverterContext, entry: Entry<BasePageSkeleton, DefaultChainModifier, string>): IBasePage;
|
|
405
|
+
declare function calculatePageHref(slug: string): string;
|
|
406
|
+
declare function calculatePageVariantHref(slug: string): string;
|
|
400
407
|
|
|
401
408
|
declare function baseTagConverter(context: ConverterContext, entry: Entry<BaseTagSkeleton, DefaultChainModifier, string>): IBaseTag;
|
|
402
409
|
|
|
@@ -424,6 +431,7 @@ type BaseConverterContext = {
|
|
|
424
431
|
articleResolver: typeof baseArticleConverter;
|
|
425
432
|
articleTypeResolver: typeof baseArticleTypeConverter;
|
|
426
433
|
tagResolver: typeof baseTagConverter;
|
|
434
|
+
personResolver: typeof basePersonConverter;
|
|
427
435
|
customTypeResolver: typeof baseCustomTypeConverter;
|
|
428
436
|
componentResolver: typeof baseComponentConverter;
|
|
429
437
|
collectionResolver: typeof baseCollectionConverter;
|
|
@@ -513,14 +521,10 @@ interface DownloadRouteParams {
|
|
|
513
521
|
}
|
|
514
522
|
declare function createDownloadHandler(config: DownloadHandlerConfig): (_request: NextRequest, { params }: DownloadRouteParams) => Promise<Response>;
|
|
515
523
|
|
|
516
|
-
declare function createBaseConverterContext(): BaseConverterContext;
|
|
524
|
+
declare function createBaseConverterContext(urlCalculators: UrlCalculators): BaseConverterContext;
|
|
517
525
|
|
|
518
526
|
declare function contentfulCustomTypeRest(context: BaseConverterContext, config: ContentfulConfig, indexPageSlug: string, options?: FetchOptions): Promise<CmsResponse<IBaseCustomType | null>>;
|
|
519
527
|
|
|
520
|
-
type IContentfulPerson = IBasePerson & {
|
|
521
|
-
bio?: IContentfulRichText | null;
|
|
522
|
-
};
|
|
523
|
-
|
|
524
528
|
type DefaultChainModifier = 'WITHOUT_LINK_RESOLUTION';
|
|
525
529
|
interface IContentfulRichText {
|
|
526
530
|
json: Document;
|
|
@@ -566,6 +570,11 @@ declare function contentfulAllArticleTypeLinks(context: BaseConverterContext, co
|
|
|
566
570
|
|
|
567
571
|
declare function contentfulPageRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, options?: FetchOptions): Promise<CmsResponse<IBasePage | null>>;
|
|
568
572
|
|
|
573
|
+
interface PersonFetchOptions extends FetchOptions {
|
|
574
|
+
customType?: string;
|
|
575
|
+
}
|
|
576
|
+
declare function contentfulPersonRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, options?: PersonFetchOptions): Promise<CmsResponse<IContentfulPerson | null>>;
|
|
577
|
+
|
|
569
578
|
type PreviewContentType = 'page' | 'pageVariant' | 'article' | 'articleType' | 'tag' | 'person' | 'customType';
|
|
570
579
|
interface PreviewEntryInfo {
|
|
571
580
|
contentType: PreviewContentType;
|
|
@@ -696,4 +705,4 @@ declare class RateLimiter {
|
|
|
696
705
|
getIntervalMs(): number;
|
|
697
706
|
}
|
|
698
707
|
|
|
699
|
-
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, type DownloadHandlerConfig, type DownloadRouteParams, EntryNotFoundError, type FetchOptions, GlobalTag, type IContentfulCollection, type IContentfulComponent, type IContentfulPerson, type IContentfulRichText, type IFetchedTemplate, type ISitemapEntry, LocationTag, NavigationTag, PageTag, PersonTag, type PreviewContentType, type PreviewEntryInfo, RateLimitError, RateLimiter, type RelatedArticlesOptions, type RetryConfig, type RevalidationConfig, type SitemapChangeFrequency, type SitemapConfig, type SitemapContentTypeConfig, type SitemapEntryProvider, TagTag, TemplateTag, type UrlCalculators, ValidationError, arrayOrUndefined, articleTag, articleTypeIndexTag, articleTypeTag, assetTag, basePageConverter, calculateBackoffDelay, contentfulAllArticleLinks, contentfulAllArticleTypeLinks, contentfulAllPageLinks, contentfulAllPersonLinks, contentfulAllTagLinks, contentfulArticleRest, contentfulArticleSitemapEntries, contentfulArticleTypeRest, contentfulArticleTypeSitemapEntries, contentfulAssetRest, contentfulCustomTypeRest, contentfulPageRest, contentfulPageSitemapEntries, contentfulPersonSitemapEntries, contentfulTagRest, contentfulTagSitemapEntries, contentfulTemplateRest, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createDownloadHandler, createResponsiveVisual, createRevalidationHandler, createSitemapProvider, customTypeTag, filterRelatedArticles, getAllSitemapEntries, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getPreviewEntryInfo, getRetryAfter, isBrowserViewable, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, templateTag, withRetry };
|
|
708
|
+
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, type DownloadHandlerConfig, type DownloadRouteParams, EntryNotFoundError, type FetchOptions, GlobalTag, type IContentfulCollection, type IContentfulComponent, type IContentfulPerson, type IContentfulRichText, type IFetchedTemplate, type ISitemapEntry, LocationTag, NavigationTag, PageTag, PersonTag, type PreviewContentType, type PreviewEntryInfo, RateLimitError, RateLimiter, type RelatedArticlesOptions, type RetryConfig, type RevalidationConfig, type SitemapChangeFrequency, type SitemapConfig, type SitemapContentTypeConfig, type SitemapEntryProvider, TagTag, TemplateTag, type UrlCalculators, ValidationError, arrayOrUndefined, articleTag, articleTypeIndexTag, articleTypeTag, assetTag, basePageConverter, calculateBackoffDelay, calculatePageHref, calculatePageVariantHref, contentfulAllArticleLinks, contentfulAllArticleTypeLinks, contentfulAllPageLinks, contentfulAllPersonLinks, contentfulAllTagLinks, contentfulArticleRest, contentfulArticleSitemapEntries, contentfulArticleTypeRest, contentfulArticleTypeSitemapEntries, contentfulAssetRest, contentfulCustomTypeRest, contentfulPageRest, contentfulPageSitemapEntries, contentfulPersonRest, contentfulPersonSitemapEntries, contentfulTagRest, contentfulTagSitemapEntries, contentfulTemplateRest, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createDownloadHandler, createResponsiveVisual, createRevalidationHandler, createSitemapProvider, customTypeTag, filterRelatedArticles, getAllSitemapEntries, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getPreviewEntryInfo, getRetryAfter, isBrowserViewable, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, templateTag, withRetry };
|
package/dist/index.js
CHANGED
|
@@ -1895,12 +1895,6 @@ function baseArticleConverter(context, entry) {
|
|
|
1895
1895
|
};
|
|
1896
1896
|
return article;
|
|
1897
1897
|
}
|
|
1898
|
-
function calculateArticleTypeHref(slug) {
|
|
1899
|
-
return `/${slug}/`;
|
|
1900
|
-
}
|
|
1901
|
-
function calculateArticleHref(articleTypeSlug, slug, _primaryTagSlug) {
|
|
1902
|
-
return `${calculateArticleTypeHref(articleTypeSlug)}${slug}/`;
|
|
1903
|
-
}
|
|
1904
1898
|
function baseArticleLinkConverter(context, entry) {
|
|
1905
1899
|
const { sys, fields } = entry;
|
|
1906
1900
|
if (sys.contentType.sys.id !== "article") {
|
|
@@ -2179,9 +2173,6 @@ function baseCustomTypeLinkConverter(context, entry) {
|
|
|
2179
2173
|
"CustomType"
|
|
2180
2174
|
);
|
|
2181
2175
|
}
|
|
2182
|
-
function calculateCustomTypeHref(slug) {
|
|
2183
|
-
return `/${slug}/`;
|
|
2184
|
-
}
|
|
2185
2176
|
|
|
2186
2177
|
// src/converters/externalComponent.ts
|
|
2187
2178
|
function baseExternalComponentConverter(_context, entry) {
|
|
@@ -2405,9 +2396,6 @@ function basePageVariantLinkConverter(context, entry) {
|
|
|
2405
2396
|
}
|
|
2406
2397
|
|
|
2407
2398
|
// src/converters/person.ts
|
|
2408
|
-
function calculatePersonHref(slug) {
|
|
2409
|
-
return `/people/${slug}/`;
|
|
2410
|
-
}
|
|
2411
2399
|
function basePersonLinkConverter(context, entry) {
|
|
2412
2400
|
const { sys, fields } = entry;
|
|
2413
2401
|
const {
|
|
@@ -2446,11 +2434,48 @@ function basePersonLinkConverter(context, entry) {
|
|
|
2446
2434
|
}
|
|
2447
2435
|
);
|
|
2448
2436
|
}
|
|
2437
|
+
function basePersonConverter(context, entry, customTypeEntry) {
|
|
2438
|
+
const {
|
|
2439
|
+
sys: { id, contentType },
|
|
2440
|
+
fields
|
|
2441
|
+
} = entry;
|
|
2442
|
+
if (contentType.sys.id !== "person") {
|
|
2443
|
+
throw new Error(`Invalid content type: expected "person", got "${contentType.sys.id}"`);
|
|
2444
|
+
}
|
|
2445
|
+
const { slug, name, description, media, bio: bioField, content: contentLinks, ...rest } = fields;
|
|
2446
|
+
const customType = customTypeEntry ? context.customTypeResolver(context, customTypeEntry) : void 0;
|
|
2447
|
+
const template = customTypeEntry?.fields.template ? resolveTemplate(context, customTypeEntry.fields.template) : null;
|
|
2448
|
+
const personContent = contentLinks?.map((c) => resolvePageContent(context, id, c)).filter((item) => item !== null) ?? [];
|
|
2449
|
+
const preContent = template?.preContent ?? [];
|
|
2450
|
+
const postContent = template?.postContent ?? [];
|
|
2451
|
+
const contents = addPositionMetadata([...preContent, ...personContent, ...postContent]);
|
|
2452
|
+
const menu = customTypeEntry?.fields.menu ? resolveNavigation(context, customTypeEntry.fields.menu) : template?.menu;
|
|
2453
|
+
const footer = customTypeEntry?.fields.footer ? resolveNavigation(context, customTypeEntry.fields.footer) : template?.footer;
|
|
2454
|
+
const icons = deduplicateIcons(
|
|
2455
|
+
collectIconsFromContent(contents),
|
|
2456
|
+
collectIconsFromNavigation(menu),
|
|
2457
|
+
collectIconsFromNavigation(footer)
|
|
2458
|
+
);
|
|
2459
|
+
return {
|
|
2460
|
+
type: "Person",
|
|
2461
|
+
id,
|
|
2462
|
+
slug,
|
|
2463
|
+
title: makeContentfulTitle(name, id),
|
|
2464
|
+
description: description ?? `Description for ${id}`,
|
|
2465
|
+
featuredImage: lookupAsset(context, media),
|
|
2466
|
+
// Person uses 'media' not 'featuredImage'
|
|
2467
|
+
href: context.urlCalculators.person(slug),
|
|
2468
|
+
bio: resolveRichTextDocument(context, id, bioField) ?? null,
|
|
2469
|
+
contents,
|
|
2470
|
+
menu,
|
|
2471
|
+
footer,
|
|
2472
|
+
icons,
|
|
2473
|
+
customType,
|
|
2474
|
+
...rest
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2449
2477
|
|
|
2450
2478
|
// src/converters/tag.ts
|
|
2451
|
-
function calculateTagHref(slug) {
|
|
2452
|
-
return `/tag/${slug}/`;
|
|
2453
|
-
}
|
|
2454
2479
|
function baseTagLinkConverter(context, entry) {
|
|
2455
2480
|
const { sys, fields } = entry;
|
|
2456
2481
|
const { name, ...simpleFields } = fields;
|
|
@@ -2515,7 +2540,7 @@ function baseTagConverter(context, entry) {
|
|
|
2515
2540
|
}
|
|
2516
2541
|
|
|
2517
2542
|
// src/api/context.ts
|
|
2518
|
-
function createBaseConverterContext() {
|
|
2543
|
+
function createBaseConverterContext(urlCalculators) {
|
|
2519
2544
|
const linkResolver = /* @__PURE__ */ new Map();
|
|
2520
2545
|
linkResolver.set("page", basePageLinkConverter);
|
|
2521
2546
|
linkResolver.set("article", baseArticleLinkConverter);
|
|
@@ -2535,21 +2560,13 @@ function createBaseConverterContext() {
|
|
|
2535
2560
|
"externalComponent",
|
|
2536
2561
|
baseExternalComponentConverter
|
|
2537
2562
|
);
|
|
2538
|
-
const urlCalculators = {
|
|
2539
|
-
page: calculatePageHref,
|
|
2540
|
-
pageVariant: calculatePageVariantHref,
|
|
2541
|
-
article: calculateArticleHref,
|
|
2542
|
-
articleType: calculateArticleTypeHref,
|
|
2543
|
-
tag: calculateTagHref,
|
|
2544
|
-
person: calculatePersonHref,
|
|
2545
|
-
customType: calculateCustomTypeHref
|
|
2546
|
-
};
|
|
2547
2563
|
return {
|
|
2548
2564
|
pageResolver: basePageConverter,
|
|
2549
2565
|
navigationItemResolver: baseNavigationItemConverter,
|
|
2550
2566
|
articleResolver: baseArticleConverter,
|
|
2551
2567
|
articleTypeResolver: baseArticleTypeConverter,
|
|
2552
2568
|
tagResolver: baseTagConverter,
|
|
2569
|
+
personResolver: basePersonConverter,
|
|
2553
2570
|
customTypeResolver: baseCustomTypeConverter,
|
|
2554
2571
|
componentResolver: baseComponentConverter,
|
|
2555
2572
|
collectionResolver: baseCollectionConverter,
|
|
@@ -2717,6 +2734,100 @@ async function contentfulPageRest(context, config, slug, options) {
|
|
|
2717
2734
|
);
|
|
2718
2735
|
}
|
|
2719
2736
|
|
|
2737
|
+
// src/api/person.ts
|
|
2738
|
+
init_utils();
|
|
2739
|
+
async function contentfulPersonRest(context, config, slug, options) {
|
|
2740
|
+
const client = getContentfulClient(config, options?.preview);
|
|
2741
|
+
const personCacheTags = getCacheTags("person", slug, options?.preview);
|
|
2742
|
+
const customTypeCacheTags = options?.customType ? getCacheTags("customType", options.customType, options?.preview) : [];
|
|
2743
|
+
const requestOptions = {
|
|
2744
|
+
...options,
|
|
2745
|
+
next: {
|
|
2746
|
+
...options?.next,
|
|
2747
|
+
tags: [...personCacheTags, ...customTypeCacheTags]
|
|
2748
|
+
}
|
|
2749
|
+
};
|
|
2750
|
+
const fetchFn = async () => {
|
|
2751
|
+
const personPromise = client.getEntries(
|
|
2752
|
+
{
|
|
2753
|
+
content_type: "person",
|
|
2754
|
+
"fields.slug": slug,
|
|
2755
|
+
include: 10,
|
|
2756
|
+
locale: options?.locale,
|
|
2757
|
+
limit: 1
|
|
2758
|
+
},
|
|
2759
|
+
requestOptions
|
|
2760
|
+
);
|
|
2761
|
+
const customTypePromise = options?.customType ? client.getEntries(
|
|
2762
|
+
{
|
|
2763
|
+
content_type: "customType",
|
|
2764
|
+
"fields.slug": options.customType,
|
|
2765
|
+
include: 10,
|
|
2766
|
+
locale: options?.locale,
|
|
2767
|
+
limit: 1
|
|
2768
|
+
},
|
|
2769
|
+
requestOptions
|
|
2770
|
+
) : Promise.resolve(null);
|
|
2771
|
+
const [personResponse, customTypeResponse] = await Promise.all([
|
|
2772
|
+
personPromise,
|
|
2773
|
+
customTypePromise
|
|
2774
|
+
]);
|
|
2775
|
+
const personEntry = personResponse.items[0];
|
|
2776
|
+
if (!personEntry || !personEntry.fields) {
|
|
2777
|
+
return { data: null, errors: [] };
|
|
2778
|
+
}
|
|
2779
|
+
const customTypeEntry = customTypeResponse?.items[0];
|
|
2780
|
+
try {
|
|
2781
|
+
const assets = convertAllAssets(personResponse, context);
|
|
2782
|
+
const rawAssets = convertAllRawAssets(personResponse);
|
|
2783
|
+
const includes = convertAllIncludes(personResponse);
|
|
2784
|
+
if (customTypeResponse) {
|
|
2785
|
+
const customAssets = convertAllAssets(customTypeResponse, context);
|
|
2786
|
+
const customRawAssets = convertAllRawAssets(customTypeResponse);
|
|
2787
|
+
const customIncludes = convertAllIncludes(customTypeResponse);
|
|
2788
|
+
for (const [key, value] of customAssets) assets.set(key, value);
|
|
2789
|
+
for (const [key, value] of customRawAssets) rawAssets.set(key, value);
|
|
2790
|
+
for (const [key, value] of customIncludes) includes.set(key, value);
|
|
2791
|
+
}
|
|
2792
|
+
const fullContext = {
|
|
2793
|
+
...context,
|
|
2794
|
+
includes,
|
|
2795
|
+
assets,
|
|
2796
|
+
rawAssets,
|
|
2797
|
+
errors: []
|
|
2798
|
+
};
|
|
2799
|
+
const converted = context.personResolver(fullContext, personEntry, customTypeEntry);
|
|
2800
|
+
if (converted?.icons && converted.icons.length > 0) {
|
|
2801
|
+
const processedIcons = await processIconsForSprite(converted.icons);
|
|
2802
|
+
converted.icons = processedIcons.length > 0 ? processedIcons : void 0;
|
|
2803
|
+
}
|
|
2804
|
+
if (fullContext.errors.length > 0 && typeof process !== "undefined" && process.env?.NODE_ENV === "production") {
|
|
2805
|
+
console.error(`CMS conversion errors for person:`, {
|
|
2806
|
+
entryId: personEntry.sys.id,
|
|
2807
|
+
slug,
|
|
2808
|
+
errors: fullContext.errors
|
|
2809
|
+
});
|
|
2810
|
+
}
|
|
2811
|
+
return { data: converted, errors: fullContext.errors };
|
|
2812
|
+
} catch (error) {
|
|
2813
|
+
const entryId = personEntry?.sys.id || "unknown";
|
|
2814
|
+
const entryType = personEntry?.sys.contentType?.sys?.id;
|
|
2815
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown conversion error";
|
|
2816
|
+
const cmsError = {
|
|
2817
|
+
entryId,
|
|
2818
|
+
entryType,
|
|
2819
|
+
message: errorMessage,
|
|
2820
|
+
error
|
|
2821
|
+
};
|
|
2822
|
+
return { data: null, errors: [cmsError] };
|
|
2823
|
+
}
|
|
2824
|
+
};
|
|
2825
|
+
if (options?.retry) {
|
|
2826
|
+
return await withRetry(fetchFn, options.retry);
|
|
2827
|
+
}
|
|
2828
|
+
return await fetchFn();
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2720
2831
|
// src/api/preview.ts
|
|
2721
2832
|
async function getPreviewEntryInfo(context, config, entryId, options) {
|
|
2722
2833
|
const client = getContentfulClient(config, true);
|
|
@@ -3240,6 +3351,6 @@ function createRevalidationHandler(config = {}) {
|
|
|
3240
3351
|
init_tags();
|
|
3241
3352
|
init_utils();
|
|
3242
3353
|
|
|
3243
|
-
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, contentfulAssetRest, contentfulCustomTypeRest, contentfulPageRest, contentfulPageSitemapEntries, contentfulPersonSitemapEntries, contentfulTagRest, contentfulTagSitemapEntries, contentfulTemplateRest, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createDownloadHandler, createResponsiveVisual, createRevalidationHandler, createSitemapProvider, customTypeTag, filterRelatedArticles, getAllSitemapEntries, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getPreviewEntryInfo, getRetryAfter, isBrowserViewable, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, templateTag, withRetry };
|
|
3354
|
+
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, calculatePageHref, calculatePageVariantHref, contentfulAllArticleLinks, contentfulAllArticleTypeLinks, contentfulAllPageLinks, contentfulAllPersonLinks, contentfulAllTagLinks, contentfulArticleRest, contentfulArticleSitemapEntries, contentfulArticleTypeRest, contentfulArticleTypeSitemapEntries, contentfulAssetRest, contentfulCustomTypeRest, contentfulPageRest, contentfulPageSitemapEntries, contentfulPersonRest, contentfulPersonSitemapEntries, contentfulTagRest, contentfulTagSitemapEntries, contentfulTemplateRest, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createDownloadHandler, createResponsiveVisual, createRevalidationHandler, createSitemapProvider, customTypeTag, filterRelatedArticles, getAllSitemapEntries, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getPreviewEntryInfo, getRetryAfter, isBrowserViewable, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, templateTag, withRetry };
|
|
3244
3355
|
//# sourceMappingURL=index.js.map
|
|
3245
3356
|
//# sourceMappingURL=index.js.map
|