mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import type { OperationContext } from '@commerce/api/operations'
|
|
import type { KiboCommerceConfig } from '../index'
|
|
import { getAllPagesQuery } from '../queries/get-all-pages-query'
|
|
import { GetPagesQueryParams } from "../../types/page";
|
|
import { normalizePage } from '../../lib/normalize'
|
|
|
|
export type GetAllPagesResult<
|
|
T extends { pages: any[] } = { pages: any[] }
|
|
> = T
|
|
|
|
export default function getAllPagesOperation({
|
|
commerce,
|
|
}: OperationContext<any>) {
|
|
|
|
async function getAllPages({
|
|
query = getAllPagesQuery,
|
|
config,
|
|
variables,
|
|
}: {
|
|
url?: string
|
|
config?: Partial<KiboCommerceConfig>
|
|
variables?: GetPagesQueryParams
|
|
preview?: boolean
|
|
query?: string
|
|
} = {}): Promise<GetAllPagesResult> {
|
|
const cfg = commerce.getConfig(config)
|
|
variables = {
|
|
documentListName: cfg.documentListName
|
|
}
|
|
const { data } = await cfg.fetch(query, { variables });
|
|
|
|
const pages = data.documentListDocuments.items.map(normalizePage);
|
|
|
|
return { pages }
|
|
}
|
|
|
|
return getAllPages
|
|
} |