forked from crowetic/commerce
* Start of Shopify provider * add missing comment to documentation * add missing env vars to documentation * update reference to types file
32 lines
681 B
TypeScript
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
|