web-manager 2.1.27 → 2.1.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/lib/account.js +50 -41
  2. package/package.json +1 -1
package/lib/account.js CHANGED
@@ -158,14 +158,14 @@ Account.prototype.resolve = function (account, options) {
158
158
  firebase.firestore().doc('users/' + currentUser.uid)
159
159
  .get()
160
160
  .then(function (doc) {
161
- return resolve(_resolveAccount(self, currentUser, doc.data(), options));
161
+ return resolve(self._resolveAccount(currentUser, doc.data(), options));
162
162
  })
163
163
  .catch(reject)
164
164
  } else {
165
165
  if (!currentUser) {
166
166
  return reject(new Error('No currently authenticated user'))
167
167
  }
168
- return resolve(_resolveAccount(self, currentUser, account, options));
168
+ return resolve(self._resolveAccount(currentUser, account, options));
169
169
  }
170
170
  });
171
171
  }
@@ -190,7 +190,8 @@ function getMonth(date) {
190
190
  return monthNames[date.getMonth()];
191
191
  }
192
192
 
193
- function _resolveAccount(self, currentUser, account, options) {
193
+ Account.prototype._resolveAccount = function (currentUser, account, options) {
194
+ var self = this;
194
195
  account = account || {};
195
196
  options = options || {};
196
197
 
@@ -224,49 +225,17 @@ function _resolveAccount(self, currentUser, account, options) {
224
225
 
225
226
  var planExpireDate = new Date(account.plan.expires.timestamp);
226
227
  var now = new Date();
227
- var daysTillExpire = Math.floor(( planExpireDate - now ) / 86400000);
228
+ var daysTillExpire = Math.floor((planExpireDate - now) / 86400000);
228
229
  let difference = (planExpireDate.getTime() - now.getTime())/(24*3600*1000);
229
230
  var startDate = new Date(account.plan.payment.startDate.timestamp);
231
+ var planIsActive = difference > -1 && account.plan.id !== defaultPlanId;
230
232
 
231
- var isDevelopment = utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
232
- // var apiLinkURL = isDevelopment ? 'http://localhost:5000/discord-link' : 'https://api.{{ site.brand.name }}.com/discord-link';
233
- // var apiUnlinkURL = isDevelopment ? 'http://localhost:5000/discord-unlink' : 'https://api.{{ site.brand.name }}.com/discord-unlink';
234
- var cancelURL = isDevelopment ? 'http://localhost:4001/cancel/' : 'https://itwcreativeworks.com/portal/account/manage/';
235
-
236
- var billingSubscribeBtn = dom.select('.auth-billing-subscribe-btn');
237
- var billingUpdateBtn = dom.select('.auth-billing-update-btn');
238
- var billingPlanId = dom.select('.auth-billing-plan-id-element');
239
- var billingFrequencyEl = dom.select('.auth-billing-frequency-element');
240
- var billingStartDateEl = dom.select('.auth-billing-start-date-element');
241
- var billingExpirationDateEl = dom.select('.auth-billing-expiration-date-element');
242
- var updateURL = new URL(cancelURL);
243
- var currentURL = new URL(window.location.href);
244
-
245
- billingSubscribeBtn.setAttribute('hidden', true);
246
- billingUpdateBtn.setAttribute('hidden', true);
247
-
248
- if (difference > -1 && account.plan.id !== defaultPlanId) {
233
+ if (planIsActive) {
249
234
  account.plan.id = account.plan.id;
250
- updateURL.searchParams.set('appName', utilities.get(self.Manager, 'properties.global.brand.name', 'Unknown'));
251
- updateURL.searchParams.set('supportUrl', currentURL.origin + '/support');
252
- updateURL.searchParams.set('supportEmail', utilities.get(self.Manager, 'properties.contact.emailSupport', 'unknown@email.com'));
253
- updateURL.searchParams.set('userEmail', currentUser.email);
254
- updateURL.searchParams.set('userId', currentUser.uid);
255
- updateURL.searchParams.set('orderId', account.plan.payment.orderId);
256
- updateURL.searchParams.set('resourceId', account.plan.payment.resourceId);
257
- billingUpdateBtn.removeAttribute('hidden').setAttribute('href', updateURL.toString());
258
235
  } else {
259
236
  account.plan.id = defaultPlanId;
260
- billingSubscribeBtn.removeAttribute('hidden');
261
237
  }
262
238
 
263
- billingPlanId.setInnerHTML(uppercase(account.plan.id));
264
- billingFrequencyEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' (billed ' + uppercase(account.plan.payment.frequency) + ')' : '');
265
- billingStartDateEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' - Purchased ' + getMonth(startDate) + ' ' + startDate.getDate() + ', ' + startDate.getFullYear() : '');
266
- billingExpirationDateEl.setInnerHTML(account.plan.id !== defaultPlanId && daysTillExpire < 366
267
- ? '<i class="fas fa-exclamation-triangle mr-1"></i> Expires in ' + daysTillExpire + ' days '
268
- : '');
269
-
270
239
  // Resolve oAuth2
271
240
  account.oauth2 = account.oauth2 || {};
272
241
  account.oauth2.discord = account.oauth2.discord || {};
@@ -280,10 +249,50 @@ function _resolveAccount(self, currentUser, account, options) {
280
249
  account.roles.vip = account.roles.vip === true || account.roles.vip === 'true';
281
250
  account.roles.promoExempt = account.roles.promoExempt === true || account.roles.promoExempt === 'true';
282
251
 
283
- self.properties = account;
284
-
285
252
  // Set UI elements
286
- _setAuthItem('.auth-apikey-element', utilities.get(account, 'api.privateKey', 'n/a'))
253
+ try {
254
+ var isDevelopment = utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
255
+ // var apiLinkURL = isDevelopment ? 'http://localhost:5000/discord-link' : 'https://api.{{ site.brand.name }}.com/discord-link';
256
+ // var apiUnlinkURL = isDevelopment ? 'http://localhost:5000/discord-unlink' : 'https://api.{{ site.brand.name }}.com/discord-unlink';
257
+ var cancelURL = isDevelopment ? 'http://localhost:4001/cancel/' : 'https://itwcreativeworks.com/portal/account/manage/';
258
+
259
+ var billingSubscribeBtn = dom.select('.auth-billing-subscribe-btn');
260
+ var billingUpdateBtn = dom.select('.auth-billing-update-btn');
261
+ var billingPlanId = dom.select('.auth-billing-plan-id-element');
262
+ var billingFrequencyEl = dom.select('.auth-billing-frequency-element');
263
+ var billingStartDateEl = dom.select('.auth-billing-start-date-element');
264
+ var billingExpirationDateEl = dom.select('.auth-billing-expiration-date-element');
265
+ var updateURL = new URL(cancelURL);
266
+ var currentURL = new URL(window.location.href);
267
+
268
+ billingSubscribeBtn.setAttribute('hidden', true);
269
+ billingUpdateBtn.setAttribute('hidden', true);
270
+
271
+ if (planIsActive) {
272
+ updateURL.searchParams.set('appName', utilities.get(self.Manager, 'properties.global.brand.name', 'Unknown'));
273
+ updateURL.searchParams.set('supportUrl', currentURL.origin + '/support');
274
+ updateURL.searchParams.set('supportEmail', utilities.get(self.Manager, 'properties.contact.emailSupport', 'unknown@email.com'));
275
+ updateURL.searchParams.set('userEmail', currentUser.email);
276
+ updateURL.searchParams.set('userId', currentUser.uid);
277
+ updateURL.searchParams.set('orderId', account.plan.payment.orderId);
278
+ updateURL.searchParams.set('resourceId', account.plan.payment.resourceId);
279
+ billingUpdateBtn.removeAttribute('hidden').setAttribute('href', updateURL.toString());
280
+ } else {
281
+ billingSubscribeBtn.removeAttribute('hidden');
282
+ }
283
+
284
+ billingPlanId.setInnerHTML(uppercase(account.plan.id));
285
+ billingFrequencyEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' (billed ' + uppercase(account.plan.payment.frequency) + ')' : '');
286
+ billingStartDateEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' - Purchased ' + getMonth(startDate) + ' ' + startDate.getDate() + ', ' + startDate.getFullYear() : '');
287
+ billingExpirationDateEl.setInnerHTML(account.plan.id !== defaultPlanId && daysTillExpire < 366
288
+ ? '<i class="fas fa-exclamation-triangle mr-1"></i> Expires in ' + daysTillExpire + ' days '
289
+ : '');
290
+
291
+ _setAuthItem('.auth-apikey-element', utilities.get(account, 'api.privateKey', 'n/a'))
292
+ } catch (e) {
293
+ console.error('Unable to set DOM elements', e);
294
+ }
295
+ self.properties = account;
287
296
 
288
297
  return self.properties;
289
298
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "2.1.27",
3
+ "version": "2.1.28",
4
4
  "description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
5
5
  "main": "index.js",
6
6
  "scripts": {