From 883fbcbcb941972b044227f03f3a88ce4b48521e Mon Sep 17 00:00:00 2001
From: Luis Alvarez <luis@vercel.com>
Date: Thu, 11 Feb 2021 13:35:17 -0500
Subject: [PATCH] Added a default fetcher

---
 framework/commerce/customer/use-customer.tsx | 10 ++--------
 framework/commerce/utils/default-fetcher.ts  | 12 ++++++++++++
 framework/commerce/wishlist/use-wishlist.tsx | 10 ++--------
 3 files changed, 16 insertions(+), 16 deletions(-)
 create mode 100644 framework/commerce/utils/default-fetcher.ts

diff --git a/framework/commerce/customer/use-customer.tsx b/framework/commerce/customer/use-customer.tsx
index f1675a544..4fb9b430b 100644
--- a/framework/commerce/customer/use-customer.tsx
+++ b/framework/commerce/customer/use-customer.tsx
@@ -5,6 +5,7 @@ import type {
   UseHookInput,
   UseHookResponse,
 } from '../utils/types'
+import defaultFetcher from '../utils/default-fetcher'
 import useData from '../utils/use-data-2'
 import { Provider, useCommerce } from '..'
 
@@ -27,14 +28,7 @@ export type UseCustomer<P extends Provider> = Partial<
   ? (input?: UseCustomerInput<P>) => CustomerResponse<P>
   : (input: UseCustomerInput<P>) => CustomerResponse<P>
 
-export const fetcher: HookFetcherFn<Customer | null> = async ({
-  options,
-  fetch,
-  normalize,
-}) => {
-  const data = await fetch({ ...options })
-  return data && normalize ? normalize(data) : data
-}
+export const fetcher = defaultFetcher as HookFetcherFn<Customer | null>
 
 export default function useCustomer<P extends Provider>(
   input: UseCustomerInput<P> = {}
diff --git a/framework/commerce/utils/default-fetcher.ts b/framework/commerce/utils/default-fetcher.ts
new file mode 100644
index 000000000..25211a689
--- /dev/null
+++ b/framework/commerce/utils/default-fetcher.ts
@@ -0,0 +1,12 @@
+import { HookFetcherFn } from './types'
+
+const defaultFetcher: HookFetcherFn<any> = async ({
+  options,
+  fetch,
+  normalize,
+}) => {
+  const data = await fetch({ ...options })
+  return data && normalize ? normalize(data) : data
+}
+
+export default defaultFetcher
diff --git a/framework/commerce/wishlist/use-wishlist.tsx b/framework/commerce/wishlist/use-wishlist.tsx
index 64bb5a1c1..314f0a1c2 100644
--- a/framework/commerce/wishlist/use-wishlist.tsx
+++ b/framework/commerce/wishlist/use-wishlist.tsx
@@ -5,6 +5,7 @@ import type {
   UseHookInput,
   UseHookResponse,
 } from '../utils/types'
+import defaultFetcher from '../utils/default-fetcher'
 import useData from '../utils/use-data-2'
 import { Provider, useCommerce } from '..'
 
@@ -27,14 +28,7 @@ export type UseWishlist<P extends Provider> = Partial<
   ? (input?: UseWishlistInput<P>) => WishlistResponse<P>
   : (input: UseWishlistInput<P>) => WishlistResponse<P>
 
-export const fetcher: HookFetcherFn<Wishlist | null> = async ({
-  options,
-  fetch,
-  normalize,
-}) => {
-  const data = await fetch({ ...options })
-  return data && normalize ? normalize(data) : data
-}
+export const fetcher = defaultFetcher as HookFetcherFn<Wishlist | null>
 
 export default function useWishlist<P extends Provider>(
   input: UseWishlistInput<P> = {}