@se-studio/contentful-rest-api 1.0.18 → 1.0.20
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 +95 -58
- package/dist/index.js +822 -732
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IBaseArticle, IBaseArticleType, IBaseCollection, IBaseComponent, INavigationItem, IBasePage, IVisual, IInternalLink, INavigation, IPerson, IResponsiveVisual } from '@se-studio/core-data-types';
|
|
1
|
+
import { IBaseArticle, IBaseArticleType, BaseCollectionContent, IBaseCollection, IBaseComponent, IBaseCustomType, INavigationItem, IBasePage, IBaseTag, IInternalLink, IVisual, IBasePerson, INavigation, IArticleLink, IArticleTypeLink, ITyped, IResponsiveVisual } from '@se-studio/core-data-types';
|
|
3
2
|
import * as contentful from 'contentful';
|
|
4
3
|
import { EntrySkeletonType, EntryFieldTypes, Entry, UnresolvedLink } from 'contentful';
|
|
4
|
+
import { Document } from '@contentful/rich-text-types';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
6
|
|
|
7
7
|
interface BaseExternalVideoFields {
|
|
@@ -377,17 +377,29 @@ interface CmsResponse<T> {
|
|
|
377
377
|
declare function baseArticleConverter(context: ConverterContext, entry: Entry<BaseArticleSkeleton, DefaultChainModifier, string>): IBaseArticle;
|
|
378
378
|
declare function baseArticleTypeConverter(context: ConverterContext, entry: Entry<BaseArticleTypeSkeleton, DefaultChainModifier, string>): IBaseArticleType;
|
|
379
379
|
|
|
380
|
-
|
|
380
|
+
type IContentfulCollection<TContents = BaseCollectionContent> = IBaseCollection<TContents> & {
|
|
381
|
+
body?: IContentfulRichText | null;
|
|
382
|
+
additionalCopy?: IContentfulRichText | null;
|
|
383
|
+
};
|
|
384
|
+
declare function baseCollectionConverter(context: ConverterContext, entry: Entry<BaseCollectionSkeleton, DefaultChainModifier, string>): IContentfulCollection;
|
|
381
385
|
|
|
382
|
-
|
|
386
|
+
type IContentfulComponent = IBaseComponent & {
|
|
387
|
+
body?: IContentfulRichText | null;
|
|
388
|
+
additionalCopy?: IContentfulRichText | null;
|
|
389
|
+
};
|
|
390
|
+
declare function baseComponentConverter(context: ConverterContext, entry: Entry<BaseComponentSkeleton, DefaultChainModifier, string>): IContentfulComponent;
|
|
391
|
+
|
|
392
|
+
declare function baseCustomTypeConverter(context: ConverterContext, entry: Entry<BaseCustomTypeSkeleton, DefaultChainModifier, string>): IBaseCustomType;
|
|
383
393
|
|
|
384
394
|
declare function baseNavigationItemConverter(context: ConverterContext, entry: Entry<BaseNavigationItemSkeleton, DefaultChainModifier, string>): INavigationItem;
|
|
385
395
|
|
|
386
396
|
declare function basePageConverter(context: ConverterContext, entry: Entry<BasePageSkeleton, DefaultChainModifier, string>): IBasePage;
|
|
387
397
|
|
|
398
|
+
declare function baseTagConverter(context: ConverterContext, entry: Entry<BaseTagSkeleton, DefaultChainModifier, string>): IBaseTag;
|
|
399
|
+
|
|
388
400
|
declare function lookupAsset(context: ConverterContext, asset: UnresolvedLink<'Asset'> | undefined): IVisual | undefined;
|
|
389
401
|
type ContentResolverFunction = (context: ConverterContext, entry: Entry<BaseContent, DefaultChainModifier, string>) => unknown;
|
|
390
|
-
type LinkResolverFunction = (context: ConverterContext, entry: Entry<BaseLink, DefaultChainModifier, string>) =>
|
|
402
|
+
type LinkResolverFunction<TResult extends IInternalLink = IInternalLink> = (context: ConverterContext, entry: Entry<BaseLink, DefaultChainModifier, string>) => TResult;
|
|
391
403
|
type LinkResolverMap = Map<string, LinkResolverFunction>;
|
|
392
404
|
type BaseConverterContext = {
|
|
393
405
|
videoPrefix: string;
|
|
@@ -397,6 +409,8 @@ type BaseConverterContext = {
|
|
|
397
409
|
pageResolver: typeof basePageConverter;
|
|
398
410
|
articleResolver: typeof baseArticleConverter;
|
|
399
411
|
articleTypeResolver: typeof baseArticleTypeConverter;
|
|
412
|
+
tagResolver: typeof baseTagConverter;
|
|
413
|
+
customTypeResolver: typeof baseCustomTypeConverter;
|
|
400
414
|
componentResolver: typeof baseComponentConverter;
|
|
401
415
|
collectionResolver: typeof baseCollectionConverter;
|
|
402
416
|
};
|
|
@@ -406,27 +420,54 @@ type ConverterContext = BaseConverterContext & {
|
|
|
406
420
|
errors: CmsError[];
|
|
407
421
|
};
|
|
408
422
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
423
|
+
declare function contentfulArticleRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, articleTypeSlug: string, options?: FetchOptions): Promise<CmsResponse<IBaseArticle | null>>;
|
|
424
|
+
|
|
425
|
+
declare function contentfulArticleTypeRest(context: BaseConverterContext, config: ContentfulConfig, indexPageSlug: string, options?: FetchOptions): Promise<CmsResponse<IBaseArticleType | null>>;
|
|
426
|
+
|
|
427
|
+
declare function createBaseConverterContext(): BaseConverterContext;
|
|
428
|
+
|
|
429
|
+
declare function contentfulCustomTypeRest(context: BaseConverterContext, config: ContentfulConfig, indexPageSlug: string, options?: FetchOptions): Promise<CmsResponse<IBaseCustomType | null>>;
|
|
430
|
+
|
|
431
|
+
interface ContentfulResponse<T = any> {
|
|
432
|
+
sys: {
|
|
433
|
+
type: 'Array';
|
|
434
|
+
};
|
|
435
|
+
total: number;
|
|
436
|
+
skip: number;
|
|
437
|
+
limit: number;
|
|
438
|
+
items: T extends contentful.EntrySkeletonType ? Array<contentful.Entry<T, 'WITHOUT_LINK_RESOLUTION', string>> : T[];
|
|
439
|
+
includes?: {
|
|
440
|
+
Entry?: any[];
|
|
441
|
+
Asset?: any[];
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
interface ContentfulQuery {
|
|
445
|
+
content_type?: string;
|
|
446
|
+
locale?: string;
|
|
447
|
+
include?: number;
|
|
448
|
+
limit?: number;
|
|
449
|
+
skip?: number;
|
|
450
|
+
[key: string]: any;
|
|
451
|
+
}
|
|
452
|
+
declare class ContentfulFetchClient {
|
|
453
|
+
private readonly baseUrl;
|
|
454
|
+
private readonly accessToken;
|
|
455
|
+
constructor(config: ContentfulConfig, preview?: boolean);
|
|
456
|
+
getEntries<T = any>(query: ContentfulQuery, options?: FetchOptions): Promise<ContentfulResponse<T>>;
|
|
457
|
+
}
|
|
458
|
+
declare function createContentfulClient(config: ContentfulConfig): ContentfulFetchClient;
|
|
459
|
+
declare function createContentfulPreviewClient(config: ContentfulConfig): ContentfulFetchClient;
|
|
460
|
+
declare function getContentfulClient(config: ContentfulConfig, preview?: boolean): ContentfulFetchClient;
|
|
461
|
+
|
|
462
|
+
type IContentfulPerson = IBasePerson & {
|
|
463
|
+
bio?: IContentfulRichText | null;
|
|
416
464
|
};
|
|
417
|
-
|
|
465
|
+
|
|
466
|
+
type DefaultChainModifier = 'WITHOUT_LINK_RESOLUTION';
|
|
418
467
|
interface IContentfulRichText {
|
|
419
468
|
json: Document;
|
|
420
469
|
customStyles?: ReadonlyArray<string> | null;
|
|
421
470
|
}
|
|
422
|
-
declare function createBaseConverterContext(): BaseConverterContext;
|
|
423
|
-
declare function contentfulArticleRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, articleTypeSlug: string, options?: FetchOptions): Promise<CmsResponse<IBaseArticle | null>>;
|
|
424
|
-
declare function contentfulArticleTypeRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, options?: FetchOptions): Promise<CmsResponse<IBaseArticleType | null>>;
|
|
425
|
-
interface IArticleLinkWithMetadata extends IInternalLink {
|
|
426
|
-
date?: Date;
|
|
427
|
-
author?: IInternalLink;
|
|
428
|
-
articleType?: IInternalLink;
|
|
429
|
-
}
|
|
430
471
|
type SitemapChangeFrequency = 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
|
|
431
472
|
interface ISitemapEntry {
|
|
432
473
|
url: string;
|
|
@@ -443,21 +484,32 @@ interface SitemapConfig {
|
|
|
443
484
|
providers: SitemapEntryProvider[];
|
|
444
485
|
}
|
|
445
486
|
interface RelatedArticlesOptions {
|
|
446
|
-
|
|
487
|
+
excludeArticleIds?: string[];
|
|
488
|
+
articleTypeIds?: string[];
|
|
447
489
|
tagIds?: string[];
|
|
448
|
-
|
|
449
|
-
excludeIds?: string[];
|
|
490
|
+
authorIds?: string[];
|
|
450
491
|
before?: Date;
|
|
451
492
|
after?: Date;
|
|
452
493
|
count?: number;
|
|
453
494
|
}
|
|
454
|
-
|
|
495
|
+
type ResolvedEntry = IBasePage | IBaseArticle | IBaseArticleType | IBaseTag | INavigation | INavigationItem | IInternalLink | unknown | IContentfulPerson;
|
|
496
|
+
type PossibleResolvedEntry = {
|
|
497
|
+
id: string;
|
|
498
|
+
type: string;
|
|
499
|
+
entry: Entry<EntrySkeletonType, DefaultChainModifier, string>;
|
|
500
|
+
resolved?: ResolvedEntry;
|
|
501
|
+
};
|
|
502
|
+
|
|
455
503
|
declare function contentfulAllPageLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<IInternalLink[]>>;
|
|
456
|
-
declare function contentfulAllArticleLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<
|
|
504
|
+
declare function contentfulAllArticleLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<IArticleLink[]>>;
|
|
457
505
|
declare function contentfulAllTagLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<IInternalLink[]>>;
|
|
458
506
|
declare function contentfulAllPersonLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<IInternalLink[]>>;
|
|
459
|
-
declare function contentfulAllArticleTypeLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<
|
|
460
|
-
|
|
507
|
+
declare function contentfulAllArticleTypeLinks(context: BaseConverterContext, config: ContentfulConfig, options?: FetchOptions): Promise<CmsResponse<IArticleTypeLink[]>>;
|
|
508
|
+
|
|
509
|
+
declare function contentfulPageRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, options?: FetchOptions): Promise<CmsResponse<IBasePage | null>>;
|
|
510
|
+
|
|
511
|
+
declare function filterRelatedArticles(articles: IArticleLink[], options: RelatedArticlesOptions): IArticleLink[];
|
|
512
|
+
|
|
461
513
|
declare function contentfulPageSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
|
|
462
514
|
declare function contentfulArticleSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
|
|
463
515
|
declare function contentfulArticleTypeSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
|
|
@@ -466,36 +518,20 @@ declare function contentfulPersonSitemapEntries(context: BaseConverterContext, c
|
|
|
466
518
|
declare function getAllSitemapEntries(context: BaseConverterContext, config: ContentfulConfig, sitemapConfig: SitemapConfig, options?: FetchOptions): Promise<CmsResponse<ISitemapEntry[]>>;
|
|
467
519
|
declare function createSitemapProvider(fetcher: (context: BaseConverterContext, config: ContentfulConfig, sitemapConfig?: SitemapContentTypeConfig, options?: FetchOptions) => Promise<CmsResponse<ISitemapEntry[]>>, sitemapConfig?: SitemapContentTypeConfig): SitemapEntryProvider;
|
|
468
520
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
482
|
-
interface ContentfulQuery {
|
|
483
|
-
content_type?: string;
|
|
484
|
-
locale?: string;
|
|
485
|
-
include?: number;
|
|
486
|
-
limit?: number;
|
|
487
|
-
skip?: number;
|
|
488
|
-
[key: string]: any;
|
|
489
|
-
}
|
|
490
|
-
declare class ContentfulFetchClient {
|
|
491
|
-
private readonly baseUrl;
|
|
492
|
-
private readonly accessToken;
|
|
493
|
-
constructor(config: ContentfulConfig, preview?: boolean);
|
|
494
|
-
getEntries<T = any>(query: ContentfulQuery, options?: FetchOptions): Promise<ContentfulResponse<T>>;
|
|
521
|
+
declare function contentfulTagRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, options?: FetchOptions): Promise<CmsResponse<IBaseTag | null>>;
|
|
522
|
+
|
|
523
|
+
interface IFetchedTemplate {
|
|
524
|
+
id: string;
|
|
525
|
+
cmsLabel: string;
|
|
526
|
+
preContent: ReadonlyArray<ITyped>;
|
|
527
|
+
postContent: ReadonlyArray<ITyped>;
|
|
528
|
+
menu?: INavigation;
|
|
529
|
+
footer?: INavigation;
|
|
530
|
+
backgroundColour?: string;
|
|
531
|
+
textColour?: string;
|
|
532
|
+
stickyNav: boolean;
|
|
495
533
|
}
|
|
496
|
-
declare function
|
|
497
|
-
declare function createContentfulPreviewClient(config: ContentfulConfig): ContentfulFetchClient;
|
|
498
|
-
declare function getContentfulClient(config: ContentfulConfig, preview?: boolean): ContentfulFetchClient;
|
|
534
|
+
declare function contentfulTemplateRest(context: BaseConverterContext, config: ContentfulConfig, cmsLabel: string, options?: FetchOptions): Promise<CmsResponse<IFetchedTemplate | null>>;
|
|
499
535
|
|
|
500
536
|
declare function createResponsiveVisual(visual: IVisual | undefined, mobileVisual: IVisual | undefined, customSize?: number | null): IResponsiveVisual | undefined;
|
|
501
537
|
|
|
@@ -532,6 +568,7 @@ declare function customTypeTag(slug: string): string;
|
|
|
532
568
|
declare function tagTag(slug: string): string;
|
|
533
569
|
declare function personTag(slug: string): string;
|
|
534
570
|
declare function assetTag(assetId: string): string;
|
|
571
|
+
declare function templateTag(label: string): string;
|
|
535
572
|
declare function locationTag(slug: string): string;
|
|
536
573
|
declare const AllTags: string[];
|
|
537
574
|
|
|
@@ -587,4 +624,4 @@ declare class RateLimiter {
|
|
|
587
624
|
getAvailableTokens(): number;
|
|
588
625
|
}
|
|
589
626
|
|
|
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
|
|
627
|
+
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 IContentfulCollection, type IContentfulComponent, type IContentfulPerson, type IContentfulRichText, type IFetchedTemplate, 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, contentfulCustomTypeRest, contentfulPageRest, contentfulPageSitemapEntries, contentfulPersonSitemapEntries, contentfulTagRest, contentfulTagSitemapEntries, contentfulTemplateRest, createBaseConverterContext, createContentfulClient, createContentfulPreviewClient, createResponsiveVisual, createRevalidationHandler, createSitemapProvider, customTypeTag, filterRelatedArticles, getAllSitemapEntries, getCacheTags, getCacheTagsForPreview, getCacheTagsForProduction, getContentfulClient, getRetryAfter, isContentfulError, isRateLimitError, isRetryableError, isValidDate, locationTag, lookupAsset, notEmpty, pageTag, personTag, resolveLink, resolveLinks, resolveRichTextDocument, revalidateSingleTag, revalidateTags, safeDate, tagTag, templateTag, withRetry };
|