mirror of
https://github.com/vercel/commerce.git
synced 2025-06-13 03:11:22 +00:00
* Update product types * Cart types progress, add zod & initial schema validator * Update normalize.ts * Update with-schema-parser.ts * Updated types, schemas & providers * Fix providers after schema parse errors * Fix paths * More provider fixes * Fix kibocommerce & commercejs * Add customer updated types & fixes * Add checkout & customer types * Import core types only from commerce * Update tsconfig.json * Convert hooks interfaces to types * Requested changes * Change to relative paths * Move Zod dependency
33 lines
797 B
TypeScript
33 lines
797 B
TypeScript
import type { SWRHook } from '@vercel/commerce/utils/types'
|
|
import type { CustomerHook } from '@vercel/commerce/types/customer'
|
|
|
|
import useCustomer, {
|
|
type UseCustomer,
|
|
} from '@vercel/commerce/customer/use-customer'
|
|
import { normalizeCustomer } from '../utils/normalize'
|
|
|
|
export default useCustomer as UseCustomer<typeof handler>
|
|
|
|
export const handler: SWRHook<CustomerHook> = {
|
|
fetchOptions: {
|
|
query: 'account',
|
|
method: 'get',
|
|
},
|
|
async fetcher({ options, fetch }) {
|
|
const data = await fetch<any | null>({
|
|
...options,
|
|
})
|
|
return data ? normalizeCustomer(data) : null
|
|
},
|
|
useHook:
|
|
({ useData }) =>
|
|
(input) => {
|
|
return useData({
|
|
swrOptions: {
|
|
revalidateOnFocus: false,
|
|
...input?.swrOptions,
|
|
},
|
|
})
|
|
},
|
|
}
|