mirror of
https://github.com/vercel/commerce.git
synced 2025-03-26 23:44:33 +00:00
* Packages Bump * Code Updated * More API Changes * Working updates * Updated Tailwind Config * SWR API updates * More changes * Commercejs Types * Commercejs Types * Commercejs Types
22 lines
694 B
TypeScript
22 lines
694 B
TypeScript
import { commerce } from '../../lib/commercejs'
|
|
import Commerce from '@chec/commerce.js'
|
|
|
|
type MethodKeys<T> = {
|
|
[K in keyof T]: T[K] extends (...args: any) => infer R ? K : never
|
|
}[keyof T]
|
|
|
|
// Calls the relevant Commerce.js SDK method based on resource and method arguments.
|
|
export default async function sdkFetch<
|
|
Resource extends keyof Commerce,
|
|
Method extends MethodKeys<Commerce[Resource]>
|
|
>(
|
|
resource: Resource,
|
|
method: Method,
|
|
...variables: Parameters<Commerce[Resource][Method] | any>
|
|
): Promise<ReturnType<Commerce[Resource][Method] | any>> {
|
|
//@ts-ignore
|
|
// Provider TODO: Fix types here.
|
|
const data = await commerce[resource][method](...variables)
|
|
return data
|
|
}
|