mirror of
https://github.com/vercel/commerce.git
synced 2025-06-20 14:11:20 +00:00
* TEC-252: Base integration with commercetools using fetchers for REST and GraphQL endpoints * TEC-252: WIP commenting some components that are failing while we don't have all the hooks defined * add sdk integration * TEC-256: Implementing product search * TEC-256: removing unnecessary env variables * TEC-256: review comments * TEC-256: other remaining review fixes Co-authored-by: nicossosa93 <nicolas.sosa@devgurus.io>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { Provider, CommercetoolsConfig } from '@framework/api'
|
|
import { OperationContext } from '@commerce/api/operations'
|
|
import { Category } from '@commerce/types/site'
|
|
import { getAllCategoriesAndBrandsQuery } from '@framework/utils/queries/get-category'
|
|
import { normalizeSite } from '@framework/lib/normalize'
|
|
|
|
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 = getAllCategoriesAndBrandsQuery,
|
|
variables,
|
|
config: cfg,
|
|
}: {
|
|
query?: string
|
|
variables?: any
|
|
config?: Partial<CommercetoolsConfig>
|
|
preview?: boolean
|
|
} = {}): Promise<GetSiteInfoResult> {
|
|
const config = commerce.getConfig(cfg)
|
|
const {
|
|
data: { categories, productTypes },
|
|
}: any = await config.fetch(query)
|
|
const ctCategories = categories.results
|
|
const ctBrands =
|
|
productTypes?.results[0]?.attributeDefinitions?.results[0]?.type?.values
|
|
?.results
|
|
return normalizeSite(ctCategories, ctBrands)
|
|
}
|
|
|
|
return getSiteInfo
|
|
}
|