Skip to content

Commit df22b67

Browse files
committed
chore: update docs for LoginService.getEffectiveEntitlements, refactor brackets.config.main_pro_plan
1 parent 1e84488 commit df22b67

File tree

4 files changed

+113
-10
lines changed

4 files changed

+113
-10
lines changed

src/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"config": {
33
"app_title": "Phoenix Code",
44
"app_name_about": "Phoenix Code",
5+
"main_pro_plan": "Phoenix Pro",
56
"about_icon": "styles/images/phoenix-icon.svg",
67
"account_url": "https://account.phcode.dev/",
78
"promotions_url": "https://promotions.phcode.dev/dev/",

src/services/login-service.js

Lines changed: 108 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ define(function (require, exports, module) {
2727
require("./setup-login-service"); // this adds loginService to KernalModeTrust
2828
require("./promotions");
2929

30+
const MS_IN_DAY = 10 * 24 * 60 * 60 * 1000;
31+
3032
const KernalModeTrust = window.KernalModeTrust;
3133
if(!KernalModeTrust){
3234
// integrated extensions will have access to kernal mode, but not external extensions
@@ -123,8 +125,91 @@ define(function (require, exports, module) {
123125
}
124126

125127
/**
126-
* Get effective entitlements including trial enhancement for UI display
127-
* Returns enhanced entitlements that treat trial users as pro users
128+
* Get effective entitlements for determining feature availability throughout the app.
129+
* This is the primary API that should be used across Phoenix to check entitlements and enable/disable features.
130+
*
131+
* @returns {Promise<Object|null>} Entitlements object or null if not logged in and no trial active
132+
*
133+
* @description Response shapes vary based on user state:
134+
*
135+
* **For non-logged-in users:**
136+
* - Returns `null` if no trial is active
137+
* - Returns synthetic entitlements if trial is active:
138+
* ```javascript
139+
* {
140+
* plan: {
141+
* paidSubscriber: true, // Always true for trial users
142+
* name: "Phoenix Pro"
143+
* },
144+
* isInProTrial: true, // Indicates this is a trial user
145+
* trialDaysRemaining: number, // Days left in trial
146+
* entitlements: {
147+
* liveEdit: {
148+
* activated: true // Trial users get liveEdit access
149+
* }
150+
* }
151+
* }
152+
* ```
153+
*
154+
* **For logged-in trial users:**
155+
* - If remote response has `plan.paidSubscriber: false`, injects `paidSubscriber: true`
156+
* - Adds `isInProTrial: true` and `trialDaysRemaining`
157+
* - Injects `entitlements.liveEdit.activated: true`
158+
* - Note: Trial users may not be actual paid subscribers, but `paidSubscriber: true` is set
159+
* so all Phoenix code treats them as paid subscribers
160+
*
161+
* **For logged-in users (full remote response):**
162+
* ```javascript
163+
* {
164+
* isSuccess: boolean,
165+
* lang: string,
166+
* plan: {
167+
* name: "Phoenix Pro",
168+
* paidSubscriber: boolean,
169+
* validTill: number // Timestamp
170+
* },
171+
* profileview: {
172+
* quota: {
173+
* titleText: "Ai Quota Used",
174+
* usageText: "100 / 200 credits",
175+
* usedPercent: number
176+
* },
177+
* htmlMessage: string // HTML alert message
178+
* },
179+
* entitlements: {
180+
* liveEdit: {
181+
* activated: boolean,
182+
* subscribeURL: string, // URL to subscribe if not activated
183+
* upgradeToPlan: string, // Plan name that includes this entitlement
184+
* validTill: number // Timestamp when entitlement expires
185+
* },
186+
* liveEditAI: {
187+
* activated: boolean,
188+
* subscribeURL: string,
189+
* purchaseCreditsURL: string, // URL to purchase AI credits
190+
* upgradeToPlan: string,
191+
* validTill: number
192+
* }
193+
* }
194+
* }
195+
* ```
196+
*
197+
* @example
198+
* // Listen for entitlements changes
199+
* const LoginService = window.KernelModeTrust.loginService;
200+
* LoginService.on(LoginService.EVENT_ENTITLEMENTS_CHANGED, (entitlements) => {
201+
* console.log('Entitlements changed:', entitlements);
202+
* // Update UI based on new entitlements
203+
* });
204+
*
205+
* // Get current entitlements
206+
* const entitlements = await LoginService.getEffectiveEntitlements();
207+
* if (entitlements?.plan?.paidSubscriber) {
208+
* // Enable pro features
209+
* }
210+
* if (entitlements?.entitlements?.liveEdit?.activated) {
211+
* // Enable live edit feature
212+
* }
128213
*/
129214
async function getEffectiveEntitlements(forceRefresh = false) {
130215
// Get raw server entitlements
@@ -151,21 +236,38 @@ define(function (require, exports, module) {
151236
plan: {
152237
...serverEntitlements.plan,
153238
paidSubscriber: true,
154-
name: "Phoenix Pro"
239+
name: brackets.config.main_pro_plan
155240
},
156241
isInProTrial: true,
157-
trialDaysRemaining: trialDaysRemaining
242+
trialDaysRemaining: trialDaysRemaining,
243+
entitlements: {
244+
...serverEntitlements.entitlements,
245+
liveEdit: {
246+
activated: true,
247+
subscribeURL: brackets.config.purchase_url,
248+
upgradeToPlan: brackets.config.main_pro_plan,
249+
validTill: Date.now() + trialDaysRemaining * MS_IN_DAY
250+
}
251+
}
158252
};
159253
}
160254
} else {
161255
// Non-logged-in user with trial - return synthetic entitlements
162256
return {
163257
plan: {
164258
paidSubscriber: true,
165-
name: "Phoenix Pro"
259+
name: brackets.config.main_pro_plan
166260
},
167261
isInProTrial: true,
168-
trialDaysRemaining: trialDaysRemaining
262+
trialDaysRemaining: trialDaysRemaining,
263+
entitlements: {
264+
liveEdit: {
265+
activated: true,
266+
subscribeURL: brackets.config.purchase_url,
267+
upgradeToPlan: brackets.config.main_pro_plan,
268+
validTill: Date.now() + trialDaysRemaining * MS_IN_DAY
269+
}
270+
}
169271
};
170272
}
171273
}

src/services/pro-dialogs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
define(function (require, exports, module) {
2929
const proTitle = `<span class="phoenix-pro-title">
30-
<span class="pro-plan-name">Phoenix Pro</span>
30+
<span class="pro-plan-name">${brackets.config.main_pro_plan}</span>
3131
<i class="fa-solid fa-feather orange-gold" style="margin-left: 3px;"></i>
3232
</span>`,
33-
proTitlePlain = `<span class="pro-plan-name">Phoenix Pro</span>
33+
proTitlePlain = `<span class="pro-plan-name">${brackets.config.main_pro_plan}</span>
3434
<i class="fa-solid fa-feather" style="margin-left: 2px;"></i>`;
3535
require("./setup-login-service"); // this adds loginService to KernalModeTrust
3636
const Dialogs = require("widgets/Dialogs"),

src/services/profile-menu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ define(function (require, exports, module) {
230230
}
231231
if (entitlements && entitlements.plan && entitlements.plan.paidSubscriber) {
232232
// Pro user (paid subscriber or trial): show plan name with feather icon
233-
let displayName = entitlements.plan.name || "Phoenix Pro";
233+
let displayName = entitlements.plan.name || brackets.config.main_pro_plan;
234234
if (entitlements.isInProTrial) {
235-
displayName = `Phoenix Pro`; // Just "Phoenix Pro" for branding, not "Phoenix Pro Trial"
235+
displayName = brackets.config.main_pro_plan; // Just "Phoenix Pro" for branding, not "Phoenix Pro Trial"
236236
}
237237
$brandingLink
238238
.attr("href", "https://account.phcode.dev")

0 commit comments

Comments
 (0)