import type { HookFetcher } from '@lib/commerce/utils/types' import type { SwrOptions } from '@lib/commerce/utils/use-data' import useCommerceCustomer from '@lib/commerce/use-customer' import type { Customer, CustomerData } from './api/customers' const defaultOpts = { url: '/api/bigcommerce/customers', method: 'GET', } export type { Customer } export const fetcher: HookFetcher = async ( options, _, fetch ) => { const data = await fetch({ ...defaultOpts, ...options }) return data?.customer ?? null } export function extendHook( customFetcher: typeof fetcher, swrOptions?: SwrOptions ) { const useCustomer = () => { return useCommerceCustomer(defaultOpts, [], customFetcher, { revalidateOnFocus: false, ...swrOptions, }) } useCustomer.extend = extendHook return useCustomer } export default extendHook(fetcher)