mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
Setup provider
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { CommerceAPI, CommerceAPIConfig } from '@commerce/api'
|
||||
import { getCommerceApi as commerceApi } from '@commerce/api'
|
||||
import createFetcher from './utils/fetch-rest'
|
||||
import createFetcher from './utils/fetch'
|
||||
|
||||
import getAllPages from './operations/get-all-pages'
|
||||
import getPage from './operations/get-page'
|
||||
@@ -9,6 +9,7 @@ import getCustomerWishlist from './operations/get-customer-wishlist'
|
||||
import getAllProductPaths from './operations/get-all-product-paths'
|
||||
import getAllProducts from './operations/get-all-products'
|
||||
import getProduct from './operations/get-product'
|
||||
import { API_URL, CART_COOKIE, CUSTOMER_COOKIE } from '../constants'
|
||||
|
||||
export interface OrdercloudConfig extends Omit<CommerceAPIConfig, 'fetch'> {
|
||||
fetch: <T>(
|
||||
@@ -20,10 +21,10 @@ export interface OrdercloudConfig extends Omit<CommerceAPIConfig, 'fetch'> {
|
||||
}
|
||||
|
||||
const config: OrdercloudConfig = {
|
||||
commerceUrl: 'https://sandboxapi.ordercloud.io',
|
||||
commerceUrl: API_URL,
|
||||
apiToken: '',
|
||||
cartCookie: '',
|
||||
customerCookie: '',
|
||||
cartCookie: CART_COOKIE,
|
||||
customerCookie: CUSTOMER_COOKIE,
|
||||
cartCookieMaxAge: 2592000,
|
||||
fetch: createFetcher(() => getCommerceApi().getConfig()),
|
||||
}
|
||||
@@ -41,10 +42,10 @@ const operations = {
|
||||
export const provider = { config, operations }
|
||||
|
||||
export type Provider = typeof provider
|
||||
export type OrderCloudAPI<P extends Provider = Provider> = CommerceAPI<P | any>
|
||||
export type OrdercloudAPI<P extends Provider = Provider> = CommerceAPI<P | any>
|
||||
|
||||
export function getCommerceApi<P extends Provider>(
|
||||
customProvider: P = provider as any
|
||||
): OrderCloudAPI<P> {
|
||||
): OrdercloudAPI<P> {
|
||||
return commerceApi(customProvider as any)
|
||||
}
|
||||
|
Reference in New Issue
Block a user