mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
27 lines
964 B
TypeScript
27 lines
964 B
TypeScript
import { KiboCommerceConfig } from '../index'
|
|
import { getAllProductsQuery } from '../queries/get-all-products-query';
|
|
import { normalizeProduct } from '../../lib/normalize'
|
|
|
|
export type GetAllProductPathsResult = {
|
|
products: Array<{ path: string }>
|
|
}
|
|
|
|
export default function getAllProductPathsOperation({commerce,}: any) {
|
|
async function getAllProductPaths({ config }: {config?: KiboCommerceConfig } = {}): Promise<GetAllProductPathsResult> {
|
|
|
|
const cfg = commerce.getConfig(config)
|
|
|
|
const productVariables = {startIndex: 0, pageSize: 100};
|
|
const { data } = await cfg.fetch(getAllProductsQuery, { variables: productVariables });
|
|
|
|
const normalizedProducts = data.products.items ? data.products.items.map( (item:any) => normalizeProduct(item, cfg)) : [];
|
|
const products = normalizedProducts.map((product: any) => ({ path: product.path }))
|
|
|
|
return Promise.resolve({
|
|
products: products
|
|
})
|
|
}
|
|
|
|
return getAllProductPaths
|
|
}
|