@@ -70,14 +70,24 @@ define(function (require, exports, module) {
7070 } ) ;
7171 }
7272
73+ let effectiveEntitlements = null ;
74+ async function _getEffectiveEntitlements ( ) {
75+ if ( effectiveEntitlements ) {
76+ return effectiveEntitlements ;
77+ }
78+ const entitlements = await LoginService . getEffectiveEntitlements ( ) ;
79+ effectiveEntitlements = entitlements ;
80+ return entitlements ;
81+ }
82+
7383 /**
7484 * Get the plan details from entitlements with fallback to free plan defaults. If the user is
7585 * in pro trial(isInProTrial API), then paidSubscriber will always be true as we need to treat user as paid.
7686 * you should use isInProTrial API to check if user is in pro trial if some trial-related logic needs to be done.
7787 * @returns {Promise<Object> } Plan details object
7888 */
7989 async function getPlanDetails ( ) {
80- const entitlements = await LoginService . getEffectiveEntitlements ( ) ;
90+ const entitlements = await _getEffectiveEntitlements ( ) ;
8191
8292 if ( entitlements && entitlements . plan ) {
8393 return entitlements . plan ;
@@ -97,7 +107,7 @@ define(function (require, exports, module) {
97107 * @returns {Promise<boolean> } True if user is in pro trial, false otherwise
98108 */
99109 async function isInProTrial ( ) {
100- const entitlements = await LoginService . getEffectiveEntitlements ( ) ;
110+ const entitlements = await _getEffectiveEntitlements ( ) ;
101111 return ! ! ( entitlements && entitlements . isInProTrial ) ;
102112 }
103113
@@ -106,7 +116,7 @@ define(function (require, exports, module) {
106116 * @returns {Promise<number> } Number of remaining trial days
107117 */
108118 async function getTrialRemainingDays ( ) {
109- const entitlements = await LoginService . getEffectiveEntitlements ( ) ;
119+ const entitlements = await _getEffectiveEntitlements ( ) ;
110120 return entitlements && entitlements . trialDaysRemaining ? entitlements . trialDaysRemaining : 0 ;
111121 }
112122
@@ -142,7 +152,7 @@ define(function (require, exports, module) {
142152 * }
143153 */
144154 async function getLiveEditEntitlement ( ) {
145- const entitlements = await LoginService . getEffectiveEntitlements ( ) ;
155+ const entitlements = await _getEffectiveEntitlements ( ) ;
146156
147157 if ( entitlements && entitlements . entitlements && entitlements . entitlements . liveEdit ) {
148158 return entitlements . entitlements . liveEdit ;
@@ -168,6 +178,7 @@ define(function (require, exports, module) {
168178 LoginService = KernalModeTrust . loginService ;
169179 // Set up event forwarding from LoginService
170180 LoginService . on ( LoginService . EVENT_ENTITLEMENTS_CHANGED , function ( ) {
181+ effectiveEntitlements = null ;
171182 Entitlements . trigger ( EVENT_ENTITLEMENTS_CHANGED ) ;
172183 } ) ;
173184 }
0 commit comments