mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
setup custom fetcher and auth hooks
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ShopifyConfig } from '../api'
|
||||
import { SwellConfig } from '../api'
|
||||
import { CollectionEdge } from '../schema'
|
||||
import getSiteCollectionsQuery from './queries/get-all-collections-query'
|
||||
|
||||
@@ -8,7 +8,7 @@ export type Category = {
|
||||
path: string
|
||||
}
|
||||
|
||||
const getCategories = async (config: ShopifyConfig): Promise<Category[]> => {
|
||||
const getCategories = async (config: SwellConfig): Promise<Category[]> => {
|
||||
const { data } = await config.fetch(getSiteCollectionsQuery, {
|
||||
variables: {
|
||||
first: 250,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { ShopifyConfig } from '../api'
|
||||
import { SwellConfig } from '../api'
|
||||
import fetchAllProducts from '../api/utils/fetch-all-products'
|
||||
import getAllProductVendors from './queries/get-all-product-vendors-query'
|
||||
|
||||
@@ -13,7 +13,7 @@ export type BrandEdge = {
|
||||
|
||||
export type Brands = BrandEdge[]
|
||||
|
||||
const getVendors = async (config: ShopifyConfig): Promise<BrandEdge[]> => {
|
||||
const getVendors = async (config: SwellConfig): Promise<BrandEdge[]> => {
|
||||
const vendors = await fetchAllProducts({
|
||||
config,
|
||||
query: getAllProductVendors,
|
||||
|
@@ -11,15 +11,16 @@ export async function getAsyncError(res: Response) {
|
||||
}
|
||||
|
||||
const handleFetchResponse = async (res: Response) => {
|
||||
if (res.ok) {
|
||||
const { data, errors } = await res.json()
|
||||
// if (res.ok) {
|
||||
// const { data, errors } = await res.json()
|
||||
|
||||
if (errors && errors.length) {
|
||||
throw getError(errors, res.status)
|
||||
}
|
||||
// if (errors && errors.length) {
|
||||
// throw getError(errors, res.status)
|
||||
// }
|
||||
|
||||
return data
|
||||
}
|
||||
// return data
|
||||
// }
|
||||
if (res) return res
|
||||
|
||||
throw await getAsyncError(res)
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Product } from '@commerce/types'
|
||||
import { Customer } from '@commerce/types'
|
||||
|
||||
import {
|
||||
Product as ShopifyProduct,
|
||||
@@ -11,7 +12,7 @@ import {
|
||||
ProductOption,
|
||||
} from '../schema'
|
||||
|
||||
import type { Cart, LineItem } from '../types'
|
||||
import type { Cart, LineItem, SwellCustomer } from '../types'
|
||||
|
||||
const money = ({ amount, currencyCode }: MoneyV2) => {
|
||||
return {
|
||||
@@ -121,6 +122,15 @@ export function normalizeCart(checkout: Checkout): Cart {
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeCustomer(customer: SwellCustomer): Customer {
|
||||
const { first_name: firstName, last_name: lastName } = customer
|
||||
return {
|
||||
...customer,
|
||||
firstName,
|
||||
lastName,
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeLineItem({
|
||||
node: { id, title, variant, quantity },
|
||||
}: CheckoutLineItemEdge): LineItem {
|
||||
|
Reference in New Issue
Block a user