mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Removed features.ts
This commit is contained in:
@@ -2,12 +2,6 @@ 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 Features = 'wishlist' | 'checkout' | string
|
||||
|
||||
export type CommerceProviderConfig = {
|
||||
features: Record<Features, boolean>
|
||||
}
|
||||
|
||||
export type Discount = {
|
||||
// The value of the discount, can be an amount or percentage
|
||||
value: number
|
||||
|
@@ -1,47 +0,0 @@
|
||||
import commerceProviderConfig from '../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)
|
||||
}
|
||||
|
||||
export function toEnvConfig(
|
||||
configMap: CommerceProviderConfig['features']
|
||||
): Map<string, boolean> {
|
||||
let toEnvConfigMap = new Map<string, boolean>()
|
||||
Object.keys(configMap).map((r) =>
|
||||
toEnvConfigMap.set(`${r.toUpperCase()}_ENABLED`, configMap[r])
|
||||
)
|
||||
return toEnvConfigMap
|
||||
}
|
||||
|
||||
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