mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 07:45:53 +00:00
41 lines
773 B
TypeScript
41 lines
773 B
TypeScript
import { getConfig, SwellConfig } from '../api'
|
|
import fetchAllProducts from '../api/utils/fetch-all-products'
|
|
|
|
type ProductPath = {
|
|
path: string
|
|
}
|
|
|
|
export type ProductPathNode = {
|
|
node: ProductPath
|
|
}
|
|
|
|
type ReturnType = {
|
|
products: ProductPathNode[]
|
|
}
|
|
|
|
const getAllProductPaths = async (options?: {
|
|
variables?: any
|
|
config?: SwellConfig
|
|
preview?: boolean
|
|
}): Promise<ReturnType> => {
|
|
let { config, variables = [{ limit: 100 }] } = options ?? {}
|
|
config = getConfig(config)
|
|
|
|
const products = await fetchAllProducts({
|
|
config,
|
|
query: 'products',
|
|
method: 'list',
|
|
variables,
|
|
})
|
|
|
|
return {
|
|
products: products?.map(({ slug: handle }) => ({
|
|
node: {
|
|
path: `/${handle}`,
|
|
},
|
|
})),
|
|
}
|
|
}
|
|
|
|
export default getAllProductPaths
|