1- import { CmsClient , components } from '@cowprotocol/cms'
1+ import { components } from '@cowprotocol/cms'
22import { PaginationParam } from 'types'
33import qs from 'qs'
44
55import { toQueryParams } from 'util/queryParams'
66import { getCmsClient } from '@cowprotocol/core'
7+ import { DATA_CACHE_TIME_SECONDS } from '@/const/meta'
78
89const PAGE_SIZE = 50
910
@@ -22,56 +23,17 @@ export type ArticleListResponse = {
2223 }
2324}
2425
25- export type SharedMediaComponent = Schemas [ 'SharedMediaComponent' ]
26- export type SharedQuoteComponent = Schemas [ 'SharedQuoteComponent' ]
2726export type SharedRichTextComponent = Schemas [ 'SharedRichTextComponent' ]
28- export type SharedSliderComponent = Schemas [ 'SharedSliderComponent' ]
29- export type SharedVideoEmbedComponent = Schemas [ 'SharedVideoEmbedComponent' ]
3027export type Category = Schemas [ 'CategoryListResponseDataItem' ]
31- export type ArticleCover = Schemas [ 'Article' ] [ 'cover' ]
32- export type ArticleBlocks = Schemas [ 'Article' ] [ 'blocks' ]
33-
34- export type ArticleBlock =
35- | SharedMediaComponent
36- | SharedQuoteComponent
37- | SharedRichTextComponent
38- | SharedSliderComponent
39- | SharedVideoEmbedComponent
40-
41- export function isSharedMediaComponent ( component : ArticleBlock ) : component is SharedMediaComponent {
42- return component . __component === 'SharedMediaComponent'
43- }
44-
45- export function isSharedQuoteComponent ( component : ArticleBlock ) : component is SharedQuoteComponent {
46- return component . __component === 'SharedQuoteComponent'
47- }
48-
49- export function isSharedRichTextComponent ( component : ArticleBlock ) : component is SharedRichTextComponent {
50- return component . __component === 'shared.rich-text'
51- }
52-
53- export function isSharedSliderComponent ( component : ArticleBlock ) : component is SharedMediaComponent {
54- return component . __component === 'SharedSliderComponent'
55- }
56-
57- export function isSharedVideoEmbedComponent ( component : ArticleBlock ) : component is SharedVideoEmbedComponent {
58- return component . __component === 'SharedVideoEmbedComponent'
59- }
6028
6129/**
6230 * Open API Fetch client. See docs for usage https://openapi-ts.pages.dev/openapi-fetch/
6331 */
6432export const client = getCmsClient ( )
6533
66- /**
67- * Returns the article slugs for the given page.
68- *
69- * @param params pagination params
70- * @returns Slugs
71- */
72- async function getArticlesSlugs ( params : PaginationParam = { } ) : Promise < string [ ] > {
73- const articlesResponse = await getArticles ( params )
74- return articlesResponse . data . map ( ( article : Article ) => article . attributes ! . slug ! )
34+ const clientAddons = {
35+ // https://github.com/openapi-ts/openapi-typescript/issues/1569#issuecomment-1982247959
36+ fetch : ( request : unknown ) => fetch ( request as Request , { next : { revalidate : DATA_CACHE_TIME_SECONDS } } ) ,
7537}
7638
7739/**
@@ -92,6 +54,7 @@ export async function getAllArticleSlugs(): Promise<string[]> {
9254 } ,
9355 } ,
9456 querySerializer,
57+ ...clientAddons ,
9558 } )
9659
9760 if ( error ) {
@@ -119,6 +82,7 @@ export async function getCategories(): Promise<Category[]> {
11982 } ,
12083 sort : 'name:asc' ,
12184 } ,
85+ ...clientAddons ,
12286 } )
12387
12488 if ( error ) {
@@ -174,6 +138,7 @@ export async function getArticles({
174138 } ,
175139 } ,
176140 querySerializer,
141+ ...clientAddons ,
177142 } )
178143
179144 if ( error ) {
@@ -211,6 +176,7 @@ export async function getArticleBySlug(slug: string): Promise<Article | null> {
211176 } ,
212177 } ,
213178 querySerializer,
179+ ...clientAddons ,
214180 } )
215181
216182 if ( error ) {
@@ -303,6 +269,7 @@ async function getBySlugAux(slug: string, endpoint: '/categories' | '/articles')
303269 params : {
304270 query,
305271 } ,
272+ ...clientAddons ,
306273 } )
307274
308275 if ( error ) {
0 commit comments