4
0
forked from crowetic/commerce

54 lines
1.3 KiB
TypeScript
Raw Normal View History

import {
CommerceAPI,
CommerceAPIConfig,
getCommerceApi as commerceApi,
} from '@commerce/api'
2021-03-02 21:05:13 -06:00
import {
2021-04-25 14:20:58 -05:00
SWELL_CHECKOUT_ID_COOKIE,
SWELL_CUSTOMER_TOKEN_COOKIE,
SWELL_COOKIE_EXPIRE,
2021-03-02 21:05:13 -06:00
} from '../const'
2021-05-13 16:10:09 +03:00
import fetchApi from './utils/fetch-swell-api'
import login from './operations/login'
import getAllPages from './operations/get-all-pages'
import getPage from './operations/get-page'
import getSiteInfo from './operations/get-site-info'
import getAllProductPaths from './operations/get-all-product-paths'
import getAllProducts from './operations/get-all-products'
import getProduct from './operations/get-product'
2021-03-02 21:05:13 -06:00
2021-03-29 17:05:20 -06:00
export interface SwellConfig extends CommerceAPIConfig {
2021-05-13 16:10:09 +03:00
fetch: any
2021-03-29 17:05:20 -06:00
}
2021-03-02 21:05:13 -06:00
const config: SwellConfig = {
2021-03-02 21:05:13 -06:00
locale: 'en-US',
2021-04-25 14:20:58 -05:00
commerceUrl: '',
apiToken: ''!,
cartCookie: SWELL_CHECKOUT_ID_COOKIE,
cartCookieMaxAge: SWELL_COOKIE_EXPIRE,
2021-05-13 16:10:09 +03:00
fetch: fetchApi,
2021-04-25 14:20:58 -05:00
customerCookie: SWELL_CUSTOMER_TOKEN_COOKIE,
}
2021-03-02 21:05:13 -06:00
const operations = {
login,
getAllPages,
getPage,
getSiteInfo,
getAllProductPaths,
getAllProducts,
getProduct,
2021-03-02 21:05:13 -06:00
}
export const provider = { config, operations }
export type Provider = typeof provider
export function getCommerceApi<P extends Provider>(
customProvider: P = provider as any
): CommerceAPI<P> {
return commerceApi(customProvider)
2021-03-02 21:05:13 -06:00
}