mirror of
https://github.com/vercel/commerce.git
synced 2025-06-20 14:11:20 +00:00
41 lines
859 B
TypeScript
41 lines
859 B
TypeScript
import { getConfig, SaleorConfig } from '../api'
|
|
import { PageCountableEdge } from '../schema'
|
|
import * as query from '../utils/queries'
|
|
|
|
type Variables = {
|
|
first?: number
|
|
}
|
|
|
|
type ReturnType = {
|
|
pages: Page[]
|
|
}
|
|
|
|
export type Page = {
|
|
id: string
|
|
name: string
|
|
url: string
|
|
sort_order?: number
|
|
body: string
|
|
}
|
|
|
|
const getAllPages = async (options?: {
|
|
variables?: Variables
|
|
config: SaleorConfig
|
|
preview?: boolean
|
|
}): Promise<ReturnType> => {
|
|
let { config, variables = { first: 100 } } = options ?? {}
|
|
config = getConfig(config)
|
|
const { locale } = config
|
|
const { data } = await config.fetch(query.PageMany, { variables })
|
|
|
|
const pages = data.pages?.edges?.map(({ node: { title: name, slug, ...node } }: PageCountableEdge) => ({
|
|
...node,
|
|
url: `/${locale}/${slug}`,
|
|
name,
|
|
}))
|
|
|
|
return { pages }
|
|
}
|
|
|
|
export default getAllPages
|