4
0
forked from crowetic/commerce
commerce/framework/shopify/product/get-all-product-paths.ts
Peter Mekhaeil 300d04c1ac
Shopify Provider (#186)
* Start of Shopify provider

* add missing comment to documentation

* add missing env vars to documentation

* update reference to types file
2021-02-12 11:14:16 -03:00

32 lines
681 B
TypeScript

import Client from 'shopify-buy'
import { getConfig } from '../api'
import { Product } from '../types'
import toCommerceProducts from '../utils/to-commerce-products'
type ReturnType = {
products: any[]
}
const getAllProductPaths = async (): Promise<ReturnType> => {
const config = getConfig()
const client = Client.buildClient({
storefrontAccessToken: config.apiToken,
domain: config.commerceUrl,
})
const res = (await client.product.fetchAll()) as Product[]
const products = toCommerceProducts(res)
return {
products: products.map((product) => {
return {
node: { ...product },
}
}),
}
}
export default getAllProductPaths