@automattic/calypso-products
Version:
This module contains information about the various products sold within calypso, such as product slugs, plan intervals, etc.
26 lines • 1.4 kB
JavaScript
import { JETPACK_PLAN_UPGRADE_MAP, JETPACK_PRODUCT_UPGRADE_MAP } from './constants';
import { getJetpackItemTermVariants } from './get-jetpack-item-term-variants';
import { isJetpackPlanSlug } from './is-jetpack-plan-slug';
import { isJetpackProductSlug } from './is-jetpack-product-slug';
import { planHasSuperiorFeature } from './main';
/**
* Check if a Jetpack item (product or plan) is superseding another one. Based on yearly variants.
* @param supersedingItem Item potentially superseding the other one
* @param supersededItem Item potentially superseded by the other one
* @returns True if the first item is superseding the second one
*/
export default function isSupersedingJetpackItem(supersedingItem, supersededItem) {
const yearlySuperseding = getJetpackItemTermVariants(supersedingItem)?.yearly;
const yearlySuperseded = getJetpackItemTermVariants(supersededItem)?.yearly;
if (!yearlySuperseding || !yearlySuperseded) {
return undefined;
}
if (isJetpackPlanSlug(yearlySuperseding)) {
return (JETPACK_PLAN_UPGRADE_MAP[yearlySuperseding]?.includes(yearlySuperseded) ||
planHasSuperiorFeature(supersedingItem, supersededItem));
}
if (isJetpackProductSlug(yearlySuperseding)) {
return JETPACK_PRODUCT_UPGRADE_MAP[yearlySuperseding]?.includes(yearlySuperseded);
}
}
//# sourceMappingURL=is-superseding-jetpack-item.js.map