Setup provider

This commit is contained in:
goncy
2021-08-25 11:13:17 -03:00
parent 0c2855a323
commit b64b3f8360
6 changed files with 47 additions and 14 deletions

View File

@@ -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)
}