Add Reaction Commerce provider

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux
2021-03-30 20:07:48 +04:00
parent 9b71bd77fc
commit 09249045eb
99 changed files with 24980 additions and 25 deletions

View File

@@ -0,0 +1,32 @@
import { GraphQLFetcherResult } from '@commerce/api'
import { getConfig, ReactionCommerceConfig } from '../api'
import { normalizeProduct, getProductQuery } from '../utils'
type Variables = {
slug: string
}
type ReturnType = {
product: any
}
const getProduct = async (options: {
variables: Variables
config: ReactionCommerceConfig
preview?: boolean
}): Promise<ReturnType> => {
let { config, variables } = options ?? {}
config = getConfig(config)
const { data }: GraphQLFetcherResult = await config.fetch(getProductQuery, {
variables,
})
const { catalogItemProduct: product } = data
return {
product: product ? normalizeProduct(product) : null,
}
}
export default getProduct