import type { HookFetcher } from '@commerce/utils/types' import type { SwrOptions } from '@commerce/utils/use-data' import useCommerceCustomer from '@commerce/use-customer' const defaultOpts = { query: '/api/bigcommerce/customers', } 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)