mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
* Add dynamic API endpoints * Add missing dependency * Update api handlers * Updates * Fix build errors * Update package.json * Add checkout endpoint parser & update errors * Update tsconfig.json * Update cart.ts * Update parser * Update errors.ts * Update errors.ts * Move to Edge runtime * Revert to local * Fix switchable runtimes * Make nodejs default runtime * Update pnpm-lock.yaml * Update handlers * Fix build errors * Change headers
26 lines
538 B
TypeScript
26 lines
538 B
TypeScript
import { Fetcher } from '@vercel/commerce/utils/types'
|
|
import { API_URL } from './const'
|
|
import { getToken, handleFetchResponse } from './utils'
|
|
|
|
const fetcher: Fetcher = async ({
|
|
url = API_URL,
|
|
method = 'POST',
|
|
variables,
|
|
query,
|
|
}) => {
|
|
const token = getToken()
|
|
|
|
return handleFetchResponse(
|
|
await fetch(url!, {
|
|
method,
|
|
body: JSON.stringify({ query, variables }),
|
|
headers: {
|
|
Authorization: `JWT ${token}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
)
|
|
}
|
|
|
|
export default fetcher
|