import type { OperationContext, OperationOptions, } from '@commerce/api/operations' import { GetSiteInfoQueryVariables } from '../../schema' import type { ShopifyConfig, Provider } from '..' import { GetSiteInfoOperation } from '../../types/site' import { getCategories, getBrands, getSiteInfoQuery } from '../../utils' export default function getSiteInfoOperation({ commerce, }: OperationContext) { async function getSiteInfo(opts?: { config?: Partial preview?: boolean }): Promise async function getSiteInfo( opts: { config?: Partial preview?: boolean } & OperationOptions ): Promise async function getSiteInfo({ query = getSiteInfoQuery, config, variables, }: { query?: string config?: Partial preview?: boolean variables?: GetSiteInfoQueryVariables } = {}): Promise { const cfg = commerce.getConfig(config) const categoriesPromise = getCategories(cfg) const brandsPromise = getBrands(cfg) /* const { fetch, locale } = cfg const { data } = await fetch( query, { variables }, { ...(locale && { headers: { 'Accept-Language': locale, }, }), } ) */ return { categories: await categoriesPromise, brands: await brandsPromise, } } return getSiteInfo }