mirror of
https://github.com/vercel/commerce.git
synced 2025-07-21 11:51:20 +00:00
* Update README.md to include information on how to add a custom provider (#250) * Update README.md * Updated commerce readme Co-authored-by: Luis Alvarez D <luis@vercel.com> * Remove unused provider config (#459) * Updated core types for commerce provider * Updated bigcommerce provider * Added util method for provider creation * Removed unrequired code from saleor * Updated shopify provider * Updated providers and local setup * Updated saleor setup * Updated swell * Updated vendure * Updated swell-js usage * Removed unrequired import from saleor Co-authored-by: Isiko Saidiali <54436062+SaidiAli@users.noreply.github.com> Co-authored-by: Luis Alvarez D <luis@vercel.com>
27 lines
790 B
TypeScript
27 lines
790 B
TypeScript
import { Fetcher } from '@commerce/utils/types'
|
|
import { CommerceError } from '@commerce/utils/errors'
|
|
import { handleFetchResponse } from './utils'
|
|
import swell from './swell'
|
|
|
|
const fetcher: Fetcher = async ({ method = 'get', variables, query }) => {
|
|
async function callSwell() {
|
|
if (Array.isArray(variables)) {
|
|
const arg1 = variables[0]
|
|
const arg2 = variables[1]
|
|
const response = await swell[query!][method](arg1, arg2)
|
|
return handleFetchResponse(response)
|
|
} else {
|
|
const response = await swell[query!][method](variables)
|
|
return handleFetchResponse(response)
|
|
}
|
|
}
|
|
|
|
if (query && query in swell) {
|
|
return await callSwell()
|
|
} else {
|
|
throw new CommerceError({ message: 'Invalid query argument!' })
|
|
}
|
|
}
|
|
|
|
export default fetcher
|