mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 16:07:01 +00:00
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { Provider, ReactionCommerceConfig } from '../'
|
|
import getCollectionsQuery from '../../utils/queries/get-all-collections-query'
|
|
import { OperationContext } from '@commerce/api/operations'
|
|
import { Category } from '@commerce/types/site'
|
|
import getCategories from '../utils/get-categories'
|
|
import getVendors from '../utils/get-vendors'
|
|
|
|
export type GetSiteInfoResult<
|
|
T extends { categories: any[]; brands: any[] } = {
|
|
categories: Category[]
|
|
brands: any[]
|
|
}
|
|
> = T
|
|
|
|
export default function getSiteInfoOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getSiteInfo({
|
|
query = getCollectionsQuery,
|
|
variables,
|
|
config: cfg,
|
|
}: {
|
|
query?: string
|
|
variables?: any
|
|
config?: Partial<ReactionCommerceConfig>
|
|
preview?: boolean
|
|
} = {}): Promise<GetSiteInfoResult> {
|
|
const config = commerce.getConfig(cfg)
|
|
|
|
const categories = await getCategories(config)
|
|
const brands = await getVendors(config)
|
|
|
|
return {
|
|
categories: categories ?? [],
|
|
brands,
|
|
}
|
|
}
|
|
|
|
return getSiteInfo
|
|
}
|