@automattic/calypso-products
Version:
This module contains information about the various products sold within calypso, such as product slugs, plan intervals, etc.
805 lines • 31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPlanFeaturesObject = exports.planHasJetpackSearch = exports.chooseDefaultCustomerType = exports.getPopularPlanSpec = void 0;
exports.getPlans = getPlans;
exports.getSimplifiedPlanFeaturesGroupedForFeaturesGrid = getSimplifiedPlanFeaturesGroupedForFeaturesGrid;
exports.getPlanFeaturesGroupedForFeaturesGrid = getPlanFeaturesGroupedForFeaturesGrid;
exports.getPlanFeaturesGroupedForComparisonGrid = getPlanFeaturesGroupedForComparisonGrid;
exports.getWooExpressFeaturesGroupedForFeaturesGrid = getWooExpressFeaturesGroupedForFeaturesGrid;
exports.getWordPressHostingFeaturesGroupedForFeaturesGrid = getWordPressHostingFeaturesGroupedForFeaturesGrid;
exports.getWooExpressFeaturesGroupedForComparisonGrid = getWooExpressFeaturesGroupedForComparisonGrid;
exports.getWooHostedFeaturesGroupedForFeaturesGrid = getWooHostedFeaturesGroupedForFeaturesGrid;
exports.getWooHostedFeaturesGroupedForComparisonGrid = getWooHostedFeaturesGroupedForComparisonGrid;
exports.getPlansSlugs = getPlansSlugs;
exports.getPlan = getPlan;
exports.getPlanClass = getPlanClass;
exports.planHasFeature = planHasFeature;
exports.planHasAtLeastOneFeature = planHasAtLeastOneFeature;
exports.getAllFeaturesForPlan = getAllFeaturesForPlan;
exports.planHasSuperiorFeature = planHasSuperiorFeature;
exports.shouldFetchSitePlans = shouldFetchSitePlans;
exports.getMonthlyPlanByYearly = getMonthlyPlanByYearly;
exports.getYearlyPlanByMonthly = getYearlyPlanByMonthly;
exports.planLevelsMatch = planLevelsMatch;
exports.isEcommercePlan = isEcommercePlan;
exports.isProPlan = isProPlan;
exports.isBusinessPlan = isBusinessPlan;
exports.isPremiumPlan = isPremiumPlan;
exports.isPersonalPlan = isPersonalPlan;
exports.isStudentPlan = isStudentPlan;
exports.isBloggerPlan = isBloggerPlan;
exports.isFreePlan = isFreePlan;
exports.isFreeHostingTrial = isFreeHostingTrial;
exports.isBusinessTrial = isBusinessTrial;
exports.is100YearPlan = is100YearPlan;
exports.isWpcomEnterpriseGridPlan = isWpcomEnterpriseGridPlan;
exports.isWooExpressPlusPlan = isWooExpressPlusPlan;
exports.isWooExpressMediumPlan = isWooExpressMediumPlan;
exports.isWooExpressSmallPlan = isWooExpressSmallPlan;
exports.isWooExpressPlan = isWooExpressPlan;
exports.isWooHostedFreePlan = isWooHostedFreePlan;
exports.isWooHostedBasicPlan = isWooHostedBasicPlan;
exports.isWooHostedProPlan = isWooHostedProPlan;
exports.isWooHostedPlan = isWooHostedPlan;
exports.isFlexiblePlan = isFlexiblePlan;
exports.isStarterPlan = isStarterPlan;
exports.isJetpackStarterPlan = isJetpackStarterPlan;
exports.isJetpackGrowthPlan = isJetpackGrowthPlan;
exports.isSecurityDailyPlan = isSecurityDailyPlan;
exports.isSecurityRealTimePlan = isSecurityRealTimePlan;
exports.isSecurityT0Plan = isSecurityT0Plan;
exports.isSecurityT1Plan = isSecurityT1Plan;
exports.isSecurityT2Plan = isSecurityT2Plan;
exports.isCompletePlan = isCompletePlan;
exports.isWpComPlan = isWpComPlan;
exports.isWpComBusinessPlan = isWpComBusinessPlan;
exports.isWpComEcommercePlan = isWpComEcommercePlan;
exports.isWpComProPlan = isWpComProPlan;
exports.isWpComPremiumPlan = isWpComPremiumPlan;
exports.isWpComPersonalPlan = isWpComPersonalPlan;
exports.isWpComStudentPlan = isWpComStudentPlan;
exports.isWpComBloggerPlan = isWpComBloggerPlan;
exports.isWpComFreePlan = isWpComFreePlan;
exports.isWpComAnnualPlan = isWpComAnnualPlan;
exports.isWpComBiennialPlan = isWpComBiennialPlan;
exports.isWpComTriennialPlan = isWpComTriennialPlan;
exports.isWpComMonthlyPlan = isWpComMonthlyPlan;
exports.isJetpackBusinessPlan = isJetpackBusinessPlan;
exports.isJetpackPremiumPlan = isJetpackPremiumPlan;
exports.isJetpackPersonalPlan = isJetpackPersonalPlan;
exports.isJetpackFreePlan = isJetpackFreePlan;
exports.isP2FreePlan = isP2FreePlan;
exports.isP2PlusPlan = isP2PlusPlan;
exports.findFirstSimilarPlanKey = findFirstSimilarPlanKey;
exports.findSimilarPlansKeys = findSimilarPlansKeys;
exports.findPlansKeys = findPlansKeys;
exports.planMatches = planMatches;
exports.calculateMonthlyPriceForPlan = calculateMonthlyPriceForPlan;
exports.calculateMonthlyPrice = calculateMonthlyPrice;
exports.getBillingMonthsForTerm = getBillingMonthsForTerm;
exports.getBillingTermForMonths = getBillingTermForMonths;
exports.plansLink = plansLink;
exports.applyTestFiltersToPlansList = applyTestFiltersToPlansList;
exports.getPlanTermLabel = getPlanTermLabel;
exports.getFeaturesList = getFeaturesList;
exports.isValidFeatureKey = isValidFeatureKey;
exports.getFeatureByKey = getFeatureByKey;
exports.getFeatureDifference = getFeatureDifference;
const constants_1 = require("./constants");
const feature_group_plan_map_1 = require("./feature-group-plan-map");
const features_list_1 = require("./features-list");
const plans_list_1 = require("./plans-list");
function getPlans() {
return plans_list_1.PLANS_LIST;
}
function getSimplifiedPlanFeaturesGroupedForFeaturesGrid() {
return (0, feature_group_plan_map_1.resolveFeatureGroupsForFeaturesGrid)({
showSimplifiedFeatures: true,
});
}
function getPlanFeaturesGroupedForFeaturesGrid() {
return (0, feature_group_plan_map_1.resolveFeatureGroupsForFeaturesGrid)();
}
function getPlanFeaturesGroupedForComparisonGrid(props) {
return (0, feature_group_plan_map_1.resolveFeatureGroupsForComparisonGrid)(props);
}
function getWooExpressFeaturesGroupedForFeaturesGrid() {
// Same as getPlanFeaturesGroupedForFeaturesGrid() for now
return getPlanFeaturesGroupedForFeaturesGrid();
}
function getWordPressHostingFeaturesGroupedForFeaturesGrid() {
return (0, feature_group_plan_map_1.resolveWordPressHostingFeatureGroupsForFeaturesGrid)();
}
function getWooExpressFeaturesGroupedForComparisonGrid() {
return (0, feature_group_plan_map_1.resolveWooExpressFeatureGroupsForComparisonGrid)();
}
function getWooHostedFeaturesGroupedForFeaturesGrid() {
return (0, feature_group_plan_map_1.resolveWooHostedFeatureGroupsForFeaturesGrid)();
}
function getWooHostedFeaturesGroupedForComparisonGrid() {
return (0, feature_group_plan_map_1.resolveWooHostedFeatureGroupsForComparisonGrid)();
}
function getPlansSlugs() {
return Object.keys(getPlans());
}
function getPlan(planKey) {
if (typeof planKey !== 'string') {
if (Object.values(plans_list_1.PLANS_LIST).includes(planKey)) {
return planKey;
}
return undefined;
}
return plans_list_1.PLANS_LIST[planKey];
}
function getPlanClass(planKey) {
if (isFreePlan(planKey)) {
return 'is-free-plan';
}
if (isFlexiblePlan(planKey)) {
return 'is-flexible-plan';
}
if (isBloggerPlan(planKey)) {
return 'is-blogger-plan';
}
if (isPersonalPlan(planKey)) {
return 'is-personal-plan';
}
if (isStudentPlan(planKey)) {
return 'is-student-plan';
}
if (isPremiumPlan(planKey)) {
return 'is-premium-plan';
}
if (isBusinessPlan(planKey)) {
return 'is-business-plan';
}
if (isWooExpressPlusPlan(planKey)) {
return 'is-wooexpress-plus-plan';
}
if (isWooExpressMediumPlan(planKey)) {
return 'is-wooexpress-medium-plan';
}
if (isWooExpressSmallPlan(planKey)) {
return 'is-wooexpress-small-plan';
}
if (isEcommercePlan(planKey)) {
return 'is-ecommerce-plan';
}
if (isWooHostedFreePlan(planKey)) {
return 'is-woo-hosted-trial';
}
if (isWooHostedBasicPlan(planKey)) {
return 'is-woo-hosted-basic-plan';
}
if (isWooHostedProPlan(planKey)) {
return 'is-woo-hosted-pro-plan';
}
if (isWpcomEnterpriseGridPlan(planKey)) {
return 'is-wpcom-enterprise-grid-plan';
}
if (isProPlan(planKey)) {
return 'is-pro-plan';
}
if (isSecurityDailyPlan(planKey)) {
return 'is-daily-security-plan';
}
if (isSecurityRealTimePlan(planKey)) {
return 'is-realtime-security-plan';
}
if (isSecurityT0Plan(planKey)) {
return 'is-security-t0';
}
if (isSecurityT1Plan(planKey)) {
return 'is-security-t1';
}
if (isSecurityT2Plan(planKey)) {
return 'is-security-t2';
}
if (isCompletePlan(planKey)) {
return 'is-complete-plan';
}
if (isJetpackGrowthPlan(planKey)) {
return 'is-jetpack-growth-plan';
}
if (isFreeHostingTrial(planKey)) {
return 'is-free-hosting-trial';
}
if (isP2PlusPlan(planKey)) {
return 'is-p2-plus-plan';
}
return '';
}
/**
* Determines if a plan has a specific feature.
*
* Collects features for a plan by calling all possible feature methods for the plan.
*/
function planHasFeature(plan, feature) {
const allFeatures = getAllFeaturesForPlan(plan);
return allFeatures.includes(feature);
}
/**
* Determine if a plan has at least one of several features.
*/
function planHasAtLeastOneFeature(plan, features) {
const allFeatures = getAllFeaturesForPlan(plan);
return features.some((feature) => allFeatures.includes(feature));
}
/**
* Get all features for a plan
*
* Collects features for a plan by calling all possible feature methods for the plan.
*
* Returns an array of all the plan features (may have duplicates)
*/
function getAllFeaturesForPlan(plan) {
const planObj = getPlan(plan);
if (!planObj) {
return [];
}
return [
...('getPlanCompareFeatures' in planObj && planObj.getPlanCompareFeatures
? planObj.getPlanCompareFeatures()
: []),
...('getPromotedFeatures' in planObj && planObj.getPromotedFeatures
? planObj.getPromotedFeatures()
: []),
...('getSignupFeatures' in planObj && planObj.getSignupFeatures
? planObj.getSignupFeatures()
: []),
...('getSignupCompareAvailableFeatures' in planObj && planObj.getSignupCompareAvailableFeatures
? planObj.getSignupCompareAvailableFeatures()
: []),
...('getBlogSignupFeatures' in planObj && planObj.getBlogSignupFeatures
? planObj.getBlogSignupFeatures()
: []),
...('getPortfolioSignupFeatures' in planObj && planObj.getPortfolioSignupFeatures
? planObj.getPortfolioSignupFeatures()
: []),
...('getIncludedFeatures' in planObj && planObj.getIncludedFeatures
? planObj.getIncludedFeatures()
: []),
];
}
/**
* Determines if a plan has a superior version of a specific feature.
*/
function planHasSuperiorFeature(plan, feature) {
const planConstantObj = getPlan(plan);
const features = planConstantObj?.getInferiorFeatures?.() ?? [];
return features.includes(feature);
}
function shouldFetchSitePlans(sitePlans) {
return !sitePlans.hasLoadedFromServer && !sitePlans.isRequesting;
}
/**
* Returns the monthly slug which corresponds to the provided yearly slug or "" if the slug is
* not a recognized or cannot be converted.
*/
function getMonthlyPlanByYearly(planSlug) {
const plan = getPlan(planSlug);
if (plan && 'getMonthlySlug' in plan && plan.getMonthlySlug) {
return plan.getMonthlySlug();
}
return findFirstSimilarPlanKey(planSlug, { term: constants_1.TERM_MONTHLY }) || '';
}
/**
* Returns the yearly slug which corresponds to the provided monthly slug or "" if the slug is
* not a recognized or cannot be converted.
*/
function getYearlyPlanByMonthly(planSlug) {
const plan = getPlan(planSlug);
if (plan && 'getAnnualSlug' in plan && plan.getAnnualSlug) {
return plan.getAnnualSlug();
}
return findFirstSimilarPlanKey(planSlug, { term: constants_1.TERM_ANNUALLY }) || '';
}
/**
* Returns true if plan "types" match regardless of their interval.
*
* For example (fake plans):
* planLevelsMatch( PRO_YEARLY, PRO_YEARLY ) => true
* planLevelsMatch( PRO_YEARLY, PRO_MONTHLY ) => true
* planLevelsMatch( PRO_YEARLY, PERSONAL_YEARLY ) => false
*/
function planLevelsMatch(planSlugA, planSlugB) {
const planA = getPlan(planSlugA);
const planB = getPlan(planSlugB);
return Boolean(planA && planB && planA.type === planB.type && planA.group === planB.group);
}
function isEcommercePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_ECOMMERCE });
}
function isProPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_PRO });
}
function isBusinessPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_BUSINESS });
}
function isPremiumPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_PREMIUM });
}
function isPersonalPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_PERSONAL });
}
function isStudentPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_STUDENT });
}
function isBloggerPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_BLOGGER });
}
function isFreePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_FREE });
}
function isFreeHostingTrial(planSlug) {
return planSlug === constants_1.PLAN_HOSTING_TRIAL_MONTHLY;
}
function isBusinessTrial(planSlug) {
return planSlug === constants_1.PLAN_HOSTING_TRIAL_MONTHLY || planSlug === constants_1.PLAN_MIGRATION_TRIAL_MONTHLY;
}
function is100YearPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_100_YEAR });
}
// Checks if it is an Enterprise plan (a.k.a VIP), introduced as part of pdgrnI-1Qp-p2.
// This is not a real plan, but added to display Enterprise in the pricing grid.
function isWpcomEnterpriseGridPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_ENTERPRISE_GRID_WPCOM, group: constants_1.GROUP_WPCOM });
}
function isWooExpressPlusPlan(planSlug) {
return constants_1.PLAN_WOOEXPRESS_PLUS === planSlug;
}
function isWooExpressMediumPlan(planSlug) {
return [constants_1.PLAN_WOOEXPRESS_MEDIUM, constants_1.PLAN_WOOEXPRESS_MEDIUM_MONTHLY].includes(planSlug);
}
function isWooExpressSmallPlan(planSlug) {
return [constants_1.PLAN_WOOEXPRESS_SMALL, constants_1.PLAN_WOOEXPRESS_SMALL_MONTHLY].includes(planSlug);
}
function isWooExpressPlan(planSlug) {
return constants_1.WOO_EXPRESS_PLANS.includes(planSlug);
}
function isWooHostedFreePlan(planSlug) {
return [constants_1.PLAN_WOO_HOSTED_FREE, constants_1.PLAN_WOO_HOSTED_FREE_TRIAL_MONTHLY].includes(planSlug);
}
function isWooHostedBasicPlan(planSlug) {
return [constants_1.PLAN_WOO_HOSTED_BASIC, constants_1.PLAN_WOO_HOSTED_BASIC_MONTHLY].includes(planSlug);
}
function isWooHostedProPlan(planSlug) {
return [constants_1.PLAN_WOO_HOSTED_PRO, constants_1.PLAN_WOO_HOSTED_PRO_MONTHLY].includes(planSlug);
}
function isWooHostedPlan(planSlug) {
return constants_1.WOO_HOSTED_PLANS.includes(planSlug);
}
function isFlexiblePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_FLEXIBLE });
}
function isStarterPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_STARTER });
}
function isJetpackStarterPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_JETPACK_STARTER });
}
function isJetpackGrowthPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_JETPACK_GROWTH });
}
function isSecurityDailyPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_SECURITY_DAILY });
}
function isSecurityRealTimePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_SECURITY_REALTIME });
}
function isSecurityT0Plan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_SECURITY_T0 });
}
function isSecurityT1Plan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_SECURITY_T1 });
}
function isSecurityT2Plan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_SECURITY_T2 });
}
function isCompletePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_ALL });
}
function isWpComPlan(planSlug) {
return planMatches(planSlug, { group: constants_1.GROUP_WPCOM });
}
function isWpComBusinessPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_BUSINESS, group: constants_1.GROUP_WPCOM });
}
function isWpComEcommercePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_ECOMMERCE, group: constants_1.GROUP_WPCOM });
}
function isWpComProPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_PRO, group: constants_1.GROUP_WPCOM });
}
function isWpComPremiumPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_PREMIUM, group: constants_1.GROUP_WPCOM });
}
function isWpComPersonalPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_PERSONAL, group: constants_1.GROUP_WPCOM });
}
function isWpComStudentPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_STUDENT, group: constants_1.GROUP_WPCOM });
}
function isWpComBloggerPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_BLOGGER, group: constants_1.GROUP_WPCOM });
}
function isWpComFreePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_FREE, group: constants_1.GROUP_WPCOM });
}
function isWpComAnnualPlan(planSlug) {
return planMatches(planSlug, { term: constants_1.TERM_ANNUALLY, group: constants_1.GROUP_WPCOM });
}
function isWpComBiennialPlan(planSlug) {
return planMatches(planSlug, { term: constants_1.TERM_BIENNIALLY, group: constants_1.GROUP_WPCOM });
}
function isWpComTriennialPlan(planSlug) {
return planMatches(planSlug, { term: constants_1.TERM_TRIENNIALLY, group: constants_1.GROUP_WPCOM });
}
function isWpComMonthlyPlan(planSlug) {
return planMatches(planSlug, { term: constants_1.TERM_MONTHLY, group: constants_1.GROUP_WPCOM });
}
function isJetpackBusinessPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_BUSINESS, group: constants_1.GROUP_JETPACK });
}
function isJetpackPremiumPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_PREMIUM, group: constants_1.GROUP_JETPACK });
}
function isJetpackPersonalPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_PERSONAL, group: constants_1.GROUP_JETPACK });
}
function isJetpackFreePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_FREE, group: constants_1.GROUP_JETPACK });
}
function isP2FreePlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_FREE, group: constants_1.GROUP_P2 });
}
function isP2PlusPlan(planSlug) {
return planMatches(planSlug, { type: constants_1.TYPE_P2_PLUS });
}
function findFirstSimilarPlanKey(planKey, diff) {
return findSimilarPlansKeys(planKey, diff)[0];
}
/**
* A similar plan is one that has the same `type`, `group`, and `term` as first
* argument, except for differences specified in the second argument.
*
* For example:
*
* > findSimilarPlansKeys( TYPE_BUSINESS, { term: TERM_BIENNIALLY } );
* [PLAN_BUSINESS_2_YEARS]
* > findSimilarPlansKeys( TYPE_JETPACK_BUSINESS_MONTHLY, { type: TYPE_ANNUALLY } );
* [TYPE_JETPACK_BUSINESS]
*
* Note: A4A plans are excluded from similar plan lookups.
*/
function findSimilarPlansKeys(planKey, diff = {}) {
const plan = getPlan(planKey);
// @TODO: make getPlan() throw an error on failure. This is going to be a larger change with a separate PR.
if (!plan) {
return [];
}
const similarPlans = findPlansKeys({
type: plan.type,
group: plan.group,
term: plan.term,
...diff,
});
// Filter out A4A plans
return similarPlans.filter((slug) => slug !== constants_1.PLAN_A4A_BUSINESS && slug !== constants_1.PLAN_A4A_BUSINESS_MONTHLY);
}
/**
* Finds all keys of plans matching a query
*
* For example:
*
* > findPlansKeys( { term: TERM_BIENNIALLY } );
* [PLAN_PERSONAL_2_YEARS, PLAN_PREMIUM_2_YEARS, PLAN_BUSINESS_2_YEARS]
*/
function findPlansKeys(query = {}) {
const plans = getPlans();
return Object.keys(plans).filter((k) => planMatches(plans[k], query));
}
/**
* Matches plan specified by `planKey` against `query`.
* Only compares `type`, `group`, and `term` properties.
*
* For example:
*
* > planMatches( TYPE_BUSINESS, { term: TERM_ANNUALLY, group: GROUP_WPCOM, type: TYPE_BUSINESS } );
* true
*
* > planMatches( TYPE_BUSINESS, { term: TERM_BIENNIALLY } );
* false
*/
function planMatches(planKey, query = {}) {
const acceptedKeys = ['type', 'group', 'term'];
const unknownKeys = Object.keys(query).filter((key) => !acceptedKeys.includes(key));
if (unknownKeys.length) {
throw new Error(`planMatches can only match against ${acceptedKeys.join(',')}, ` +
`but unknown keys ${unknownKeys.join(',')} were passed.`);
}
// @TODO: make getPlan() throw an error on failure. This is going to be a larger change with a separate PR.
const plan = getPlan(planKey);
if (!plan) {
return false;
}
if ((!('type' in query) || plan.type === query.type) &&
(!('group' in query) || plan.group === query.group) &&
(!('term' in query) || plan.term === query.term)) {
return true;
}
return false;
}
function calculateMonthlyPriceForPlan(planSlug, termPrice) {
const plan = getPlan(planSlug);
if (!plan) {
throw new Error(`Unknown plan: ${planSlug}`);
}
return calculateMonthlyPrice(plan.term, termPrice);
}
function calculateMonthlyPrice(term, termPrice) {
const divisor = getBillingMonthsForTerm(term);
return parseFloat((termPrice / divisor).toFixed(2));
}
function getBillingMonthsForTerm(term) {
if (term === constants_1.TERM_MONTHLY) {
return 1;
}
else if (term === constants_1.TERM_ANNUALLY) {
return 12;
}
else if (term === constants_1.TERM_BIENNIALLY) {
return 24;
}
else if (term === constants_1.TERM_TRIENNIALLY) {
return 36;
}
else if (term === constants_1.TERM_QUADRENNIALLY) {
return 48;
}
else if (term === constants_1.TERM_QUINQUENNIALLY) {
return 60;
}
else if (term === constants_1.TERM_SEXENNIALLY) {
return 72;
}
else if (term === constants_1.TERM_SEPTENNIALLY) {
return 84;
}
else if (term === constants_1.TERM_OCTENNIALLY) {
return 96;
}
else if (term === constants_1.TERM_NOVENNIALLY) {
return 108;
}
else if (term === constants_1.TERM_DECENNIALLY) {
return 120;
}
else if (term === constants_1.TERM_CENTENNIALLY) {
return 1200;
}
throw new Error(`Unknown term: ${term}`);
}
function getBillingTermForMonths(term) {
if (term === 1) {
return constants_1.TERM_MONTHLY;
}
else if (term === 12) {
return constants_1.TERM_ANNUALLY;
}
else if (term === 24) {
return constants_1.TERM_BIENNIALLY;
}
else if (term === 36) {
return constants_1.TERM_TRIENNIALLY;
}
else if (term === 48) {
return constants_1.TERM_QUADRENNIALLY;
}
else if (term === 60) {
return constants_1.TERM_QUINQUENNIALLY;
}
else if (term === 72) {
return constants_1.TERM_SEXENNIALLY;
}
else if (term === 84) {
return constants_1.TERM_SEPTENNIALLY;
}
else if (term === 96) {
return constants_1.TERM_OCTENNIALLY;
}
else if (term === 108) {
return constants_1.TERM_NOVENNIALLY;
}
else if (term === 120) {
return constants_1.TERM_DECENNIALLY;
}
else if (term === 1200) {
return constants_1.TERM_CENTENNIALLY;
}
throw new Error(`Unknown term: ${term}`);
}
function plansLink(urlString, siteSlug, intervalType, forceIntervalType = false) {
const url = new URL(urlString, window.location.origin);
if ('monthly' === intervalType || forceIntervalType) {
url.pathname += '/' + intervalType;
}
if (siteSlug) {
url.pathname += '/' + siteSlug;
}
if (urlString.startsWith('/')) {
return url.pathname + url.search;
}
return url.toString();
}
function applyTestFiltersToPlansList(planName, abtest, extraArgs = {}) {
const plan = getPlan(planName);
if (!plan) {
throw new Error(`Unknown plan: ${planName}`);
}
const filteredPlanConstantObj = { ...plan };
const filteredPlanFeaturesConstantList = 'getPlanCompareFeatures' in plan && plan.getPlanCompareFeatures
? plan.getPlanCompareFeatures(abtest, extraArgs)
: [];
/* eslint-disable @typescript-eslint/no-empty-function */
// these becomes no-ops when we removed some of the abtest overrides, but
// we're leaving the code in place for future tests
const removeDisabledFeatures = () => { };
const updatePlanDescriptions = () => { };
const updatePlanFeatures = () => { };
/* eslint-enable */
removeDisabledFeatures();
updatePlanDescriptions();
updatePlanFeatures();
return {
...filteredPlanConstantObj,
getPlanCompareFeatures: () => filteredPlanFeaturesConstantList,
};
}
function getPlanTermLabel(planName, translate) {
const plan = getPlan(planName);
if (!plan || !plan.term) {
return;
}
switch (plan.term) {
case constants_1.TERM_MONTHLY:
return translate('Monthly subscription');
case constants_1.TERM_ANNUALLY:
return translate('Annual subscription');
case constants_1.TERM_BIENNIALLY:
return translate('Two year subscription');
case constants_1.TERM_TRIENNIALLY:
return translate('Three year subscription');
case constants_1.TERM_CENTENNIALLY:
return translate('Hundred year subscription');
}
}
const getPopularPlanSpec = ({ flowName, customerType, isJetpack, availablePlans, }) => {
// Jetpack doesn't currently highlight "Popular" plans
if (isJetpack) {
return false;
}
if (availablePlans.length === 0) {
return false;
}
const defaultPlan = getPlan(availablePlans[0]);
if (!defaultPlan) {
return false;
}
const group = constants_1.GROUP_WPCOM;
if (flowName === 'hosting') {
return {
type: constants_1.TYPE_BUSINESS,
group,
};
}
if (customerType === 'personal') {
if (availablePlans.findIndex(isPremiumPlan) !== -1) {
return {
type: constants_1.TYPE_PREMIUM,
group,
};
}
// when customerType is not personal, default to business
}
else if (availablePlans.findIndex(isBusinessPlan) !== -1) {
return {
type: constants_1.TYPE_BUSINESS,
group,
};
}
// finally, just return the default one.
return {
type: defaultPlan.type,
group,
};
};
exports.getPopularPlanSpec = getPopularPlanSpec;
function isValueTruthy(value) {
return !!value;
}
const chooseDefaultCustomerType = ({ currentCustomerType, selectedPlan, currentPlan, }) => {
if (currentCustomerType) {
return currentCustomerType;
}
const group = constants_1.GROUP_WPCOM;
const businessPlanSlugs = [
findPlansKeys({ group, term: constants_1.TERM_ANNUALLY, type: constants_1.TYPE_PREMIUM })[0],
findPlansKeys({ group, term: constants_1.TERM_BIENNIALLY, type: constants_1.TYPE_PREMIUM })[0],
findPlansKeys({ group, term: constants_1.TERM_TRIENNIALLY, type: constants_1.TYPE_PREMIUM })[0],
findPlansKeys({ group, term: constants_1.TERM_ANNUALLY, type: constants_1.TYPE_BUSINESS })[0],
findPlansKeys({ group, term: constants_1.TERM_BIENNIALLY, type: constants_1.TYPE_BUSINESS })[0],
findPlansKeys({ group, term: constants_1.TERM_TRIENNIALLY, type: constants_1.TYPE_BUSINESS })[0],
findPlansKeys({ group, term: constants_1.TERM_ANNUALLY, type: constants_1.TYPE_ECOMMERCE })[0],
findPlansKeys({ group, term: constants_1.TERM_BIENNIALLY, type: constants_1.TYPE_ECOMMERCE })[0],
findPlansKeys({ group, term: constants_1.TERM_TRIENNIALLY, type: constants_1.TYPE_ECOMMERCE })[0],
findPlansKeys({ group, term: constants_1.TERM_ANNUALLY, type: constants_1.TYPE_PRO })[0],
findPlansKeys({ group, term: constants_1.TERM_BIENNIALLY, type: constants_1.TYPE_PRO })[0],
]
.map((planKey) => getPlan(planKey))
.filter(isValueTruthy)
.map((plan) => plan.getStoreSlug());
if (selectedPlan) {
return businessPlanSlugs.includes(selectedPlan) ? 'business' : 'personal';
}
else if (currentPlan) {
const isPlanInBusinessGroup = businessPlanSlugs.indexOf(currentPlan.productSlug) !== -1;
return isPlanInBusinessGroup ? 'business' : 'personal';
}
return 'personal';
};
exports.chooseDefaultCustomerType = chooseDefaultCustomerType;
/**
* Determines if a plan includes Jetpack Search by looking at the plan's features.
*/
const planHasJetpackSearch = (planSlug) => planHasFeature(planSlug, constants_1.FEATURE_JETPACK_SEARCH) ||
planHasFeature(planSlug, constants_1.FEATURE_JETPACK_SEARCH_MONTHLY);
exports.planHasJetpackSearch = planHasJetpackSearch;
function getFeaturesList() {
return features_list_1.FEATURES_LIST;
}
const getPlanFeaturesObject = (planFeaturesList, isExperimentVariant) => {
if (!planFeaturesList) {
return [];
}
return planFeaturesList.map((featuresConst) => {
const feature = features_list_1.FEATURES_LIST[featuresConst];
if (!feature || !isExperimentVariant) {
return feature;
}
// Wrap feature methods to pass isExperimentVariant parameter
return {
...feature,
getTitle: (params) => feature.getTitle({ ...params, isExperimentVariant }),
...(feature.getDescription && {
getDescription: (params) => feature.getDescription({ ...params, isExperimentVariant }),
}),
};
});
};
exports.getPlanFeaturesObject = getPlanFeaturesObject;
function isValidFeatureKey(feature) {
return !!features_list_1.FEATURES_LIST[feature];
}
function getFeatureByKey(feature) {
return features_list_1.FEATURES_LIST[feature];
}
function getFeatureDifference(smallerPlan, biggerPlan, featureBundleSelector) {
let biggerPlanObject = getPlan(biggerPlan)?.[featureBundleSelector];
let smallerPlanObject = getPlan(smallerPlan)?.[featureBundleSelector];
if (typeof biggerPlanObject === 'function') {
biggerPlanObject = biggerPlanObject();
}
else if (!Array.isArray(biggerPlanObject)) {
biggerPlanObject = [];
}
if (typeof smallerPlanObject === 'function') {
smallerPlanObject = smallerPlanObject();
}
else if (!Array.isArray(smallerPlanObject)) {
smallerPlanObject = [];
}
const difference = biggerPlanObject.filter((feature) => !smallerPlanObject.includes(feature));
return difference;
}
//# sourceMappingURL=main.js.map