forked from crowetic/commerce
Updated config
This commit is contained in:
parent
35ac41e04d
commit
5bd31d254d
@ -26,8 +26,11 @@ export type ProductImageVariables = Pick<
|
||||
| 'imgXLHeight'
|
||||
>;
|
||||
|
||||
export interface BigcommerceConfig extends CommerceAPIConfig {
|
||||
export interface BigcommerceConfigOptions extends CommerceAPIConfig {
|
||||
images?: Images;
|
||||
}
|
||||
|
||||
export interface BigcommerceConfig extends BigcommerceConfigOptions {
|
||||
readonly imageVariables?: ProductImageVariables;
|
||||
}
|
||||
|
||||
@ -46,31 +49,49 @@ if (!API_TOKEN) {
|
||||
);
|
||||
}
|
||||
|
||||
const config: BigcommerceConfig = {
|
||||
export class Config {
|
||||
private config: BigcommerceConfig;
|
||||
|
||||
constructor(config: BigcommerceConfigOptions) {
|
||||
this.config = {
|
||||
...config,
|
||||
get imageVariables() {
|
||||
const { images } = this;
|
||||
return images
|
||||
? {
|
||||
imgSmallWidth: images.small?.width,
|
||||
imgSmallHeight: images.small?.height,
|
||||
imgMediumWidth: images.medium?.height,
|
||||
imgMediumHeight: images.medium?.height,
|
||||
imgLargeWidth: images.large?.height,
|
||||
imgLargeHeight: images.large?.height,
|
||||
imgXLWidth: images.xl?.height,
|
||||
imgXLHeight: images.xl?.height,
|
||||
}
|
||||
: undefined;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
setConfig(newConfig: Partial<BigcommerceConfig>) {
|
||||
Object.assign(this.config, newConfig);
|
||||
}
|
||||
}
|
||||
|
||||
const config = new Config({
|
||||
commerceUrl: API_URL,
|
||||
apiToken: API_TOKEN,
|
||||
fetch: fetchAPI,
|
||||
get imageVariables() {
|
||||
const { images } = this;
|
||||
return images
|
||||
? {
|
||||
imgSmallWidth: images.small?.width,
|
||||
imgSmallHeight: images.small?.height,
|
||||
imgMediumWidth: images.medium?.height,
|
||||
imgMediumHeight: images.medium?.height,
|
||||
imgLargeWidth: images.large?.height,
|
||||
imgLargeHeight: images.large?.height,
|
||||
imgXLWidth: images.xl?.height,
|
||||
imgXLHeight: images.xl?.height,
|
||||
}
|
||||
: undefined;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export function getConfig() {
|
||||
return config;
|
||||
return config.getConfig();
|
||||
}
|
||||
|
||||
export function setConfig(newConfig: Partial<BigcommerceConfig>) {
|
||||
Object.assign(config, newConfig);
|
||||
return config.setConfig(newConfig);
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
import BigcommerceAPI from "./bigcommerce/api";
|
||||
|
||||
const API_URL = process.env.NEXT_EXAMPLE_BIGCOMMERCE_STOREFRONT_API_URL!;
|
||||
const API_TOKEN = process.env.NEXT_EXAMPLE_BIGCOMMERCE_STOREFRONT_API_TOKEN!;
|
||||
|
||||
export const commerce = new BigcommerceAPI({
|
||||
commerceUrl: API_URL,
|
||||
apiToken: API_TOKEN,
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user