@se-studio/contentful-rest-api 1.0.46 → 1.0.47
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/CHANGELOG.md +416 -0
- package/dist/api/article-type.d.ts +37 -0
- package/dist/api/article-type.d.ts.map +1 -0
- package/dist/api/article-type.js +134 -0
- package/dist/api/article-type.js.map +1 -0
- package/dist/api/article.d.ts +32 -0
- package/dist/api/article.d.ts.map +1 -0
- package/dist/api/article.js +43 -0
- package/dist/api/article.js.map +1 -0
- package/dist/api/asset.d.ts +28 -0
- package/dist/api/asset.d.ts.map +1 -0
- package/dist/api/asset.js +55 -0
- package/dist/api/asset.js.map +1 -0
- package/dist/api/context.d.ts +24 -0
- package/dist/api/context.d.ts.map +1 -0
- package/dist/api/context.js +62 -0
- package/dist/api/context.js.map +1 -0
- package/dist/api/custom-type.d.ts +37 -0
- package/dist/api/custom-type.d.ts.map +1 -0
- package/dist/api/custom-type.js +44 -0
- package/dist/api/custom-type.js.map +1 -0
- package/dist/api/helpers.d.ts +73 -0
- package/dist/api/helpers.d.ts.map +1 -0
- package/dist/api/helpers.js +296 -0
- package/dist/api/helpers.js.map +1 -0
- package/dist/api/index.d.ts +22 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +28 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/links.d.ts +109 -0
- package/dist/api/links.d.ts.map +1 -0
- package/dist/api/links.js +199 -0
- package/dist/api/links.js.map +1 -0
- package/dist/api/page.d.ts +33 -0
- package/dist/api/page.d.ts.map +1 -0
- package/dist/api/page.js +40 -0
- package/dist/api/page.js.map +1 -0
- package/dist/api/person.d.ts +37 -0
- package/dist/api/person.d.ts.map +1 -0
- package/dist/api/person.js +134 -0
- package/dist/api/person.js.map +1 -0
- package/dist/api/preview.d.ts +55 -0
- package/dist/api/preview.d.ts.map +1 -0
- package/dist/api/preview.js +160 -0
- package/dist/api/preview.js.map +1 -0
- package/dist/api/related-articles.d.ts +22 -0
- package/dist/api/related-articles.d.ts.map +1 -0
- package/dist/api/related-articles.js +82 -0
- package/dist/api/related-articles.js.map +1 -0
- package/dist/api/server-asset.d.ts +40 -0
- package/dist/api/server-asset.d.ts.map +1 -0
- package/dist/api/server-asset.js +65 -0
- package/dist/api/server-asset.js.map +1 -0
- package/dist/api/sitemap.d.ts +131 -0
- package/dist/api/sitemap.d.ts.map +1 -0
- package/dist/api/sitemap.js +199 -0
- package/dist/api/sitemap.js.map +1 -0
- package/dist/api/tag.d.ts +37 -0
- package/dist/api/tag.d.ts.map +1 -0
- package/dist/api/tag.js +131 -0
- package/dist/api/tag.js.map +1 -0
- package/dist/api/template.d.ts +49 -0
- package/dist/api/template.d.ts.map +1 -0
- package/dist/api/template.js +88 -0
- package/dist/api/template.js.map +1 -0
- package/dist/api/types.d.ts +98 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/baseTypes/baseAlternatePageContent.d.ts +24 -0
- package/dist/baseTypes/baseAlternatePageContent.d.ts.map +1 -0
- package/dist/baseTypes/baseAlternatePageContent.js +2 -0
- package/dist/baseTypes/baseAlternatePageContent.js.map +1 -0
- package/dist/baseTypes/baseArticle.d.ts +179 -0
- package/dist/baseTypes/baseArticle.d.ts.map +1 -0
- package/dist/baseTypes/baseArticle.js +2 -0
- package/dist/baseTypes/baseArticle.js.map +1 -0
- package/dist/baseTypes/baseArticleType.d.ts +156 -0
- package/dist/baseTypes/baseArticleType.d.ts.map +1 -0
- package/dist/baseTypes/baseArticleType.js +2 -0
- package/dist/baseTypes/baseArticleType.js.map +1 -0
- package/dist/baseTypes/baseBanner.d.ts +76 -0
- package/dist/baseTypes/baseBanner.d.ts.map +1 -0
- package/dist/baseTypes/baseBanner.js +2 -0
- package/dist/baseTypes/baseBanner.js.map +1 -0
- package/dist/baseTypes/baseCollection.d.ts +132 -0
- package/dist/baseTypes/baseCollection.d.ts.map +1 -0
- package/dist/baseTypes/baseCollection.js +2 -0
- package/dist/baseTypes/baseCollection.js.map +1 -0
- package/dist/baseTypes/baseComponent.d.ts +130 -0
- package/dist/baseTypes/baseComponent.d.ts.map +1 -0
- package/dist/baseTypes/baseComponent.js +2 -0
- package/dist/baseTypes/baseComponent.js.map +1 -0
- package/dist/baseTypes/baseCustomType.d.ts +126 -0
- package/dist/baseTypes/baseCustomType.d.ts.map +1 -0
- package/dist/baseTypes/baseCustomType.js +2 -0
- package/dist/baseTypes/baseCustomType.js.map +1 -0
- package/dist/baseTypes/baseExternalComponent.d.ts +66 -0
- package/dist/baseTypes/baseExternalComponent.d.ts.map +1 -0
- package/dist/baseTypes/baseExternalComponent.js +2 -0
- package/dist/baseTypes/baseExternalComponent.js.map +1 -0
- package/dist/baseTypes/baseExternalVideo.d.ts +85 -0
- package/dist/baseTypes/baseExternalVideo.d.ts.map +1 -0
- package/dist/baseTypes/baseExternalVideo.js +2 -0
- package/dist/baseTypes/baseExternalVideo.js.map +1 -0
- package/dist/baseTypes/baseLink.d.ts +90 -0
- package/dist/baseTypes/baseLink.d.ts.map +1 -0
- package/dist/baseTypes/baseLink.js +2 -0
- package/dist/baseTypes/baseLink.js.map +1 -0
- package/dist/baseTypes/baseMedia.d.ts +92 -0
- package/dist/baseTypes/baseMedia.d.ts.map +1 -0
- package/dist/baseTypes/baseMedia.js +2 -0
- package/dist/baseTypes/baseMedia.js.map +1 -0
- package/dist/baseTypes/baseNavigation.d.ts +36 -0
- package/dist/baseTypes/baseNavigation.d.ts.map +1 -0
- package/dist/baseTypes/baseNavigation.js +2 -0
- package/dist/baseTypes/baseNavigation.js.map +1 -0
- package/dist/baseTypes/baseNavigationItem.d.ts +96 -0
- package/dist/baseTypes/baseNavigationItem.d.ts.map +1 -0
- package/dist/baseTypes/baseNavigationItem.js +2 -0
- package/dist/baseTypes/baseNavigationItem.js.map +1 -0
- package/dist/baseTypes/basePage.d.ts +120 -0
- package/dist/baseTypes/basePage.d.ts.map +1 -0
- package/dist/baseTypes/basePage.js +2 -0
- package/dist/baseTypes/basePage.js.map +1 -0
- package/dist/baseTypes/basePageTest.d.ts +66 -0
- package/dist/baseTypes/basePageTest.d.ts.map +1 -0
- package/dist/baseTypes/basePageTest.js +2 -0
- package/dist/baseTypes/basePageTest.js.map +1 -0
- package/dist/baseTypes/basePageVariant.d.ts +123 -0
- package/dist/baseTypes/basePageVariant.d.ts.map +1 -0
- package/dist/baseTypes/basePageVariant.js +2 -0
- package/dist/baseTypes/basePageVariant.js.map +1 -0
- package/dist/baseTypes/basePerson.d.ts +111 -0
- package/dist/baseTypes/basePerson.d.ts.map +1 -0
- package/dist/baseTypes/basePerson.js +2 -0
- package/dist/baseTypes/basePerson.js.map +1 -0
- package/dist/baseTypes/baseSchema.d.ts +18 -0
- package/dist/baseTypes/baseSchema.d.ts.map +1 -0
- package/dist/baseTypes/baseSchema.js +2 -0
- package/dist/baseTypes/baseSchema.js.map +1 -0
- package/dist/baseTypes/baseShared.d.ts +30 -0
- package/dist/baseTypes/baseShared.d.ts.map +1 -0
- package/dist/baseTypes/baseShared.js +2 -0
- package/dist/baseTypes/baseShared.js.map +1 -0
- package/dist/baseTypes/baseTag.d.ts +108 -0
- package/dist/baseTypes/baseTag.d.ts.map +1 -0
- package/dist/baseTypes/baseTag.js +2 -0
- package/dist/baseTypes/baseTag.js.map +1 -0
- package/dist/baseTypes/baseTagType.d.ts +11 -0
- package/dist/baseTypes/baseTagType.d.ts.map +1 -0
- package/dist/baseTypes/baseTagType.js +2 -0
- package/dist/baseTypes/baseTagType.js.map +1 -0
- package/dist/baseTypes/baseTemplate.d.ts +55 -0
- package/dist/baseTypes/baseTemplate.d.ts.map +1 -0
- package/dist/baseTypes/baseTemplate.js +2 -0
- package/dist/baseTypes/baseTemplate.js.map +1 -0
- package/dist/client.d.ts +143 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +268 -0
- package/dist/client.js.map +1 -0
- package/dist/converters/article.d.ts +42 -0
- package/dist/converters/article.d.ts.map +1 -0
- package/dist/converters/article.js +220 -0
- package/dist/converters/article.js.map +1 -0
- package/dist/converters/asset.d.ts +22 -0
- package/dist/converters/asset.d.ts.map +1 -0
- package/dist/converters/asset.js +282 -0
- package/dist/converters/asset.js.map +1 -0
- package/dist/converters/collection.d.ts +26 -0
- package/dist/converters/collection.d.ts.map +1 -0
- package/dist/converters/collection.js +50 -0
- package/dist/converters/collection.js.map +1 -0
- package/dist/converters/component.d.ts +26 -0
- package/dist/converters/component.d.ts.map +1 -0
- package/dist/converters/component.js +54 -0
- package/dist/converters/component.js.map +1 -0
- package/dist/converters/customType.d.ts +24 -0
- package/dist/converters/customType.d.ts.map +1 -0
- package/dist/converters/customType.js +71 -0
- package/dist/converters/customType.js.map +1 -0
- package/dist/converters/externalComponent.d.ts +22 -0
- package/dist/converters/externalComponent.d.ts.map +1 -0
- package/dist/converters/externalComponent.js +34 -0
- package/dist/converters/externalComponent.js.map +1 -0
- package/dist/converters/helpers.d.ts +116 -0
- package/dist/converters/helpers.d.ts.map +1 -0
- package/dist/converters/helpers.js +128 -0
- package/dist/converters/helpers.js.map +1 -0
- package/dist/converters/iconCollector.d.ts +65 -0
- package/dist/converters/iconCollector.d.ts.map +1 -0
- package/dist/converters/iconCollector.js +282 -0
- package/dist/converters/iconCollector.js.map +1 -0
- package/dist/converters/index.d.ts +18 -0
- package/dist/converters/index.d.ts.map +1 -0
- package/dist/converters/index.js +18 -0
- package/dist/converters/index.js.map +1 -0
- package/dist/converters/link.d.ts +11 -0
- package/dist/converters/link.d.ts.map +1 -0
- package/dist/converters/link.js +96 -0
- package/dist/converters/link.js.map +1 -0
- package/dist/converters/navigationItem.d.ts +11 -0
- package/dist/converters/navigationItem.d.ts.map +1 -0
- package/dist/converters/navigationItem.js +73 -0
- package/dist/converters/navigationItem.js.map +1 -0
- package/dist/converters/page.d.ts +44 -0
- package/dist/converters/page.d.ts.map +1 -0
- package/dist/converters/page.js +121 -0
- package/dist/converters/page.js.map +1 -0
- package/dist/converters/person.d.ts +40 -0
- package/dist/converters/person.d.ts.map +1 -0
- package/dist/converters/person.js +109 -0
- package/dist/converters/person.js.map +1 -0
- package/dist/converters/resolver.d.ts +29 -0
- package/dist/converters/resolver.d.ts.map +1 -0
- package/dist/converters/resolver.js +317 -0
- package/dist/converters/resolver.js.map +1 -0
- package/dist/converters/schema.d.ts +14 -0
- package/dist/converters/schema.d.ts.map +1 -0
- package/dist/converters/schema.js +18 -0
- package/dist/converters/schema.js.map +1 -0
- package/dist/converters/svgProcessor.d.ts +23 -0
- package/dist/converters/svgProcessor.d.ts.map +1 -0
- package/dist/converters/svgProcessor.js +47 -0
- package/dist/converters/svgProcessor.js.map +1 -0
- package/dist/converters/tag.d.ts +25 -0
- package/dist/converters/tag.d.ts.map +1 -0
- package/dist/converters/tag.js +98 -0
- package/dist/converters/tag.js.map +1 -0
- package/dist/converters/template.d.ts +26 -0
- package/dist/converters/template.d.ts.map +1 -0
- package/dist/converters/template.js +44 -0
- package/dist/converters/template.js.map +1 -0
- package/dist/index.d.ts +28 -721
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -3634
- package/dist/index.js.map +1 -1
- package/dist/revalidation/handlers.d.ts +52 -0
- package/dist/revalidation/handlers.d.ts.map +1 -0
- package/dist/revalidation/handlers.js +130 -0
- package/dist/revalidation/handlers.js.map +1 -0
- package/dist/revalidation/index.d.ts +3 -0
- package/dist/revalidation/index.d.ts.map +1 -0
- package/dist/revalidation/index.js +4 -0
- package/dist/revalidation/index.js.map +1 -0
- package/dist/revalidation/nextjs-route.d.ts +31 -0
- package/dist/revalidation/nextjs-route.d.ts.map +1 -0
- package/dist/revalidation/nextjs-route.js +34 -0
- package/dist/revalidation/nextjs-route.js.map +1 -0
- package/dist/revalidation/route.d.ts +3 -0
- package/dist/revalidation/route.d.ts.map +1 -0
- package/dist/revalidation/route.js +97 -0
- package/dist/revalidation/route.js.map +1 -0
- package/dist/revalidation/server-utils.d.ts +22 -0
- package/dist/revalidation/server-utils.d.ts.map +1 -0
- package/dist/revalidation/server-utils.js +41 -0
- package/dist/revalidation/server-utils.js.map +1 -0
- package/dist/revalidation/tags.d.ts +81 -0
- package/dist/revalidation/tags.d.ts.map +1 -0
- package/dist/revalidation/tags.js +117 -0
- package/dist/revalidation/tags.js.map +1 -0
- package/dist/revalidation/utils.d.ts +21 -0
- package/dist/revalidation/utils.d.ts.map +1 -0
- package/dist/revalidation/utils.js +51 -0
- package/dist/revalidation/utils.js.map +1 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +10 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/arrayUtils.d.ts +3 -0
- package/dist/utils/arrayUtils.d.ts.map +1 -0
- package/dist/utils/arrayUtils.js +12 -0
- package/dist/utils/arrayUtils.js.map +1 -0
- package/dist/utils/dateUtils.d.ts +9 -0
- package/dist/utils/dateUtils.d.ts.map +1 -0
- package/dist/utils/dateUtils.js +26 -0
- package/dist/utils/dateUtils.js.map +1 -0
- package/dist/utils/errors.d.ts +56 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +100 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json-utils.d.ts +17 -0
- package/dist/utils/json-utils.d.ts.map +1 -0
- package/dist/utils/json-utils.js +43 -0
- package/dist/utils/json-utils.js.map +1 -0
- package/dist/utils/retry.d.ts +112 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +221 -0
- package/dist/utils/retry.js.map +1 -0
- package/package.json +12 -6
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contentful Asset API Module
|
|
3
|
+
*
|
|
4
|
+
* Provides functions for fetching and serving Contentful assets
|
|
5
|
+
* with proper caching and Content-Disposition handling.
|
|
6
|
+
*/
|
|
7
|
+
import { type ContentfulAssetResponse } from '../client';
|
|
8
|
+
import type { ContentfulConfig, FetchOptions } from '../types';
|
|
9
|
+
export type { ContentfulAssetFields, ContentfulAssetResponse } from '../client';
|
|
10
|
+
/**
|
|
11
|
+
* Check if a content type can be displayed inline in the browser.
|
|
12
|
+
* Returns true for PDFs, images, videos, and common text formats.
|
|
13
|
+
*
|
|
14
|
+
* @param contentType - MIME type to check
|
|
15
|
+
* @returns true if the browser can display this content type inline
|
|
16
|
+
*/
|
|
17
|
+
export declare function isBrowserViewable(contentType: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Fetch asset metadata from Contentful by asset ID.
|
|
20
|
+
* Uses the shared Contentful client with rate limiting and retry logic.
|
|
21
|
+
*
|
|
22
|
+
* @param config - Contentful configuration
|
|
23
|
+
* @param assetId - The Contentful asset ID
|
|
24
|
+
* @param options - Optional fetch options (preview, cache settings)
|
|
25
|
+
* @returns The asset response or null if not found
|
|
26
|
+
*/
|
|
27
|
+
export declare function contentfulAssetRest(config: ContentfulConfig, assetId: string, options: FetchOptions): Promise<ContentfulAssetResponse | null>;
|
|
28
|
+
//# sourceMappingURL=asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/api/asset.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,uBAAuB,EAAuB,MAAM,WAAW,CAAC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG/D,YAAY,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAchF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAO9D;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAazC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contentful Asset API Module
|
|
3
|
+
*
|
|
4
|
+
* Provides functions for fetching and serving Contentful assets
|
|
5
|
+
* with proper caching and Content-Disposition handling.
|
|
6
|
+
*/
|
|
7
|
+
import { getContentfulClient } from '../client';
|
|
8
|
+
import { getCacheTags } from '../revalidation/utils';
|
|
9
|
+
/**
|
|
10
|
+
* Content types that browsers can display inline
|
|
11
|
+
*/
|
|
12
|
+
const BROWSER_VIEWABLE_TYPES = [
|
|
13
|
+
'application/pdf',
|
|
14
|
+
'text/plain',
|
|
15
|
+
'text/html',
|
|
16
|
+
'text/css',
|
|
17
|
+
'text/javascript',
|
|
18
|
+
'application/json',
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Check if a content type can be displayed inline in the browser.
|
|
22
|
+
* Returns true for PDFs, images, videos, and common text formats.
|
|
23
|
+
*
|
|
24
|
+
* @param contentType - MIME type to check
|
|
25
|
+
* @returns true if the browser can display this content type inline
|
|
26
|
+
*/
|
|
27
|
+
export function isBrowserViewable(contentType) {
|
|
28
|
+
// All images and videos are viewable
|
|
29
|
+
if (contentType.startsWith('image/') || contentType.startsWith('video/')) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return BROWSER_VIEWABLE_TYPES.includes(contentType);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Fetch asset metadata from Contentful by asset ID.
|
|
36
|
+
* Uses the shared Contentful client with rate limiting and retry logic.
|
|
37
|
+
*
|
|
38
|
+
* @param config - Contentful configuration
|
|
39
|
+
* @param assetId - The Contentful asset ID
|
|
40
|
+
* @param options - Optional fetch options (preview, cache settings)
|
|
41
|
+
* @returns The asset response or null if not found
|
|
42
|
+
*/
|
|
43
|
+
export async function contentfulAssetRest(config, assetId, options) {
|
|
44
|
+
const client = getContentfulClient(config, options.preview);
|
|
45
|
+
// Get cache tags for this asset
|
|
46
|
+
const cacheTags = getCacheTags('asset', assetId, options?.preview);
|
|
47
|
+
return client.getAsset(assetId, {
|
|
48
|
+
...options,
|
|
49
|
+
next: {
|
|
50
|
+
revalidate: options?.next?.revalidate ?? 86400, // Default 24 hours
|
|
51
|
+
tags: [...cacheTags, ...(options?.next?.tags ?? [])],
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.js","sourceRoot":"","sources":["../../src/api/asset.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAgC,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAMrD;;GAEG;AACH,MAAM,sBAAsB,GAAG;IAC7B,iBAAiB;IACjB,YAAY;IACZ,WAAW;IACX,UAAU;IACV,iBAAiB;IACjB,kBAAkB;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,qCAAqC;IACrC,IAAI,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,sBAAsB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAwB,EACxB,OAAe,EACf,OAAqB;IAErB,MAAM,MAAM,GAAG,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE5D,gCAAgC;IAChC,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAEnE,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE;QAC9B,GAAG,OAAO;QACV,IAAI,EAAE;YACJ,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,IAAI,KAAK,EAAE,mBAAmB;YACnE,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;SACrD;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BaseConverterContext, UrlCalculators } from '../converters/helpers';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a base converter context with default resolvers for all content types.
|
|
4
|
+
*
|
|
5
|
+
* Sets up default converters for:
|
|
6
|
+
* - Pages, Articles, Article Types
|
|
7
|
+
* - Components, Collections, External Components
|
|
8
|
+
* - Links (pages, articles, tags, people, etc.)
|
|
9
|
+
* - Navigation items
|
|
10
|
+
*
|
|
11
|
+
* Projects can extend this context with custom resolvers for specific content types.
|
|
12
|
+
*
|
|
13
|
+
* @returns Base converter context with all default resolvers configured
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const context = createBaseConverterContext();
|
|
18
|
+
*
|
|
19
|
+
* // Use with API functions
|
|
20
|
+
* const page = await contentfulPageRest(context, config, 'home');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function createBaseConverterContext(urlCalculators: UrlCalculators): BaseConverterContext;
|
|
24
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/api/context.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,oBAAoB,EAKpB,cAAc,EACf,MAAM,uBAAuB,CAAC;AAW/B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,cAAc,GAAG,oBAAoB,CAqC/F"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { baseArticleConverter, baseArticleLinkConverter, baseArticleTypeConverter, baseArticleTypeLinkConverter, } from '../converters/article';
|
|
2
|
+
import { baseCollectionConverter } from '../converters/collection';
|
|
3
|
+
import { baseComponentConverter } from '../converters/component';
|
|
4
|
+
import { baseCustomTypeConverter, baseCustomTypeLinkConverter } from '../converters/customType';
|
|
5
|
+
import { baseExternalComponentConverter } from '../converters/externalComponent';
|
|
6
|
+
import { baseLinkConverter } from '../converters/link';
|
|
7
|
+
import { baseNavigationItemConverter } from '../converters/navigationItem';
|
|
8
|
+
import { basePageConverter, basePageLinkConverter, basePageVariantLinkConverter, } from '../converters/page';
|
|
9
|
+
import { basePersonConverter, basePersonLinkConverter } from '../converters/person';
|
|
10
|
+
import { baseTagConverter, baseTagLinkConverter } from '../converters/tag';
|
|
11
|
+
/**
|
|
12
|
+
* Creates a base converter context with default resolvers for all content types.
|
|
13
|
+
*
|
|
14
|
+
* Sets up default converters for:
|
|
15
|
+
* - Pages, Articles, Article Types
|
|
16
|
+
* - Components, Collections, External Components
|
|
17
|
+
* - Links (pages, articles, tags, people, etc.)
|
|
18
|
+
* - Navigation items
|
|
19
|
+
*
|
|
20
|
+
* Projects can extend this context with custom resolvers for specific content types.
|
|
21
|
+
*
|
|
22
|
+
* @returns Base converter context with all default resolvers configured
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const context = createBaseConverterContext();
|
|
27
|
+
*
|
|
28
|
+
* // Use with API functions
|
|
29
|
+
* const page = await contentfulPageRest(context, config, 'home');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function createBaseConverterContext(urlCalculators) {
|
|
33
|
+
const linkResolver = new Map();
|
|
34
|
+
linkResolver.set('page', basePageLinkConverter);
|
|
35
|
+
linkResolver.set('article', baseArticleLinkConverter);
|
|
36
|
+
linkResolver.set('articleType', baseArticleTypeLinkConverter);
|
|
37
|
+
linkResolver.set('tag', baseTagLinkConverter);
|
|
38
|
+
linkResolver.set('person', basePersonLinkConverter);
|
|
39
|
+
linkResolver.set('pageVariant', basePageVariantLinkConverter);
|
|
40
|
+
linkResolver.set('link', baseLinkConverter);
|
|
41
|
+
linkResolver.set('customType', baseCustomTypeLinkConverter);
|
|
42
|
+
const contentResolver = new Map();
|
|
43
|
+
contentResolver.set('collection', baseCollectionConverter);
|
|
44
|
+
contentResolver.set('component', baseComponentConverter);
|
|
45
|
+
contentResolver.set('externalComponent', baseExternalComponentConverter);
|
|
46
|
+
return {
|
|
47
|
+
pageResolver: basePageConverter,
|
|
48
|
+
navigationItemResolver: baseNavigationItemConverter,
|
|
49
|
+
articleResolver: baseArticleConverter,
|
|
50
|
+
articleTypeResolver: baseArticleTypeConverter,
|
|
51
|
+
tagResolver: baseTagConverter,
|
|
52
|
+
personResolver: basePersonConverter,
|
|
53
|
+
customTypeResolver: baseCustomTypeConverter,
|
|
54
|
+
componentResolver: baseComponentConverter,
|
|
55
|
+
collectionResolver: baseCollectionConverter,
|
|
56
|
+
linkResolver,
|
|
57
|
+
contentResolver,
|
|
58
|
+
urlCalculators,
|
|
59
|
+
videoPrefix: '',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/api/context.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAChG,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AASjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,0BAA0B,CAAC,cAA8B;IACvE,MAAM,YAAY,GAAoB,IAAI,GAAG,EAAE,CAAC;IAChD,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,qBAA6C,CAAC,CAAC;IACxE,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,wBAA8D,CAAC,CAAC;IAC5F,YAAY,CAAC,GAAG,CACd,aAAa,EACb,4BAAsE,CACvE,CAAC;IACF,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,oBAA4C,CAAC,CAAC;IACtE,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,uBAA+C,CAAC,CAAC;IAC5E,YAAY,CAAC,GAAG,CAAC,aAAa,EAAE,4BAAoD,CAAC,CAAC;IACtF,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,iBAAyC,CAAC,CAAC;IACpE,YAAY,CAAC,GAAG,CAAC,YAAY,EAAE,2BAAmD,CAAC,CAAC;IAEpF,MAAM,eAAe,GAAuB,IAAI,GAAG,EAAE,CAAC;IACtD,eAAe,CAAC,GAAG,CAAC,YAAY,EAAE,uBAAkD,CAAC,CAAC;IACtF,eAAe,CAAC,GAAG,CAAC,WAAW,EAAE,sBAAiD,CAAC,CAAC;IACpF,eAAe,CAAC,GAAG,CACjB,mBAAmB,EACnB,8BAAyD,CAC1D,CAAC;IAEF,OAAO;QACL,YAAY,EAAE,iBAAiB;QAC/B,sBAAsB,EAAE,2BAA2B;QACnD,eAAe,EAAE,oBAAoB;QACrC,mBAAmB,EAAE,wBAAwB;QAC7C,WAAW,EAAE,gBAAgB;QAC7B,cAAc,EAAE,mBAAmB;QACnC,kBAAkB,EAAE,uBAAuB;QAC3C,iBAAiB,EAAE,sBAAsB;QACzC,kBAAkB,EAAE,uBAAuB;QAC3C,YAAY;QACZ,eAAe;QACf,cAAc;QACd,WAAW,EAAE,EAAE;KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IBaseCustomType } from '@se-studio/core-data-types';
|
|
2
|
+
import type { BaseConverterContext } from '../converters/helpers';
|
|
3
|
+
import type { CmsResponse, ContentfulConfig, FetchOptions } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Fetches a custom type from Contentful by slug
|
|
6
|
+
*
|
|
7
|
+
* Custom types represent index pages for categories like Topics or Resources.
|
|
8
|
+
* They provide configuration for both the main index page and potentially
|
|
9
|
+
* individual entry pages.
|
|
10
|
+
*
|
|
11
|
+
* @param context - Converter context
|
|
12
|
+
* @param config - Contentful configuration
|
|
13
|
+
* @param slug - Custom type's slug to fetch (e.g., 'topics', 'resources')
|
|
14
|
+
* @param options - Fetch options (locale, preview, caching, etc.)
|
|
15
|
+
* @returns Promise resolving to IBaseCustomType or null if not found
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const customType = await contentfulCustomTypeRest(
|
|
20
|
+
* context,
|
|
21
|
+
* {
|
|
22
|
+
* spaceId: process.env.CONTENTFUL_SPACE_ID!,
|
|
23
|
+
* accessToken: process.env.CONTENTFUL_ACCESS_TOKEN!,
|
|
24
|
+
* },
|
|
25
|
+
* 'topics',
|
|
26
|
+
* {
|
|
27
|
+
* locale: 'en-US',
|
|
28
|
+
* cache: {
|
|
29
|
+
* tags: ['topics-custom-type'],
|
|
30
|
+
* revalidate: 3600
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* );
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function contentfulCustomTypeRest(context: BaseConverterContext, config: ContentfulConfig, slug: string, options: FetchOptions): Promise<CmsResponse<IBaseCustomType | null>>;
|
|
37
|
+
//# sourceMappingURL=custom-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-type.d.ts","sourceRoot":"","sources":["../../src/api/custom-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,WAAW,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAc9C"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { fetchSingleEntity } from './helpers';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches a custom type from Contentful by slug
|
|
4
|
+
*
|
|
5
|
+
* Custom types represent index pages for categories like Topics or Resources.
|
|
6
|
+
* They provide configuration for both the main index page and potentially
|
|
7
|
+
* individual entry pages.
|
|
8
|
+
*
|
|
9
|
+
* @param context - Converter context
|
|
10
|
+
* @param config - Contentful configuration
|
|
11
|
+
* @param slug - Custom type's slug to fetch (e.g., 'topics', 'resources')
|
|
12
|
+
* @param options - Fetch options (locale, preview, caching, etc.)
|
|
13
|
+
* @returns Promise resolving to IBaseCustomType or null if not found
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const customType = await contentfulCustomTypeRest(
|
|
18
|
+
* context,
|
|
19
|
+
* {
|
|
20
|
+
* spaceId: process.env.CONTENTFUL_SPACE_ID!,
|
|
21
|
+
* accessToken: process.env.CONTENTFUL_ACCESS_TOKEN!,
|
|
22
|
+
* },
|
|
23
|
+
* 'topics',
|
|
24
|
+
* {
|
|
25
|
+
* locale: 'en-US',
|
|
26
|
+
* cache: {
|
|
27
|
+
* tags: ['topics-custom-type'],
|
|
28
|
+
* revalidate: 3600
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* );
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export async function contentfulCustomTypeRest(context, config, slug, options) {
|
|
35
|
+
return fetchSingleEntity(context, config, {
|
|
36
|
+
contentType: 'customType',
|
|
37
|
+
cacheTagType: 'customType',
|
|
38
|
+
cacheTagIdentifier: slug,
|
|
39
|
+
query: { 'fields.slug': slug },
|
|
40
|
+
resolver: (ctx, entry) => ctx.customTypeResolver(ctx, entry),
|
|
41
|
+
errorLogContext: { slug },
|
|
42
|
+
}, options);
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=custom-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-type.js","sourceRoot":"","sources":["../../src/api/custom-type.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAA6B,EAC7B,MAAwB,EACxB,IAAY,EACZ,OAAqB;IAErB,OAAO,iBAAiB,CACtB,OAAO,EACP,MAAM,EACN;QACE,WAAW,EAAE,YAAY;QACzB,YAAY,EAAE,YAAY;QAC1B,kBAAkB,EAAE,IAAI;QACxB,KAAK,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE;QAC9B,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC;QAC5D,eAAe,EAAE,EAAE,IAAI,EAAE;KAC1B,EACD,OAAO,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { IArticleLink, IInternalLink, IVisual } from '@se-studio/core-data-types';
|
|
2
|
+
import type { Asset, Entry, EntrySkeletonType } from 'contentful';
|
|
3
|
+
import type { BaseArticleSkeleton } from '../baseTypes/baseArticle';
|
|
4
|
+
import type { BaseArticleTypeSkeleton } from '../baseTypes/baseArticleType';
|
|
5
|
+
import type { BasePageSkeleton } from '../baseTypes/basePage';
|
|
6
|
+
import type { BasePersonSkeleton } from '../baseTypes/basePerson';
|
|
7
|
+
import type { BaseTagSkeleton } from '../baseTypes/baseTag';
|
|
8
|
+
import { type ContentfulResponse, getContentfulClient } from '../client';
|
|
9
|
+
import type { BaseConverterContext, ConverterContext } from '../converters/helpers';
|
|
10
|
+
import type { CmsResponse, ContentfulConfig, FetchOptions } from '../types';
|
|
11
|
+
import type { DefaultChainModifier, PossibleResolvedEntry, SingleEntityFetchConfig } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Build fetch options with defaults.
|
|
14
|
+
*
|
|
15
|
+
* @param options - Provided fetch options
|
|
16
|
+
* @param defaultDraftOnly - Default value for preview if not specified
|
|
17
|
+
* @returns Combined fetch options
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildFetchOptions(options: FetchOptions | undefined, defaultDraftOnly?: boolean): FetchOptions;
|
|
20
|
+
/**
|
|
21
|
+
* Get Contentful configuration from environment variables.
|
|
22
|
+
*
|
|
23
|
+
* Supports CONTENTFUL_SPACE_ID, CONTENTFUL_ENVIRONMENT (or CONTENTFUL_ENVIRONMENT_NAME),
|
|
24
|
+
* and access tokens for both delivery and preview.
|
|
25
|
+
*
|
|
26
|
+
* @param preview - Whether to get the preview access token
|
|
27
|
+
* @returns Contentful configuration object
|
|
28
|
+
* @throws Error if required environment variables are missing
|
|
29
|
+
*/
|
|
30
|
+
export declare function getContentfulConfig(preview: boolean): ContentfulConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Generic fetcher helper that simplifies CMS data fetching in projects.
|
|
33
|
+
*
|
|
34
|
+
* Combines a lower-level fetcher with project-specific context and configuration,
|
|
35
|
+
* handles common error logging pattern, and returns the data directly.
|
|
36
|
+
*
|
|
37
|
+
* @param fetcher - The API function to call
|
|
38
|
+
* @param context - The project's converter context
|
|
39
|
+
* @param config - Contentful configuration
|
|
40
|
+
* @param options - Fetch options
|
|
41
|
+
* @param errorLabel - Human-readable label for error logging (e.g., 'page links')
|
|
42
|
+
* @returns Promise resolving to the fetched data
|
|
43
|
+
*/
|
|
44
|
+
export declare function fetchWithErrors<T>(fetcher: (context: BaseConverterContext, config: ContentfulConfig, options: FetchOptions) => Promise<CmsResponse<T>>, context: BaseConverterContext, config: ContentfulConfig, options: FetchOptions, errorLabel: string): Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Field selection constants for link-only fetching.
|
|
47
|
+
* These reduce payload size by excluding content arrays, navigation, templates, etc.
|
|
48
|
+
*/
|
|
49
|
+
export declare const PAGE_LINK_FIELDS = "sys,fields.cmsLabel,fields.title,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden,fields.tags";
|
|
50
|
+
export declare const ARTICLE_LINK_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,fields.externalLink,fields.download";
|
|
51
|
+
export declare const ARTICLE_TYPE_LINK_FIELDS = "sys,fields.name,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden";
|
|
52
|
+
export declare const TAG_LINK_FIELDS = "sys,fields.cmsLabel,fields.name,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden";
|
|
53
|
+
export declare const PERSON_LINK_FIELDS = "sys,fields.name,fields.slug,fields.media,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden";
|
|
54
|
+
export declare function convertAllAssets(response: ContentfulResponse<unknown>, context: BaseConverterContext): Map<string, IVisual>;
|
|
55
|
+
export declare function convertAllRawAssets(response: ContentfulResponse<unknown>): Map<string, Asset>;
|
|
56
|
+
export declare function convertAllIncludes(response: ContentfulResponse<unknown>): Map<string, PossibleResolvedEntry>;
|
|
57
|
+
/**
|
|
58
|
+
* Generic helper for fetching a single entity from Contentful.
|
|
59
|
+
* Handles caching, error handling, retry logic, and conversion consistently.
|
|
60
|
+
*
|
|
61
|
+
* @param context - Base converter context for content transformation
|
|
62
|
+
* @param config - Contentful configuration (spaceId, accessToken, environment)
|
|
63
|
+
* @param fetchConfig - Configuration for this specific fetch
|
|
64
|
+
* @param options - Optional fetch options (locale, preview, caching, retry)
|
|
65
|
+
* @returns Promise resolving to the entity or null if not found, with any conversion errors
|
|
66
|
+
*/
|
|
67
|
+
export declare function fetchSingleEntity<TEntry extends EntrySkeletonType, TResult>(context: BaseConverterContext, config: ContentfulConfig, fetchConfig: SingleEntityFetchConfig<TEntry, TResult>, options: FetchOptions): Promise<CmsResponse<TResult | null>>;
|
|
68
|
+
/**
|
|
69
|
+
* Shared helper function for paginated Contentful link fetching.
|
|
70
|
+
* Returns links with lastModified metadata from sys.updatedAt.
|
|
71
|
+
*/
|
|
72
|
+
export declare function fetchAllLinks<TEntry extends EntrySkeletonType = BasePageSkeleton | BaseArticleSkeleton | BaseArticleTypeSkeleton | BaseTagSkeleton | BasePersonSkeleton, TResult extends IInternalLink | IArticleLink = IInternalLink>(contentType: string, client: ReturnType<typeof getContentfulClient>, requestOptions: FetchOptions | undefined, converter: (context: ConverterContext, entry: Entry<TEntry, DefaultChainModifier, string>) => TResult, context: BaseConverterContext, pageSize?: number, select?: string): Promise<CmsResponse<TResult[]>>;
|
|
73
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/api/helpers.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { getContentfulClient } from '../client';
|
|
2
|
+
import { convertAssetToVisual } from '../converters/asset';
|
|
3
|
+
import { processIconsForSprite } from '../converters/iconCollector';
|
|
4
|
+
import { getCacheTags } from '../revalidation/utils';
|
|
5
|
+
import { withRetry } from '../utils';
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// CMS Configuration and Options
|
|
8
|
+
// ============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Build fetch options with defaults.
|
|
11
|
+
*
|
|
12
|
+
* @param options - Provided fetch options
|
|
13
|
+
* @param defaultDraftOnly - Default value for preview if not specified
|
|
14
|
+
* @returns Combined fetch options
|
|
15
|
+
*/
|
|
16
|
+
export function buildFetchOptions(options, defaultDraftOnly = false) {
|
|
17
|
+
const preview = options?.preview === undefined ? defaultDraftOnly : options.preview;
|
|
18
|
+
return {
|
|
19
|
+
preview,
|
|
20
|
+
cache: 'force-cache',
|
|
21
|
+
...options,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get Contentful configuration from environment variables.
|
|
26
|
+
*
|
|
27
|
+
* Supports CONTENTFUL_SPACE_ID, CONTENTFUL_ENVIRONMENT (or CONTENTFUL_ENVIRONMENT_NAME),
|
|
28
|
+
* and access tokens for both delivery and preview.
|
|
29
|
+
*
|
|
30
|
+
* @param preview - Whether to get the preview access token
|
|
31
|
+
* @returns Contentful configuration object
|
|
32
|
+
* @throws Error if required environment variables are missing
|
|
33
|
+
*/
|
|
34
|
+
export function getContentfulConfig(preview) {
|
|
35
|
+
const spaceId = process.env.CONTENTFUL_SPACE_ID;
|
|
36
|
+
const environment = process.env.CONTENTFUL_ENVIRONMENT || process.env.CONTENTFUL_ENVIRONMENT_NAME;
|
|
37
|
+
const accessToken = preview
|
|
38
|
+
? process.env.CONTENTFUL_PREVIEW_ACCESS_TOKEN
|
|
39
|
+
: process.env.CONTENTFUL_ACCESS_TOKEN;
|
|
40
|
+
if (!spaceId) {
|
|
41
|
+
throw new Error('CONTENTFUL_SPACE_ID environment variable is required');
|
|
42
|
+
}
|
|
43
|
+
if (!accessToken) {
|
|
44
|
+
if (preview) {
|
|
45
|
+
throw new Error('CONTENTFUL_PREVIEW_ACCESS_TOKEN environment variable is required');
|
|
46
|
+
}
|
|
47
|
+
throw new Error('CONTENTFUL_ACCESS_TOKEN environment variable is required');
|
|
48
|
+
}
|
|
49
|
+
if (!environment) {
|
|
50
|
+
throw new Error('CONTENTFUL_ENVIRONMENT or CONTENTFUL_ENVIRONMENT_NAME environment variable is required');
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
spaceId,
|
|
54
|
+
accessToken,
|
|
55
|
+
environment,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Generic fetcher helper that simplifies CMS data fetching in projects.
|
|
60
|
+
*
|
|
61
|
+
* Combines a lower-level fetcher with project-specific context and configuration,
|
|
62
|
+
* handles common error logging pattern, and returns the data directly.
|
|
63
|
+
*
|
|
64
|
+
* @param fetcher - The API function to call
|
|
65
|
+
* @param context - The project's converter context
|
|
66
|
+
* @param config - Contentful configuration
|
|
67
|
+
* @param options - Fetch options
|
|
68
|
+
* @param errorLabel - Human-readable label for error logging (e.g., 'page links')
|
|
69
|
+
* @returns Promise resolving to the fetched data
|
|
70
|
+
*/
|
|
71
|
+
export async function fetchWithErrors(fetcher, context, config, options, errorLabel) {
|
|
72
|
+
const response = await fetcher(context, config, options);
|
|
73
|
+
if (response.errors.length > 0) {
|
|
74
|
+
console.warn(`Errors occurred while fetching ${errorLabel}:`, response.errors);
|
|
75
|
+
}
|
|
76
|
+
return response.data;
|
|
77
|
+
}
|
|
78
|
+
// ============================================================================
|
|
79
|
+
// Field Selection Constants
|
|
80
|
+
// ============================================================================
|
|
81
|
+
/**
|
|
82
|
+
* Field selection constants for link-only fetching.
|
|
83
|
+
* These reduce payload size by excluding content arrays, navigation, templates, etc.
|
|
84
|
+
*/
|
|
85
|
+
export const PAGE_LINK_FIELDS = 'sys,fields.cmsLabel,fields.title,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden,fields.tags';
|
|
86
|
+
export const ARTICLE_LINK_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,fields.externalLink,fields.download';
|
|
87
|
+
export const ARTICLE_TYPE_LINK_FIELDS = 'sys,fields.name,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden';
|
|
88
|
+
export const TAG_LINK_FIELDS = 'sys,fields.cmsLabel,fields.name,fields.slug,fields.featuredImage,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden';
|
|
89
|
+
export const PERSON_LINK_FIELDS = 'sys,fields.name,fields.slug,fields.media,fields.backgroundColour,fields.textColour,fields.indexed,fields.hidden';
|
|
90
|
+
// ============================================================================
|
|
91
|
+
// Asset and Include Conversion
|
|
92
|
+
// ============================================================================
|
|
93
|
+
export function convertAllAssets(response, context) {
|
|
94
|
+
const visuals = new Map();
|
|
95
|
+
const assets = response.includes?.Asset;
|
|
96
|
+
if (assets && assets.length > 0) {
|
|
97
|
+
for (const asset of assets) {
|
|
98
|
+
const visual = convertAssetToVisual(context, asset);
|
|
99
|
+
if (visual) {
|
|
100
|
+
visuals.set(visual.id, visual);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return visuals;
|
|
105
|
+
}
|
|
106
|
+
export function convertAllRawAssets(response) {
|
|
107
|
+
const rawAssets = new Map();
|
|
108
|
+
const assets = response.includes?.Asset;
|
|
109
|
+
if (assets && assets.length > 0) {
|
|
110
|
+
for (const asset of assets) {
|
|
111
|
+
rawAssets.set(asset.sys.id, asset);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return rawAssets;
|
|
115
|
+
}
|
|
116
|
+
export function convertAllIncludes(response) {
|
|
117
|
+
const includes = new Map();
|
|
118
|
+
const entries = [...response.items, ...(response.includes?.Entry || [])];
|
|
119
|
+
if (entries && entries.length > 0) {
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
if (entry?.sys && entry.fields) {
|
|
122
|
+
includes.set(entry.sys.id, {
|
|
123
|
+
id: entry.sys.id,
|
|
124
|
+
type: entry.sys.contentType.sys.id,
|
|
125
|
+
entry,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return includes;
|
|
131
|
+
}
|
|
132
|
+
// ============================================================================
|
|
133
|
+
// Generic Single Entity Fetcher
|
|
134
|
+
// ============================================================================
|
|
135
|
+
/**
|
|
136
|
+
* Generic helper for fetching a single entity from Contentful.
|
|
137
|
+
* Handles caching, error handling, retry logic, and conversion consistently.
|
|
138
|
+
*
|
|
139
|
+
* @param context - Base converter context for content transformation
|
|
140
|
+
* @param config - Contentful configuration (spaceId, accessToken, environment)
|
|
141
|
+
* @param fetchConfig - Configuration for this specific fetch
|
|
142
|
+
* @param options - Optional fetch options (locale, preview, caching, retry)
|
|
143
|
+
* @returns Promise resolving to the entity or null if not found, with any conversion errors
|
|
144
|
+
*/
|
|
145
|
+
export async function fetchSingleEntity(context, config, fetchConfig, options) {
|
|
146
|
+
const client = getContentfulClient(config, options.preview);
|
|
147
|
+
// Set cache tags for this request
|
|
148
|
+
const cacheTags = getCacheTags(fetchConfig.cacheTagType, fetchConfig.cacheTagIdentifier, options?.preview);
|
|
149
|
+
const requestOptions = {
|
|
150
|
+
...options,
|
|
151
|
+
next: {
|
|
152
|
+
...options?.next,
|
|
153
|
+
tags: cacheTags,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
const fetchFn = async () => {
|
|
157
|
+
const response = await client.getEntries({
|
|
158
|
+
content_type: fetchConfig.contentType,
|
|
159
|
+
...fetchConfig.query,
|
|
160
|
+
include: 10,
|
|
161
|
+
locale: options?.locale,
|
|
162
|
+
limit: 1,
|
|
163
|
+
}, requestOptions);
|
|
164
|
+
const entry = response.items[0];
|
|
165
|
+
if (!entry || !entry.fields) {
|
|
166
|
+
return { data: null, errors: [] };
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
const assets = convertAllAssets(response, context);
|
|
170
|
+
const rawAssets = convertAllRawAssets(response);
|
|
171
|
+
const includes = convertAllIncludes(response);
|
|
172
|
+
const fullContext = {
|
|
173
|
+
...context,
|
|
174
|
+
includes,
|
|
175
|
+
assets,
|
|
176
|
+
rawAssets,
|
|
177
|
+
errors: [],
|
|
178
|
+
};
|
|
179
|
+
const converted = fetchConfig.resolver(fullContext, entry);
|
|
180
|
+
// Process icons if the result has an icons field (e.g., IBasePage)
|
|
181
|
+
if (converted && typeof converted === 'object' && 'icons' in converted) {
|
|
182
|
+
const icons = converted.icons;
|
|
183
|
+
if (icons && Array.isArray(icons) && icons.length > 0) {
|
|
184
|
+
const processedIcons = await processIconsForSprite(icons);
|
|
185
|
+
converted.icons =
|
|
186
|
+
processedIcons.length > 0 ? processedIcons : undefined;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Log errors in production
|
|
190
|
+
if (fullContext.errors.length > 0 &&
|
|
191
|
+
typeof process !== 'undefined' &&
|
|
192
|
+
process.env?.NODE_ENV === 'production') {
|
|
193
|
+
console.error(`CMS conversion errors for ${fetchConfig.contentType}:`, {
|
|
194
|
+
entryId: entry.sys.id,
|
|
195
|
+
...fetchConfig.errorLogContext,
|
|
196
|
+
errors: fullContext.errors,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return { data: converted, errors: fullContext.errors };
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
const entryId = entry.sys.id;
|
|
203
|
+
const entryType = entry.sys.contentType?.sys?.id;
|
|
204
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown conversion error';
|
|
205
|
+
const cmsError = {
|
|
206
|
+
entryId,
|
|
207
|
+
entryType,
|
|
208
|
+
message: errorMessage,
|
|
209
|
+
error,
|
|
210
|
+
};
|
|
211
|
+
return { data: null, errors: [cmsError] };
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
// Apply retry logic if configured
|
|
215
|
+
if (options?.retry) {
|
|
216
|
+
return await withRetry(fetchFn, options.retry);
|
|
217
|
+
}
|
|
218
|
+
return await fetchFn();
|
|
219
|
+
}
|
|
220
|
+
// ============================================================================
|
|
221
|
+
// Generic All Links Fetcher
|
|
222
|
+
// ============================================================================
|
|
223
|
+
/**
|
|
224
|
+
* Shared helper function for paginated Contentful link fetching.
|
|
225
|
+
* Returns links with lastModified metadata from sys.updatedAt.
|
|
226
|
+
*/
|
|
227
|
+
export async function fetchAllLinks(contentType, client, requestOptions, converter, context, pageSize = 100, select) {
|
|
228
|
+
const allLinks = [];
|
|
229
|
+
const errors = [];
|
|
230
|
+
let skip = 0;
|
|
231
|
+
let hasMore = true;
|
|
232
|
+
const fetchFn = async () => {
|
|
233
|
+
while (hasMore) {
|
|
234
|
+
try {
|
|
235
|
+
const response = await client.getEntries({
|
|
236
|
+
content_type: contentType,
|
|
237
|
+
include: 2, // Minimal include for link-only fetching
|
|
238
|
+
locale: requestOptions?.locale,
|
|
239
|
+
limit: pageSize,
|
|
240
|
+
skip,
|
|
241
|
+
...(select && { select }),
|
|
242
|
+
}, requestOptions);
|
|
243
|
+
if (response.items.length === 0) {
|
|
244
|
+
hasMore = false;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
// Convert entries to links
|
|
248
|
+
const includes = convertAllIncludes(response);
|
|
249
|
+
const assets = convertAllAssets(response, context);
|
|
250
|
+
const rawAssets = convertAllRawAssets(response);
|
|
251
|
+
const fullContext = {
|
|
252
|
+
...context,
|
|
253
|
+
includes,
|
|
254
|
+
assets,
|
|
255
|
+
rawAssets,
|
|
256
|
+
errors: [],
|
|
257
|
+
};
|
|
258
|
+
for (const entry of response.items) {
|
|
259
|
+
if (!entry.fields)
|
|
260
|
+
continue;
|
|
261
|
+
try {
|
|
262
|
+
const converted = converter(fullContext, entry);
|
|
263
|
+
// Add lastModified from sys.updatedAt
|
|
264
|
+
converted.lastModified = entry.sys.updatedAt
|
|
265
|
+
? new Date(entry.sys.updatedAt)
|
|
266
|
+
: undefined;
|
|
267
|
+
allLinks.push(converted);
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
const entryId = entry.sys.id;
|
|
271
|
+
const entryType = entry.sys.contentType?.sys?.id;
|
|
272
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown conversion error';
|
|
273
|
+
errors.push({
|
|
274
|
+
entryId,
|
|
275
|
+
entryType,
|
|
276
|
+
message: errorMessage,
|
|
277
|
+
error,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
skip += pageSize;
|
|
282
|
+
// Check if we've fetched all items
|
|
283
|
+
if (skip >= response.total) {
|
|
284
|
+
hasMore = false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
console.error('Error fetching links', typeof error, error, JSON.stringify(error, null, 2));
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return { data: allLinks, errors };
|
|
293
|
+
};
|
|
294
|
+
return await fetchFn();
|
|
295
|
+
}
|
|
296
|
+
//# sourceMappingURL=helpers.js.map
|