web-manager 3.1.28 → 3.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/account.js +55 -50
  2. package/package.json +2 -2
package/lib/account.js CHANGED
@@ -1,17 +1,15 @@
1
1
  /*
2
2
  */
3
- var dom;
4
- var utilities;
5
-
6
3
  function Account(init) {
7
4
  var self = this;
5
+
8
6
  init = init || {};
9
7
  self.properties = {};
10
8
  self.accountPageInitialized = false;
11
9
 
12
10
  try {
13
- dom = init.dom || self.Manager.dom();
14
- utilities = init.utilities || self.Manager.utilities();
11
+ self.dom = init.dom || self.Manager.dom();
12
+ self.utilities = init.utilities || self.Manager.utilities();
15
13
 
16
14
  if (new URL(window.location.href).pathname.includes('account')) {
17
15
  self.initializeAccountPage();
@@ -93,10 +91,11 @@ Account.prototype.initializeAccountPage = function (options) {
93
91
 
94
92
  Account.prototype.delete = function (options) {
95
93
  var self = this;
94
+
96
95
  var user = firebase.auth().currentUser;
97
- var errorElement = dom.select('.auth-delete-account-error-message-element');
98
- var confirmValue = dom.select('.auth-delete-account-confirmation-input').getValue()
99
- var deleteButton = dom.select('.auth-delete-account-btn')
96
+ var errorElement = self.dom.select('.auth-delete-account-error-message-element');
97
+ var confirmValue = self.dom.select('.auth-delete-account-confirmation-input').getValue()
98
+ var deleteButton = self.dom.select('.auth-delete-account-btn')
100
99
 
101
100
  deleteButton.setAttribute('disabled', true).addClass('disabled');
102
101
  errorElement.setAttribute('hidden', true);
@@ -115,7 +114,7 @@ Account.prototype.delete = function (options) {
115
114
  } else {
116
115
  user.getIdToken(false)
117
116
  .then(function(token) {
118
- fetch('https://us-central1-' + utilities.get(self.Manager, 'properties.options.libraries.firebase_app.config.projectId', 'unknown') + '.cloudfunctions.net/bm_api', {
117
+ fetch('https://us-central1-' + self.utilities.get(self.Manager, 'properties.options.libraries.firebase_app.config.projectId', 'unknown') + '.cloudfunctions.net/bm_api', {
119
118
  // fetch('http://localhost:5001/optiic-api/us-central1/bm_api', {
120
119
  method: 'POST',
121
120
  headers: { 'Content-Type': 'application/json' },
@@ -173,16 +172,6 @@ Account.prototype.resolve = function (account, options) {
173
172
  });
174
173
  }
175
174
 
176
- function _setAuthItem(selector, value) {
177
- dom.select(selector).each(function(e, i) {
178
- if (e.tagName === 'INPUT') {
179
- dom.select(e).setValue(value);
180
- } else {
181
- dom.select(e).setInnerHTML(value);
182
- }
183
- });
184
- }
185
-
186
175
  function uppercase(str) {
187
176
  return str.charAt(0).toUpperCase() + str.slice(1);
188
177
  }
@@ -221,6 +210,7 @@ Account.prototype._resolveAccount2 = function (firebaseUser, account, options) {
221
210
  */
222
211
  Account.prototype._resolveAccount = function (firebaseUser, account, options) {
223
212
  var self = this;
213
+
224
214
  firebaseUser = firebaseUser || {};
225
215
  account = account || {};
226
216
  options = options || {};
@@ -239,9 +229,17 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
239
229
  // Resolve plan
240
230
  account.plan = account.plan || {};
241
231
  account.plan.id = account.plan.id || defaultPlanId;
232
+
242
233
  account.plan.expires = account.plan.expires || {};
243
234
  account.plan.expires.timestamp = new Date(account.plan.expires.timestamp || 0).toISOString();
244
235
  account.plan.expires.timestampUNIX = Math.round(new Date(account.plan.expires.timestamp || 0).getTime() / 1000);
236
+
237
+ account.plan.trial = account.plan.trial || {};
238
+ account.plan.trial.activated = account.plan.trial.activated || false;
239
+ account.plan.trial.expires = account.plan.trial.expires || {};
240
+ account.plan.trial.expires.timestamp = new Date(account.plan.trial.expires.timestamp || 0).toISOString()
241
+ account.plan.trial.expires.timestampUNIX = Math.round(new Date(account.plan.trial.expires.timestamp || 0).getTime() / 1000);
242
+
245
243
  account.plan.limits = account.plan.limits || {};
246
244
  // account.plan.devices = account.plan.devices || 1;
247
245
 
@@ -266,17 +264,17 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
266
264
  // In a try/catch because this lib is used in node sometimes
267
265
  try {
268
266
  currentURL = new URL(window.location.href);
269
- isDevelopment = utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
267
+ isDevelopment = self.utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
270
268
 
271
- if (utilities.get(isDevelopment)) {
269
+ if (self.utilities.get(isDevelopment)) {
272
270
  currentURL.searchParams
273
271
  .forEach(function(value, key) {
274
- var accountValue = utilities.get(account, key, undefined)
272
+ var accountValue = self.utilities.get(account, key, undefined)
275
273
  if (typeof accountValue !== undefined) {
276
274
  if (value === 'true') { value = true }
277
275
  if (value === 'false') { value = false }
278
276
 
279
- utilities.set(account, key, value)
277
+ self.utilities.set(account, key, value)
280
278
  }
281
279
  });
282
280
  }
@@ -289,7 +287,7 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
289
287
  var planExpireDate = new Date(account.plan.expires.timestamp);
290
288
  var now = new Date();
291
289
  var daysTillExpire = Math.floor((planExpireDate - now) / 86400000);
292
- var difference = (planExpireDate.getTime() - now.getTime())/(24*3600*1000);
290
+ var difference = (planExpireDate.getTime() - now.getTime()) / (24 * 3600 * 1000);
293
291
  var startDate = new Date(account.plan.payment.startDate.timestamp);
294
292
  var planIsActive = difference > -1 && account.plan.id !== defaultPlanId;
295
293
 
@@ -338,14 +336,6 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
338
336
  // Personal
339
337
  account.personal = account.personal || {};
340
338
 
341
- account.personal.name = account.personal.name || {};
342
- account.personal.name.first = account.personal.name.first || '';
343
- account.personal.name.last = account.personal.name.last || '';
344
-
345
- account.personal.telephone = account.personal.telephone || {};
346
- account.personal.telephone.countryCode = account.personal.telephone.countryCode || 0;
347
- account.personal.telephone.national = account.personal.telephone.national || 0;
348
-
349
339
  account.personal.birthday = account.personal.birthday || {};
350
340
  account.personal.birthday.timestamp = account.personal.birthday.timestamp || '1970-01-01T00:00:00.000Z';
351
341
  account.personal.birthday.timestampUNIX = account.personal.birthday.timestampUNIX || 0;
@@ -353,40 +343,56 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
353
343
  account.personal.gender = account.personal.gender || '';
354
344
 
355
345
  account.personal.location = account.personal.location || {};
346
+ account.personal.location.city = account.personal.location.city || '';
356
347
  account.personal.location.country = account.personal.location.country || '';
357
348
 
349
+ account.personal.name = account.personal.name || {};
350
+ account.personal.name.first = account.personal.name.first || '';
351
+ account.personal.name.last = account.personal.name.last || '';
352
+
353
+ account.personal.telephone = account.personal.telephone || {};
354
+ account.personal.telephone.countryCode = account.personal.telephone.countryCode || 0;
355
+ account.personal.telephone.national = account.personal.telephone.national || 0;
358
356
 
359
357
  // Set UI elements
360
358
  // In a try/catch because this lib is used in node sometimes
361
359
  try {
362
- // var apiLinkURL = isDevelopment ? 'http://localhost:5000/discord-link' : 'https://api.{{ site.brand.name }}.com/discord-link';
363
- // var apiUnlinkURL = isDevelopment ? 'http://localhost:5000/discord-unlink' : 'https://api.{{ site.brand.name }}.com/discord-unlink';
364
360
  var cancelURL = isDevelopment ? 'http://localhost:4001/cancel/' : 'https://itwcreativeworks.com/portal/account/manage/';
365
361
 
366
- var billingSubscribeBtn = dom.select('.auth-billing-subscribe-btn');
367
- var billingUpdateBtn = dom.select('.auth-billing-update-btn');
368
- var billingPlanId = dom.select('.auth-billing-plan-id-element');
369
- var billingFrequencyEl = dom.select('.auth-billing-frequency-element');
370
- var billingStartDateEl = dom.select('.auth-billing-start-date-element');
371
- var billingExpirationDateEl = dom.select('.auth-billing-expiration-date-element');
362
+ var billingSubscribeBtn = self.dom.select('.auth-billing-subscribe-btn');
363
+ var billingUpdateBtn = self.dom.select('.auth-billing-update-btn');
364
+ var billingPlanId = self.dom.select('.auth-billing-plan-id-element');
365
+ var billingFrequencyEl = self.dom.select('.auth-billing-frequency-element');
366
+ var billingStartDateEl = self.dom.select('.auth-billing-start-date-element');
367
+ var billingExpirationDateEl = self.dom.select('.auth-billing-expiration-date-element');
372
368
 
373
- var $referralCount = dom.select('.auth-referral-count-element');
374
- var $referralCode = dom.select('.auth-referral-code-element');
375
- var $referralLink = dom.select('.auth-referral-link-element');
376
- var $referralSocialLink = dom.select('a.auth-referral-social-link[data-provider]');
369
+ var $referralCount = self.dom.select('.auth-referral-count-element');
370
+ var $referralCode = self.dom.select('.auth-referral-code-element');
371
+ var $referralLink = self.dom.select('.auth-referral-link-element');
372
+ var $referralSocialLink = self.dom.select('a.auth-referral-social-link[data-provider]');
377
373
 
378
- var authCreatedEl = dom.select('.auth-created-element');
379
- var authPhoneInput = dom.select('.auth-phone-input');
374
+ var authCreatedEl = self.dom.select('.auth-created-element');
375
+ var authPhoneInput = self.dom.select('.auth-phone-input');
380
376
 
381
377
  var updateURL = new URL(cancelURL);
382
378
  var referralURL = new URL(window.location.origin || window.location.host);
383
379
 
380
+ function _setAuthItem(selector, value) {
381
+ self.dom.select(selector).each(function(e, i) {
382
+ if (e.tagName === 'INPUT') {
383
+ self.dom.select(e).setValue(value);
384
+ } else {
385
+ self.dom.select(e).setInnerHTML(value);
386
+ }
387
+ });
388
+ }
389
+
384
390
  referralURL.pathname = '/';
385
391
  referralURL.searchParams.set('aff', account.affiliate.code)
386
392
 
387
393
  authCreatedEl.setInnerHTML(
388
394
  new Date(
389
- parseInt(utilities.get(firebaseUser, 'metadata.a', '0'))
395
+ parseInt(self.utilities.get(firebaseUser, 'metadata.a', '0'))
390
396
  )
391
397
  .toLocaleString(undefined, {
392
398
  weekday: 'long', year: 'numeric', month: 'long', day: 'numeric',
@@ -413,15 +419,14 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
413
419
  ? '<i class="fas fa-exclamation-triangle mr-1"></i> Expires in ' + daysTillExpire + ' days '
414
420
  : '');
415
421
 
416
- _setAuthItem('.auth-apikey-element', utilities.get(account, 'api.privateKey', 'n/a'));
417
-
422
+ _setAuthItem('.auth-apikey-element', self.utilities.get(account, 'api.privateKey', 'n/a'));
418
423
 
419
424
  $referralCount.setInnerHTML(account.affiliate.referrals.length);
420
425
  $referralCode.setInnerHTML(account.affiliate.code).setValue(account.affiliate.code);
421
426
  $referralCode.setInnerHTML(referralURL.toString()).setValue(referralURL.toString());
422
427
 
423
428
  var affiliateLinkURI = encodeURIComponent(referralURL.toString());
424
- var affiliateLinkTextURI = encodeURIComponent('Sign up for ' + utilities.get(self.Manager, 'properties.global.brand.name', 'this') + ', a useful service:');
429
+ var affiliateLinkTextURI = encodeURIComponent('Sign up for ' + self.utilities.get(self.Manager, 'properties.global.brand.name', 'this') + ', a useful service:');
425
430
 
426
431
  $referralSocialLink
427
432
  .each(function ($el) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.1.28",
3
+ "version": "3.1.30",
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": {
@@ -28,4 +28,4 @@
28
28
  "firebase": "^8.10.1",
29
29
  "lazysizes": "^5.3.2"
30
30
  }
31
- }
31
+ }