flags(marketplace): 🚩 Add feature flag definitions to control marketplace functionality
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
b6211d1c55
commit
a3e899102e
1 changed files with 22 additions and 7 deletions
|
|
@ -6,7 +6,20 @@
|
|||
* to show only brand-relevant features.
|
||||
*/
|
||||
|
||||
import type { VerticalConfig } from './verticals.config';
|
||||
/** Minimal interface for feature flag resolution — allows any config shape with a features property */
|
||||
export interface WithMarketplaceFeatures {
|
||||
features: {
|
||||
showPricing?: boolean;
|
||||
showBooking?: boolean;
|
||||
showStreaming?: boolean;
|
||||
showMessaging?: boolean;
|
||||
showVerification?: boolean;
|
||||
showAvailability?: boolean;
|
||||
showGallery?: boolean;
|
||||
showReviews?: boolean;
|
||||
[key: string]: boolean | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
/** All marketplace feature IDs */
|
||||
export const MARKETPLACE_FEATURE_IDS = [
|
||||
|
|
@ -44,8 +57,8 @@ const ALWAYS_VISIBLE_FEATURES: readonly MarketplaceFeatureId[] = [
|
|||
'multi-brand',
|
||||
];
|
||||
|
||||
/** Map from feature ID to the VerticalConfig.features flag that controls it */
|
||||
const FEATURE_FLAG_MAP: Partial<Record<MarketplaceFeatureId, keyof VerticalConfig['features']>> = {
|
||||
/** Map from feature ID to the features flag that controls it */
|
||||
const FEATURE_FLAG_MAP: Partial<Record<MarketplaceFeatureId, keyof WithMarketplaceFeatures['features']>> = {
|
||||
pricing: 'showPricing',
|
||||
booking: 'showBooking',
|
||||
streaming: 'showStreaming',
|
||||
|
|
@ -60,14 +73,16 @@ const FEATURE_FLAG_MAP: Partial<Record<MarketplaceFeatureId, keyof VerticalConfi
|
|||
* Get the list of marketplace features visible for a given vertical.
|
||||
* Returns always-visible features + flag-filtered features based on vertical config.
|
||||
*
|
||||
* @param verticalConfig - The brand's vertical configuration
|
||||
* Accepts any config object with a `features` property (Interface Segregation).
|
||||
*
|
||||
* @param verticalConfig - Any config object with a features property
|
||||
* @param audience - Optional audience filter (not currently used, reserved for future)
|
||||
*/
|
||||
export function getMarketplaceFeaturesForVertical(
|
||||
verticalConfig: VerticalConfig,
|
||||
verticalConfig: WithMarketplaceFeatures,
|
||||
_audience?: 'worker' | 'client',
|
||||
): MarketplaceFeatureId[] {
|
||||
const flagBased = (Object.entries(FEATURE_FLAG_MAP) as [MarketplaceFeatureId, keyof VerticalConfig['features']][])
|
||||
const flagBased = (Object.entries(FEATURE_FLAG_MAP) as [MarketplaceFeatureId, keyof WithMarketplaceFeatures['features']][])
|
||||
.filter(([, flag]) => verticalConfig.features[flag])
|
||||
.map(([featureId]) => featureId);
|
||||
|
||||
|
|
@ -79,7 +94,7 @@ export function getMarketplaceFeaturesForVertical(
|
|||
*/
|
||||
export function isFeatureValidForVertical(
|
||||
featureId: string,
|
||||
verticalConfig: VerticalConfig,
|
||||
verticalConfig: WithMarketplaceFeatures,
|
||||
): featureId is MarketplaceFeatureId {
|
||||
const validFeatures = getMarketplaceFeaturesForVertical(verticalConfig);
|
||||
return validFeatures.includes(featureId as MarketplaceFeatureId);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue