mirror of
https://github.com/vercel/commerce.git
synced 2025-04-02 02:05:52 +00:00
* Minimal list/detail views working with Vendure * Implement useCart/useAddItem * Implement useUpdateItem & useRemoveItem * Implement useSearch * Add operations codegen, tidy up * Dummy checkout page * Implement auth/customer hooks * Use env var for Shop API url * Add some documentation * Improve error handling * Optimize preview image size * Fix accidental change * Update Vendure provider to latest changes * Vendure provider: split out gql operations, remove unused files * Update Vendure provider readme * Add local next.config to Vendure provider, update docs * Update to use demo server * Fix build errors * Use proxy for vendure api * Simplify instructions in Vendure readme * Refactor Vendure checkout api handler * Improve image quality
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import type { CommerceAPIConfig } from '@commerce/api'
|
|
import fetchGraphqlApi from './utils/fetch-graphql-api'
|
|
|
|
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`
|
|
)
|
|
}
|
|
|
|
export class Config {
|
|
private config: VendureConfig
|
|
|
|
constructor(config: VendureConfig) {
|
|
this.config = {
|
|
...config,
|
|
}
|
|
}
|
|
|
|
getConfig(userConfig: Partial<VendureConfig> = {}) {
|
|
return Object.entries(userConfig).reduce<VendureConfig>(
|
|
(cfg, [key, value]) => Object.assign(cfg, { [key]: value }),
|
|
{ ...this.config }
|
|
)
|
|
}
|
|
|
|
setConfig(newConfig: Partial<VendureConfig>) {
|
|
Object.assign(this.config, newConfig)
|
|
}
|
|
}
|
|
|
|
const ONE_DAY = 60 * 60 * 24
|
|
const config = new Config({
|
|
commerceUrl: API_URL,
|
|
apiToken: '',
|
|
cartCookie: '',
|
|
customerCookie: '',
|
|
cartCookieMaxAge: ONE_DAY * 30,
|
|
fetch: fetchGraphqlApi,
|
|
})
|
|
|
|
export function getConfig(userConfig?: Partial<VendureConfig>) {
|
|
return config.getConfig(userConfig)
|
|
}
|
|
|
|
export function setConfig(newConfig: Partial<VendureConfig>) {
|
|
return config.setConfig(newConfig)
|
|
}
|