@@ -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 }
0 commit comments