mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Merge branch 'agnostic' of https://github.com/vercel/commerce into agnostic
This commit is contained in:
5
framework/bigcommerce/config.json
Normal file
5
framework/bigcommerce/config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"features": {
|
||||
"wishlist": false
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import { HookHandler } from '@commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@commerce/products/use-search'
|
||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||
import type { SearchProductsData } from '../api/catalog/products'
|
||||
import type { BigcommerceProvider } from '..'
|
||||
|
||||
|
5
framework/commerce/config.json
Normal file
5
framework/commerce/config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"features": {
|
||||
"wishlist": true
|
||||
}
|
||||
}
|
@@ -2,6 +2,10 @@ import type { Wishlist as BCWishlist } from '@framework/api/wishlist'
|
||||
import type { Customer as BCCustomer } from '@framework/api/customers'
|
||||
import type { SearchProductsData as BCSearchProductsData } from '@framework/api/catalog/products'
|
||||
|
||||
export type CommerceProviderConfig = {
|
||||
features: Record<string, boolean>
|
||||
}
|
||||
|
||||
export type Discount = {
|
||||
// The value of the discount, can be an amount or percentage
|
||||
value: number
|
||||
|
37
framework/commerce/utils/features.ts
Normal file
37
framework/commerce/utils/features.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import commerceProviderConfig from '@framework/config.json'
|
||||
import type { CommerceProviderConfig } from '../types'
|
||||
import memo from 'lodash.memoize'
|
||||
|
||||
type FeaturesAPI = {
|
||||
isEnabled: (desideredFeature: string) => boolean
|
||||
}
|
||||
|
||||
function isFeatureEnabled(config: CommerceProviderConfig) {
|
||||
const features = config.features
|
||||
return (desideredFeature: string) =>
|
||||
Object.keys(features)
|
||||
.filter((k) => features[k])
|
||||
.includes(desideredFeature)
|
||||
}
|
||||
|
||||
function boostrap(): FeaturesAPI {
|
||||
const basis = {
|
||||
isEnabled: () => false,
|
||||
}
|
||||
|
||||
if (!commerceProviderConfig) {
|
||||
console.log('No config.json found - Please add a config.json')
|
||||
return basis
|
||||
}
|
||||
|
||||
if (commerceProviderConfig.features) {
|
||||
return {
|
||||
...basis,
|
||||
isEnabled: memo(isFeatureEnabled(commerceProviderConfig)),
|
||||
}
|
||||
}
|
||||
|
||||
return basis
|
||||
}
|
||||
|
||||
export default boostrap()
|
Reference in New Issue
Block a user