mirror of
https://github.com/vercel/commerce.git
synced 2025-07-30 21:51:21 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
saleor
shopify
swell
vendure
api
endpoints
operations
utils
index.ts
auth
cart
customer
product
types
utils
wishlist
.env.template
README.md
codegen.json
commerce.config.json
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import type { APIProvider, CommerceAPIConfig } from '@commerce/api'
|
|
import { CommerceAPI, getCommerceApi as commerceApi } from '@commerce/api'
|
|
import fetchGraphqlApi from './utils/fetch-graphql-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 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'
|
|
|
|
export interface VendureConfig extends CommerceAPIConfig {}
|
|
|
|
const API_URL = process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL
|
|
|
|
if (!API_URL) {
|
|
throw new Error(
|
|
`The environment variable NEXT_PUBLIC_VENDURE_SHOP_API_URL is missing and it's required to access your store`
|
|
)
|
|
}
|
|
|
|
const ONE_DAY = 60 * 60 * 24
|
|
const config: VendureConfig = {
|
|
commerceUrl: API_URL,
|
|
apiToken: '',
|
|
cartCookie: '',
|
|
customerCookie: '',
|
|
cartCookieMaxAge: ONE_DAY * 30,
|
|
fetch: fetchGraphqlApi,
|
|
}
|
|
|
|
const operations = {
|
|
login,
|
|
getAllPages,
|
|
getPage,
|
|
getSiteInfo,
|
|
getCustomerWishlist,
|
|
getAllProductPaths,
|
|
getAllProducts,
|
|
getProduct,
|
|
}
|
|
|
|
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)
|
|
}
|