diff --git a/src/services/entitlements.js b/src/services/entitlements.js index d7be8eccd7..a04f6fd464 100644 --- a/src/services/entitlements.js +++ b/src/services/entitlements.js @@ -70,6 +70,16 @@ define(function (require, exports, module) { }); } + let effectiveEntitlements = null; + async function _getEffectiveEntitlements() { + if(effectiveEntitlements){ + return effectiveEntitlements; + } + const entitlements = await LoginService.getEffectiveEntitlements(); + effectiveEntitlements = entitlements; + return entitlements; + } + /** * Get the plan details from entitlements with fallback to free plan defaults. If the user is * in pro trial(isInProTrial API), then paidSubscriber will always be true as we need to treat user as paid. @@ -77,7 +87,7 @@ define(function (require, exports, module) { * @returns {Promise} Plan details object */ async function getPlanDetails() { - const entitlements = await LoginService.getEffectiveEntitlements(); + const entitlements = await _getEffectiveEntitlements(); if (entitlements && entitlements.plan) { return entitlements.plan; @@ -97,7 +107,7 @@ define(function (require, exports, module) { * @returns {Promise} True if user is in pro trial, false otherwise */ async function isInProTrial() { - const entitlements = await LoginService.getEffectiveEntitlements(); + const entitlements = await _getEffectiveEntitlements(); return !!(entitlements && entitlements.isInProTrial); } @@ -106,13 +116,13 @@ define(function (require, exports, module) { * @returns {Promise} Number of remaining trial days */ async function getTrialRemainingDays() { - const entitlements = await LoginService.getEffectiveEntitlements(); + const entitlements = await _getEffectiveEntitlements(); return entitlements && entitlements.trialDaysRemaining ? entitlements.trialDaysRemaining : 0; } /** * Get current raw entitlements. Should not be used directly, use individual feature entitlement instead - * like getLiveEditEntitlement. + * like getLiveEditEntitlement. Raw entitlements are server set and will not contain trial info. * @returns {Promise} Raw entitlements object or null */ async function getRawEntitlements() { @@ -142,7 +152,7 @@ define(function (require, exports, module) { * } */ async function getLiveEditEntitlement() { - const entitlements = await LoginService.getEffectiveEntitlements(); + const entitlements = await _getEffectiveEntitlements(); if (entitlements && entitlements.entitlements && entitlements.entitlements.liveEdit) { return entitlements.entitlements.liveEdit; @@ -168,6 +178,7 @@ define(function (require, exports, module) { LoginService = KernalModeTrust.loginService; // Set up event forwarding from LoginService LoginService.on(LoginService.EVENT_ENTITLEMENTS_CHANGED, function() { + effectiveEntitlements = null; Entitlements.trigger(EVENT_ENTITLEMENTS_CHANGED); }); } diff --git a/src/services/login-service.js b/src/services/login-service.js index d756b8fc01..094c63fdfb 100644 --- a/src/services/login-service.js +++ b/src/services/login-service.js @@ -213,8 +213,10 @@ define(function (require, exports, module) { /** - * Get entitlements from API or cache - * Returns null if user is not logged in + * Get entitlements from API or disc cache. + * @param {string} forceRefresh If provided will always fetch from server and bypass cache. Use rarely like + * when a user logs in/out/some other user activity/ account-related events. + * Returns null if the user is not logged in */ async function getEntitlements(forceRefresh = false) { // Return null if not logged in @@ -250,7 +252,8 @@ define(function (require, exports, module) { try { const accountBaseURL = LoginService.getAccountBaseURL(); const language = brackets.getLocale(); - let url = `${accountBaseURL}/getAppEntitlements?lang=${language}`; + const currentVersion = window.AppConfig.apiVersion || "1.0.0"; + let url = `${accountBaseURL}/getAppEntitlements?lang=${language}&version=${currentVersion}`; let fetchOptions = { method: 'GET', headers: { @@ -413,8 +416,8 @@ define(function (require, exports, module) { } /** - * Get effective entitlements for determining feature availability throughout the app. - * This is the primary API that should be used across Phoenix to check entitlements and enable/disable features. + * Get effective entitlements for determining feature availability. + * This is for internal use only. All consumers in phoenix code should use `KernalModeTrust.Entitlements` APIs. * * @returns {Promise} Entitlements object or null if not logged in and no trial active * diff --git a/src/services/readme-login-browser-no_dist.md b/src/services/readme-login-browser-no_dist.md index 85acca4f92..f9b684c652 100644 --- a/src/services/readme-login-browser-no_dist.md +++ b/src/services/readme-login-browser-no_dist.md @@ -107,17 +107,22 @@ For testing with a local account server instance: - Start your local account development stack on `localhost:5000` - Ensure all login endpoints are properly configured -3. **Login and Copy Session:** +Now just visit login server at `http://localhost:5000` and login. It should work with phoenix code dev server +at https://localhost:8000/src when you run phoenix code dev server via `npm run serve`. This works without any +manual cookie copy needed as the dev server sets cookies localhost wide. But if that didnt work, please see +manual cookie copy instructions below. + +1. **Login and Copy Session:** - Navigate to `http://localhost:5000` in browser - Login with test credentials - Copy `session` cookie value from DevTools -4. **Set Cookie in Phoenix App:** +2. **Set Cookie in Phoenix App:** - Navigate to `http://localhost:8000/src/` - Open Chrome DevTools → Application → Cookies - Create `session` cookie with copied value (same process as above) -5. **Verify Local Integration:** +3. **Verify Local Integration:** - API calls from localhost:8000 now route through serve-proxy.js to localhost:5000 - Authentication should work with local account server