mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 13:41:22 +00:00
41 lines
859 B
TypeScript
41 lines
859 B
TypeScript
import { ShopifyConfig } from '../api'
|
|
import fetchAllProducts from '../api/utils/fetch-all-products'
|
|
import getAllProductVendors from './queries/get-all-product-vendors-query'
|
|
|
|
export type Brand = {
|
|
entityId: string
|
|
name: string
|
|
path: string
|
|
}
|
|
|
|
export type BrandEdge = {
|
|
node: Brand
|
|
}
|
|
|
|
export type Brands = BrandEdge[]
|
|
|
|
const getVendors = async (config: ShopifyConfig): Promise<BrandEdge[]> => {
|
|
const vendors = await fetchAllProducts({
|
|
config,
|
|
query: getAllProductVendors,
|
|
variables: {
|
|
first: 250,
|
|
},
|
|
})
|
|
|
|
let vendorsStrings = vendors.map(({ node: { vendor } }) => vendor)
|
|
|
|
return [...new Set(vendorsStrings)].map((v) => {
|
|
const id = v.replace(/\s+/g, '-').toLowerCase()
|
|
return {
|
|
node: {
|
|
entityId: id,
|
|
name: v,
|
|
path: `brands/${id}`,
|
|
},
|
|
}
|
|
})
|
|
}
|
|
|
|
export default getVendors
|