From 1377ac38dbcb96fb599ca413f2234010be3fdbb3 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 10 Sep 2025 11:59:38 +0500 Subject: [PATCH] common: no need for isLegacyPro --- .../common/src/utils/is-feature-available.ts | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/packages/common/src/utils/is-feature-available.ts b/packages/common/src/utils/is-feature-available.ts index 0bc7cf98e..f5560b2dc 100644 --- a/packages/common/src/utils/is-feature-available.ts +++ b/packages/common/src/utils/is-feature-available.ts @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { SubscriptionPlan, SubscriptionType } from "@notesnook/core"; +import { SubscriptionPlan } from "@notesnook/core"; import { database as db } from "../database.js"; type CaptionValue = ("infinity" | (string & {})) | boolean | number; @@ -448,8 +448,8 @@ export async function isFeatureAvailable( export async function getFeatureLimit( feature: Feature ) { - const { isLegacyPro, plan } = await getUserPlan(); - return getFeatureLimitFromPlan(feature, plan, isLegacyPro); + const plan = await getUserPlan(); + return getFeatureLimitFromPlan(feature, plan); } export async function areFeaturesAvailable( @@ -458,7 +458,7 @@ export async function areFeaturesAvailable( ): Promise<{ [K in TIds[number]]: FeatureResult; }> { - const { isLegacyPro, plan } = await getUserPlan(); + const plan = await getUserPlan(); const results = {} as { [K in TIds[number]]: FeatureResult; }; @@ -467,7 +467,7 @@ export async function areFeaturesAvailable( const id = ids[i]; const feature = getFeature(id); - const limit = getFeatureLimitFromPlan(feature, plan, isLegacyPro); + const limit = getFeatureLimitFromPlan(feature, plan); const isAllowed = await limit.isAllowed(value || (await feature.used?.())); results[id as TIds[number]] = { @@ -484,16 +484,8 @@ export async function areFeaturesAvailable( async function getUserPlan() { const user = await db.user.getUser(); - const type = user?.subscription?.type; - - const isLegacyPro = - type !== undefined && - (type === SubscriptionType.BETA || - type === SubscriptionType.PREMIUM || - type === SubscriptionType.PREMIUM_CANCELED || - type === SubscriptionType.TRIAL); const plan = user?.subscription?.plan || SubscriptionPlan.FREE; - return { plan, isLegacyPro }; + return plan; } async function availableOn(id: FeatureId, value?: number) { @@ -540,11 +532,11 @@ export type FeatureUsage = { used: number; }; export async function getFeaturesUsage(): Promise { - const { isLegacyPro, plan } = await getUserPlan(); + const plan = await getUserPlan(); const usage: FeatureUsage[] = []; for (const key in features) { const feature = getFeature(key as FeatureId); - const limit = getFeatureLimitFromPlan(feature, plan, isLegacyPro); + const limit = getFeatureLimitFromPlan(feature, plan); if (!feature.used || typeof limit.value !== "number") continue; usage.push({ id: key as FeatureId, @@ -557,10 +549,9 @@ export async function getFeaturesUsage(): Promise { function getFeatureLimitFromPlan( feature: Feature, - plan: SubscriptionPlan, - isLegacyPro: boolean + plan: SubscriptionPlan ): Limit> { - const key = isLegacyPro ? "legacyPro" : PLAN_TO_AVAILABILITY[plan]; + const key = PLAN_TO_AVAILABILITY[plan]; return feature.availability[key] as unknown as Limit>; } @@ -572,7 +563,8 @@ const PLAN_TO_AVAILABILITY: Record< [SubscriptionPlan.ESSENTIAL]: "essential", [SubscriptionPlan.PRO]: "pro", [SubscriptionPlan.BELIEVER]: "believer", - [SubscriptionPlan.EDUCATION]: "pro" + [SubscriptionPlan.EDUCATION]: "pro", + [SubscriptionPlan.LEGACY_PRO]: "legacyPro" }; const AVAILABILITY_TO_PLAN: Record<