Skip to content

Commit f63a451

Browse files
committed
chore: we now seperate isSubscriber and paidSubscriber in entitlments
earlier, we always set paidSubscriber to true even when they were trial users, now its more clear to directly use paidSubscriber for only paid users and isSubscriber for general users in trial/paid
1 parent 3ac1636 commit f63a451

File tree

12 files changed

+100
-87
lines changed

12 files changed

+100
-87
lines changed

src/assets/new-project/assets/js/code-editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ function _updateProBranding() {
197197
// Get plan info from window.top.Phoenix.pro.plan
198198
const planInfo = window.top.Phoenix && window.top.Phoenix.pro && window.top.Phoenix.pro.plan;
199199

200-
if (planInfo && planInfo.paidSubscriber) {
200+
if (planInfo && planInfo.isSubscriber) {
201201
// Hide free title, show pro title
202202
$freeTitle.addClass('forced-hidden');
203203
$proTitle.removeClass('forced-hidden');

src/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,10 @@
447447
}
448448

449449
async function _startRequireLoop() {
450-
// If running on localhost, fetch proxy config to get dynamic account URL
451-
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
450+
// If running on localhost, `npm run serve`, `npm run serveLocalAccount` targets puts in a fetch proxy.
451+
// tTe proxy helps work around cookie domain set by phcode.dev as the dev urls are localhost. so to use
452+
// either the actual services endpoint or localhost endpoints in dev, this is needed.
453+
if (!Phoenix.isTestWindow && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1')) {
452454
try {
453455
const response = await fetch('/proxy/config');
454456
if (response.ok) {

src/services/EntitlementsManager.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ define(function (require, exports, module) {
8787

8888
/**
8989
* Get the plan details from entitlements with fallback to free plan defaults. If the user is
90-
* in pro trial(isInProTrial API), then paidSubscriber will always be true as we need to treat user as paid.
91-
* you should use isInProTrial API to check if user is in pro trial if some trial-related logic needs to be done.
90+
* in pro trial(isInProTrial API), then isSubscriber will always be true as we need to treat
91+
* user as subcriber. you should use isInProTrial API to check if user is in pro trial if some
92+
* trial-related logic needs to be done.
9293
* @returns {Promise<Object>} Plan details object
9394
*/
9495
async function getPlanDetails() {
@@ -101,14 +102,15 @@ define(function (require, exports, module) {
101102
// Fallback to free plan defaults
102103
const currentDate = Date.now();
103104
return {
105+
isSubscriber: false,
104106
paidSubscriber: false,
105107
name: Strings.USER_FREE_PLAN_NAME_DO_NOT_TRANSLATE,
106108
validTill: currentDate + (FREE_PLAN_VALIDITY_DAYS * MS_IN_DAY)
107109
};
108110
}
109111

110112
/**
111-
* Check if user is in a pro trial. IF the user is in pro trail, then `plan.paidSubscriber` will always be true.
113+
* Check if user is in a pro trial. IF the user is in pro trail, then `plan.isSubscriber` will always be true.
112114
* @returns {Promise<boolean>} True if user is in pro trial, false otherwise
113115
*/
114116
async function isInProTrial() {

src/services/login-service.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ define(function (require, exports, module) {
461461
if(entitlements.plan && (!entitlements.plan.validTill || currentDate > entitlements.plan.validTill)) {
462462
entitlements.plan = {
463463
...entitlements.plan,
464+
isSubscriber: false,
464465
paidSubscriber: false,
465466
name: Strings.USER_FREE_PLAN_NAME_DO_NOT_TRANSLATE,
466467
fullName: Strings.USER_FREE_PLAN_NAME_DO_NOT_TRANSLATE,
@@ -498,7 +499,8 @@ define(function (require, exports, module) {
498499
* ```javascript
499500
* {
500501
* plan: {
501-
* paidSubscriber: true, // Always true for trial users
502+
* isSubscriber: true, // Always true for trial users
503+
* paidSubscriber: false, // if the user is a paid for the plan, or is it an unpaid promo
502504
* name: "Phoenix Pro"
503505
* fullName: "Phoenix Pro" // this can be deceptive name like "Phoenix Pro For Education" to use in
504506
* // profile popup, not main branding
@@ -514,11 +516,12 @@ define(function (require, exports, module) {
514516
* ```
515517
*
516518
* **For logged-in trial users:**
517-
* - If remote response has `plan.paidSubscriber: false`, injects `paidSubscriber: true`
519+
* - If remote response has `plan.isSubscriber: false`, injects `isSubscriber: true`
518520
* - Adds `isInProTrial: true` and `trialDaysRemaining`
519521
* - Injects `entitlements.liveEdit.activated: true`
520-
* - Note: Trial users may not be actual paid subscribers, but `paidSubscriber: true` is set
521-
* so all Phoenix code treats them as paid subscribers
522+
* - Note: Trial users may not be actual paid subscribers, but `isSubscriber: true` is set
523+
* so all Phoenix code treats them as subscribers. to check if they actually paid or not, use
524+
* `paidSubscriber` field.
522525
*
523526
* **For logged-in users (full remote response):**
524527
* ```javascript
@@ -529,6 +532,7 @@ define(function (require, exports, module) {
529532
* name: "Phoenix Pro",
530533
* fullName: "Phoenix Pro" // this can be deceptive name like "Phoenix Pro For Education" to use in
531534
* // profile popup, not main branding
535+
* isSubscriber: boolean,
532536
* paidSubscriber: boolean,
533537
* validTill: number // Timestamp
534538
* },
@@ -574,7 +578,7 @@ define(function (require, exports, module) {
574578
*
575579
* // Get current entitlements
576580
* const entitlements = await LoginService.getEffectiveEntitlements();
577-
* if (entitlements?.plan?.paidSubscriber) {
581+
* if (entitlements?.plan?.isSubscriber) {
578582
* // Enable pro features
579583
* }
580584
* if (entitlements?.entitlements?.liveEdit?.activated) {
@@ -597,8 +601,8 @@ define(function (require, exports, module) {
597601
// now we need to grant trial, as user is entitled to trial if he is here.
598602
// User has active server plan(either with login or device license)
599603
if (serverEntitlements && serverEntitlements.plan) {
600-
if (serverEntitlements.plan.paidSubscriber) {
601-
// Already a paid subscriber(or has device license), return as-is
604+
if (serverEntitlements.plan.isSubscriber) {
605+
// Already a subscriber(or has device license), return as-is
602606
// never inject trail data in this case.
603607
return serverEntitlements;
604608
}
@@ -608,7 +612,8 @@ define(function (require, exports, module) {
608612
...serverEntitlements,
609613
plan: {
610614
...serverEntitlements.plan,
611-
paidSubscriber: true,
615+
isSubscriber: true,
616+
paidSubscriber: serverEntitlements.plan.paidSubscriber || false,
612617
name: brackets.config.main_pro_plan,
613618
fullName: brackets.config.main_pro_plan,
614619
validTill: dateNowFn() + trialDaysRemaining * MS_IN_DAY
@@ -632,7 +637,8 @@ define(function (require, exports, module) {
632637
// Non-logged-in, non licensed user with trial - return synthetic entitlements
633638
return {
634639
plan: {
635-
paidSubscriber: true,
640+
isSubscriber: true,
641+
paidSubscriber: false,
636642
name: brackets.config.main_pro_plan,
637643
fullName: brackets.config.main_pro_plan,
638644
validTill: dateNowFn() + trialDaysRemaining * MS_IN_DAY

src/services/login-utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ define(function (require, exports, module) {
110110
// Check paidSubscriber changes
111111
const currentPaidSub = current.plan && current.plan.paidSubscriber;
112112
const lastPaidSub = last.plan && last.plan.paidSubscriber;
113-
if (currentPaidSub !== lastPaidSub) {
113+
// Check isSubscriber changes
114+
const currentIsSubscriber = current.plan && current.plan.isSubscriber;
115+
const lastIsSubscriber = last.plan && last.plan.isSubscriber;
116+
if (currentIsSubscriber !== lastIsSubscriber || currentPaidSub !== lastPaidSub) {
114117
return true;
115118
}
116119

src/services/profile-menu.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ define(function (require, exports, module) {
179179
<i class="fa-solid fa-feather" style="margin-left: 3px;"></i>
180180
</span>
181181
</div>`;
182-
} else if (effectiveEntitlements.plan && effectiveEntitlements.plan.paidSubscriber) {
182+
} else if (effectiveEntitlements.plan && effectiveEntitlements.plan.isSubscriber) {
183183
// Device-licensed user: show Phoenix Pro branding
184184
const planName = effectiveEntitlements.plan.fullName || brackets.config.main_pro_plan;
185185
proInfoHtml = `<div class="trial-plan-info">
@@ -234,21 +234,21 @@ define(function (require, exports, module) {
234234
// Phoenix.pro is only for display purposes and should not be used to gate features.
235235
// Use kernal mode apis for trusted check of pro features.
236236
Phoenix.pro.plan = {
237-
paidSubscriber: false,
237+
isSubscriber: false,
238238
name: Strings.USER_FREE_PLAN_NAME_DO_NOT_TRANSLATE,
239239
fullName: Strings.USER_FREE_PLAN_NAME_DO_NOT_TRANSLATE
240240
};
241241
}
242242

243243
if (entitlements && entitlements.plan){
244244
Phoenix.pro.plan = {
245-
paidSubscriber: entitlements.plan.paidSubscriber,
245+
isSubscriber: entitlements.plan.isSubscriber,
246246
name: entitlements.plan.name,
247247
fullName: entitlements.plan.fullName,
248248
validTill: entitlements.plan.validTill
249249
};
250250
}
251-
if (entitlements && entitlements.plan && entitlements.plan.paidSubscriber) {
251+
if (entitlements && entitlements.plan && entitlements.plan.isSubscriber) {
252252
// Pro user (paid subscriber or trial): show short name branding with `name feather icon`(not full name)
253253
let displayName = entitlements.plan.name || brackets.config.main_pro_plan;
254254
if (entitlements.isInProTrial) {
@@ -384,7 +384,7 @@ define(function (require, exports, module) {
384384
// Update plan class and content based on paid subscriber status
385385
$planName.removeClass('user-plan-free user-plan-paid');
386386

387-
if (entitlements.plan.paidSubscriber) {
387+
if (entitlements.plan.isSubscriber) {
388388
// Use pro styling with feather icon for pro users (paid or trial)
389389
if (entitlements.isInProTrial) {
390390
// For trial users: separate "Phoenix Pro" with icon from "(X days left)" text
@@ -596,7 +596,7 @@ define(function (require, exports, module) {
596596
const effectiveEntitlements = await KernalModeTrust.loginService.getEffectiveEntitlements();
597597
return effectiveEntitlements &&
598598
(effectiveEntitlements.isInProTrial ||
599-
(effectiveEntitlements.plan && effectiveEntitlements.plan.paidSubscriber));
599+
(effectiveEntitlements.plan && effectiveEntitlements.plan.isSubscriber));
600600
} catch (error) {
601601
console.error('Failed to check Pro access status:', error);
602602
return false;
@@ -611,7 +611,7 @@ define(function (require, exports, module) {
611611
const effectiveEntitlements = await KernalModeTrust.loginService.getEffectiveEntitlements();
612612
if (effectiveEntitlements &&
613613
(effectiveEntitlements.isInProTrial ||
614-
(effectiveEntitlements.plan && effectiveEntitlements.plan.paidSubscriber))) {
614+
(effectiveEntitlements.plan && effectiveEntitlements.plan.isSubscriber))) {
615615
console.log('Profile Menu: Found Pro entitlements (trial or device license), updating branding...');
616616
_updateBranding(effectiveEntitlements);
617617
} else {

src/services/promotions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ define(function (require, exports, module) {
213213

214214
// getEntitlements() returns null if not logged in
215215
const entitlements = await LoginService.getEntitlements();
216-
return entitlements && entitlements.plan && entitlements.plan.paidSubscriber === true;
216+
return entitlements && entitlements.plan && entitlements.plan.isSubscriber === true;
217217
} catch (error) {
218218
console.error("Error checking pro subscription:", error);
219219
return false;

test/spec/login-browser-integ-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ define(function (require, exports, module) {
183183
Date.now() + 30 * 24 * 60 * 60 * 1000; // valid for 30 days
184184

185185
entitlementsResponse.plan = {
186-
paidSubscriber: true,
186+
isSubscriber: true,
187187
name: "Phoenix Pro",
188188
fullName: "Phoenix Pro",
189189
validTill: validTill
@@ -196,7 +196,7 @@ define(function (require, exports, module) {
196196
};
197197
} else {
198198
entitlementsResponse.plan = {
199-
paidSubscriber: false,
199+
isSubscriber: false,
200200
name: "Free Plan",
201201
fullName: "Free Plan"
202202
};

test/spec/login-desktop-integ-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ define(function (require, exports, module) {
209209
Date.now() + 30 * 24 * 60 * 60 * 1000; // valid for 30 days
210210

211211
entitlementsResponse.plan = {
212-
paidSubscriber: true,
212+
isSubscriber: true,
213213
name: "Phoenix Pro",
214214
fullName: isDeviceIDRequest ? "Phoenix Pro Test Edu" : "Phoenix Pro",
215215
validTill: validTill
@@ -222,7 +222,7 @@ define(function (require, exports, module) {
222222
};
223223
} else {
224224
entitlementsResponse.plan = {
225-
paidSubscriber: false,
225+
isSubscriber: false,
226226
name: "Free Plan",
227227
fullName: "Free Plan"
228228
};

0 commit comments

Comments
 (0)