web-manager 3.1.50 → 3.1.52

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +99 -305
  2. package/lib/account.js +49 -58
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -71,9 +71,6 @@ function Manager() {
71
71
  ready: false,
72
72
  initilizing: false,
73
73
  authReady: false,
74
- masterSWRegistered: false,
75
-
76
- eventHandlersSet: false
77
74
  },
78
75
  // initReady: false,
79
76
  // initSecondaryReady: false,
@@ -111,22 +108,6 @@ function Manager() {
111
108
  safari: '',
112
109
  },
113
110
  validRedirectHosts: [],
114
- // preferences: {
115
- // // firebase: {
116
- // // enabled: false
117
- // // },
118
- // // pushNotifications: {
119
- // // enabled: false
120
- // // },
121
- // // load: {
122
- // // variables: '',
123
- // // functionsFirebase: '',
124
- // // },
125
- // // auth: {
126
- // // prohibitedReturnURL: '',
127
- // // requiredReturnURL: '',
128
- // // },
129
- // },
130
111
  },
131
112
  auth: {
132
113
  user: false
@@ -134,40 +115,12 @@ function Manager() {
134
115
  references: {
135
116
  serviceWorker: undefined
136
117
  },
137
- // firebase: {
138
- // user: {
139
- // exists: false,
140
- // authStateChangeRan: false,
141
- // authObject: {}
142
- // },
143
- // config: {
144
- // apiKey: '',
145
- // authDomain: '',
146
- // databaseURL: '',
147
- // projectId: '',
148
- // storageBucket: '',
149
- // messagingSenderId: '',
150
- // },
151
- // functions: {
152
- // auth: undefined,
153
- // messaging: undefined,
154
- // database: undefined,
155
- // firestore: undefined,
156
- // },
157
- // },
158
118
  meta: {
159
119
  environment: 'production'
160
120
  }
161
121
  };
162
122
 
163
123
  try {
164
- // set(this, 'properties.options.page', pageOptions);
165
- // set(this, 'properties.options.global', globalOptions);
166
- // set(this, 'properties.global.domain', document.location.hostname);
167
- // set(this, 'properties.page.url', document.location.href);
168
- // this.properties.options.page = pageOptions || {};
169
- // this.properties.options.global = globalOptions || {};]
170
- // this.properties.global.urlRoot = window.location.protocol + '//' + window.location.hostname;
171
124
  this.properties.page.url = window.location.href;
172
125
  } catch (e) {
173
126
 
@@ -192,56 +145,49 @@ function Manager() {
192
145
  Manager.prototype.setEventListeners = function() {
193
146
  var This = this;
194
147
 
195
- if (!utilities.get(this, 'properties.page.status.eventHandlersSet', false)) {
196
- this.properties.page.status.eventHandlersSet = true;
197
-
198
- document.addEventListener('click', function (event) {
199
- // auth events
200
- if (event.target.matches('.auth-signin-email-btn')) {
201
- This.auth().signIn('email');
202
- } else if (event.target.matches('.auth-signup-email-btn')) {
203
- This.auth().signUp('email');
204
- } else if (event.target.matches('.auth-signin-provider-btn')) {
205
- This.auth().signIn(event.target.getAttribute('data-provider'));
206
- } else if (event.target.matches('.auth-signup-provider-btn')) {
207
- This.auth().signUp(event.target.getAttribute('data-provider'));
208
- } else if (event.target.matches('.auth-signout-all-btn')) {
209
- This.auth().signOut();
210
- } else if (event.target.matches('.auth-forgot-email-btn')) {
211
- This.auth().forgot();
212
- } else if (event.target.matches('#prechat-btn')) {
213
- load_chatsy(This, This.properties.options);
214
- } else if (event.target.matches('.auth-subscribe-notifications-btn')) {
148
+ // Setup click handler
149
+ document.addEventListener('click', function (event) {
150
+ // auth events
151
+ if (event.target.matches('.auth-signin-email-btn')) {
152
+ This.auth().signIn('email');
153
+ } else if (event.target.matches('.auth-signup-email-btn')) {
154
+ This.auth().signUp('email');
155
+ } else if (event.target.matches('.auth-signin-provider-btn')) {
156
+ This.auth().signIn(event.target.getAttribute('data-provider'));
157
+ } else if (event.target.matches('.auth-signup-provider-btn')) {
158
+ This.auth().signUp(event.target.getAttribute('data-provider'));
159
+ } else if (event.target.matches('.auth-signout-all-btn')) {
160
+ This.auth().signOut();
161
+ } else if (event.target.matches('.auth-forgot-email-btn')) {
162
+ This.auth().forgot();
163
+ } else if (event.target.matches('#prechat-btn')) {
164
+ load_chatsy(This, This.properties.options);
165
+ } else if (event.target.matches('.auth-subscribe-notifications-btn')) {
166
+ This.notifications().subscribe()
167
+ }
168
+
169
+ // Autorequest
170
+ if (!This._notificationRequested && This.properties.options.pushNotifications.autoRequest) {
171
+ This._notificationRequested = true;
172
+
173
+ setTimeout(function () {
215
174
  This.notifications().subscribe()
216
- }
175
+ }, This.properties.options.pushNotifications.autoRequest * 1000);
176
+ }
217
177
 
218
- // Autorequest
219
- if (!This._notificationRequested && This.properties.options.pushNotifications.autoRequest) {
220
- This._notificationRequested = true;
178
+ });
221
179
 
222
- setTimeout(function () {
223
- This.notifications().subscribe()
224
- }, This.properties.options.pushNotifications.autoRequest * 1000);
225
- }
180
+ // Mouse leave event
181
+ document.addEventListener('mouseleave', function() {
182
+ showExitPopup(This);
183
+ });
226
184
 
227
- }, false);
228
- }
185
+ // Window blur event
186
+ window.addEventListener('blur', function() {
187
+ showExitPopup(This);
188
+ });
229
189
  }
230
190
 
231
- // Requires firebase auth to be determined
232
- // function _setupTokenRefreshHandler(This) {
233
- // // console.log('_setupTokenRefreshHandler', This.properties.page.status.authReady);
234
- // if (This.properties.page.status.authReady) {
235
- // return firebase.messaging().onTokenRefresh(
236
- // handleTokenRefresh(This)
237
- // .catch(function (e) {
238
- // console.error(e);
239
- // })
240
- // );
241
- // }
242
- // setTimeout(function () {_setupTokenRefreshHandler(This)}, 300);
243
- // }
244
-
245
191
  function _authStateHandler(This, user) {
246
192
  // This.log('----authStateHandler', user);
247
193
  if (user) {
@@ -337,9 +283,7 @@ function Manager() {
337
283
  }
338
284
 
339
285
  function _authHandle_out(This) {
340
- // This.log('_authHandle_out: ', This.properties.options.auth.state);
341
286
  if (This.properties.options.auth.state === 'required') {
342
- // window.location.href = This.query().create(This.properties.options.auth.sends.required).set('auth_redirect', encodeURIComponent(window.location.href)).getUrl();
343
287
  var sendSplit = This.properties.options.auth.sends.required.split('?');
344
288
  var newQuery = new URLSearchParams(sendSplit[1]);
345
289
  newQuery.set('auth_redirect', window.location.href);
@@ -415,70 +359,8 @@ function Manager() {
415
359
  // }
416
360
  }
417
361
  }
418
-
419
362
  }
420
363
 
421
- // navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
422
- // // Let's see if you have a subscription already
423
- // console.log('&&& GET SUB');
424
- // return serviceWorkerRegistration.pushManager.getSubscription();
425
- // })
426
- // .then(function(subscription) {
427
- // if (!subscription) {
428
- // // You do not have subscription
429
- // console.log('&&& NO SUBSCRIPTION');
430
- // } else {
431
- // console.log('&&& YES SUBSCRIPTION');
432
- //
433
- // }
434
- //
435
- // // You have subscription.
436
- // // Send data to service worker
437
- // // navigator.serviceWorker.controller.postMessage({'data': dataToServiceWorker});
438
- //
439
- // })
440
-
441
- // navigator.serviceWorker.ready.then(() => {
442
- // // I thought the page would be controlled at this point, thanks to clients.claim()
443
- // console.log('.ready resolved, and navigator.serviceWorker.controller is', navigator.serviceWorker.controller);
444
- // navigator.serviceWorker.addEventListener('controllerchange', () => {
445
- // console.log('Okay, now things are under control. navigator.serviceWorker.controller is', navigator.serviceWorker.controller);
446
- // });
447
- // });
448
-
449
- // Manager.prototype.init = async function() {
450
- // Manager.prototype.init = function() {
451
- // if ((get(this, 'properties.page.status.ready', false) == false) && ((get(this, 'properties.page.status.initializing', false) == false))) {
452
- // set(this, 'properties.page.status.initializing', true);
453
- // console.log('INIT Called');
454
- // // await wait(300,100);
455
- // console.log('INIT finished waiting');
456
- // // this.testFunction();
457
- //
458
- // // setup
459
- // this.setEventListeners();
460
- //
461
- // // make sure firebase etc is loaded and elements on page are updated to reflect user's auth status
462
- // // also update properties so that it reflects whether the user is logged inspect
463
- //
464
- // // check that navigator exists
465
- //
466
- // //check local storage exists
467
- //
468
- // // parse query string
469
- //
470
- // // add cookie thing with settings
471
- // // _ready = true;
472
- // set(this, 'properties.page.status.initializing', false);
473
- // set(this, 'properties.page.status.ready', true);
474
- //
475
- // }
476
- //
477
- // return new Promise((resolve, reject) => {
478
- // resolve(true);
479
- // });
480
- // }
481
-
482
364
  // init with polyfills
483
365
  Manager.prototype.init = function(configuration, callback) {
484
366
  var This = this;
@@ -499,7 +381,6 @@ function Manager() {
499
381
  init_loadPolyfills(This, configuration, function() {
500
382
  This.properties.page.status.initializing = false;
501
383
  // This.properties.genericPromise = new Promise(resolve => { resolve() });
502
- var tempUrl = This.properties.global.url;
503
384
  var options_defaults = {
504
385
  // debug: {
505
386
  // environment: This.properties.meta.environment,
@@ -519,18 +400,20 @@ function Manager() {
519
400
  auth: {
520
401
  state: 'default', // required, prohibited, default
521
402
  sends: {
522
- required: tempUrl + '/signup/',
523
- prohibited: tempUrl + '/',
403
+ required: '/signup/',
404
+ prohibited: '/',
524
405
  },
525
406
  },
526
- popup: {
407
+ exitPopup: {
527
408
  enabled: true,
528
409
  config: {
529
- title: '',
530
- message: '',
531
- btn_ok: {
532
- text: '',
533
- link: '',
410
+ timeout: 3600000,
411
+ handler: null,
412
+ title: 'Special Offer!',
413
+ message: 'Get 15% off your purchase of our <strong>Premium plans</strong>. <br><br> Get access to all features and unlimited usage.',
414
+ okButton: {
415
+ text: 'Claim 15% Discount',
416
+ link: '/pricing?utm_source=exitpopup&utm_medium=popup&utm_campaign=exitpopup',
534
417
  },
535
418
  },
536
419
  },
@@ -609,11 +492,9 @@ function Manager() {
609
492
  type: '',
610
493
  showLink: false,
611
494
  content: {
612
- message: 'We use cookies to ensure you get the best experience on our website. By continuing to use the site, you agree to our<a href="' + tempUrl + '/terms/" class="cc-link" style="padding-right: 0">terms of service</a>.',
613
- dismiss: 'Got it!',
614
- // link: 'Learn more',
615
- // href: '' || This.properties.global.urlRoot + '/cookies/',
616
- // href: (tempUrl + '/cookies/')
495
+ message: 'We use cookies to ensure you get the best experience on our website. By continuing to use the site, you agree to our<a href="/terms/" class="cc-link" style="padding-right: 0">terms of service</a>.',
496
+ // dismiss: 'Got it!',
497
+ dismiss: 'I understand',
617
498
  },
618
499
  },
619
500
  },
@@ -753,7 +634,6 @@ function Manager() {
753
634
  return;
754
635
  }
755
636
 
756
- // console.log('HERE 0');
757
637
  Promise.all([
758
638
  load_sentry(This, options_user),
759
639
  load_firebase(This, options_user),
@@ -762,46 +642,8 @@ function Manager() {
762
642
  postCrucial();
763
643
  })
764
644
  .catch(function (e) {
765
- //@@@ LOG TO SENTRY HERE?
766
645
  console.error('Lib error', e);
767
- // postCrucial();
768
646
  })
769
- // console.log('HERE 0');
770
- // Promise.all([
771
- // load_sentry(This, options_user),
772
- // load_firebase(This, options_user),
773
- // ])
774
- // .then(function() {
775
- // console.log('HERE 5');
776
- //
777
- // // handle firebase user
778
- // if (firebase.auth) {
779
- // firebase.auth().onAuthStateChanged(function(user) {
780
- // This.properties.page.status.authReady = true;
781
- // This.properties.auth.user = user || false;
782
- // _authStateHandler(This, user);
783
- // })
784
- // }
785
- //
786
- // // setup
787
- // This.setEventListeners();
788
- //
789
- // // run the init callback
790
- // This.properties.page.status.ready = true;
791
- // callback();
792
- //
793
- // // loan non-critical libraries
794
- // load_lazysizes(This, options_user);
795
- // load_cookieconsent(This, options_user);
796
- // subscriptionManager(This, options_user);
797
- //
798
- // This.log('Manager ', This);
799
- // return;
800
- // })
801
- // .catch(function (e) {
802
- // console.log('E', e);
803
- // })
804
-
805
647
  })
806
648
 
807
649
  } else {
@@ -810,38 +652,6 @@ function Manager() {
810
652
 
811
653
  }
812
654
 
813
- // Manager.prototype.subscribeToPushNotifications = function(options) {
814
- // if ((typeof firebase.messaging !== 'undefined')) {
815
- // return firebase.messaging().requestPermission()
816
- // .then(() => checkSubscription())
817
- // .catch((err) => {
818
- // console.error(err);
819
- // });
820
- // }
821
- // }
822
- // Sentry.configureScope(scope => {
823
- // scope.setExtra('battery', 0.7);
824
- // scope.setTag('user_mode', 'admin');
825
- // scope.setUser({ id: '4711' });
826
- // // scope.clear();
827
- // });
828
- //
829
- // // Add a breadcrumb for future events
830
- // Sentry.addBreadcrumb({
831
- // message: 'My Breadcrumb',
832
- // // ...
833
- // });
834
- //
835
- // // Capture exceptions, messages or manual events
836
- // Sentry.captureMessage('Hello, world!');
837
- // Sentry.captureException(new Error('Good bye'));
838
- // Sentry.captureEvent({
839
- // message: 'Manual',
840
- // stacktrace: [
841
- // // ...
842
- // ],
843
- // });
844
-
845
655
  Manager.prototype.sentry = function() {
846
656
  // var en = (Sentry && Sentry)
847
657
  return {
@@ -864,12 +674,6 @@ function Manager() {
864
674
  };
865
675
  }
866
676
 
867
- // function _postAuthSubscriptionCheck() {
868
- // return new Promise(function(resolve, reject) {
869
- //
870
- // });
871
- // }
872
-
873
677
  Manager.prototype.auth = function() {
874
678
  var This = this;
875
679
  var firebaseActive = typeof firebase !== 'undefined';
@@ -883,28 +687,6 @@ function Manager() {
883
687
  select(erel).hide().setInnerHTML('');
884
688
  }
885
689
 
886
- // function signinButtonDisabled(status) {
887
- // if (status) {
888
- // select('.auth-signin-email-btn').setAttribute('disabled', true);
889
- // } else {
890
- // select('.auth-signin-email-btn').removeAttribute('disabled');
891
- // }
892
- // }
893
- // function signupButtonDisabled(status) {
894
- // if (status) {
895
- // select('.auth-signup-email-btn').setAttribute('disabled', true);
896
- // } else {
897
- // select('.auth-signup-email-btn').removeAttribute('disabled');
898
- // }
899
- // }
900
- // function forgotButtonDisabled(status) {
901
- // if (status) {
902
- // select('.auth-forgot-email-btn').setAttribute('disabled', true);
903
- // } else {
904
- // select('.auth-forgot-email-btn').removeAttribute('disabled');
905
- // }
906
- // }
907
-
908
690
  function setAuthButtonDisabled(button, status) {
909
691
  var el = select('.auth-' + button + '-email-btn');
910
692
  var disabled = 'disabled';
@@ -1211,21 +993,6 @@ function Manager() {
1211
993
  }
1212
994
  }
1213
995
 
1214
- // function handleTokenRefresh(This) {
1215
- // This.log('handleTokenRefresh()');
1216
- // return new Promise(function(resolve, reject) {
1217
- // var notifications = This.notifications();
1218
- // notifications.isSubscribed()
1219
- // .then(function (result) {
1220
- // if (result) {
1221
- // return resolve(This.notifications().subscribe());
1222
- // } else {
1223
- // return resolve();
1224
- // }
1225
- // })
1226
- // });
1227
- // }
1228
-
1229
996
  /*
1230
997
  HELPERS
1231
998
  */
@@ -1233,13 +1000,21 @@ function Manager() {
1233
1000
  if (!('serviceWorker' in navigator) || !(typeof firebase.messaging !== 'undefined')) {return}
1234
1001
 
1235
1002
  // service worker guide: https://developers.google.com/web/updates/2018/06/fresher-sw
1236
- navigator.serviceWorker.register('/' + (options_user.serviceWorker.path || 'master-service-worker.js') + '?config=' + encodeURIComponent(JSON.stringify({name: This.properties.global.brand.name, app: This.properties.global.app, env: This.properties.meta.environment, v: This.properties.global.version, cb: This.properties.global.cacheBreaker, firebase: options_user.libraries.firebase_app.config})) )
1003
+ navigator.serviceWorker.register(
1004
+ '/' + (options_user.serviceWorker.path || 'master-service-worker.js')
1005
+ + '?config=' + encodeURIComponent(JSON.stringify({
1006
+ name: This.properties.global.brand.name,
1007
+ app: This.properties.global.app,
1008
+ env: This.properties.meta.environment,
1009
+ v: This.properties.global.version,
1010
+ cb: This.properties.global.cacheBreaker,
1011
+ firebase: options_user.libraries.firebase_app.config
1012
+ }))
1013
+ )
1237
1014
  .then(function (registration) {
1238
1015
  // firebase.messaging().useServiceWorker(registration);
1239
- // console.log('----TEST registration', registration);
1240
1016
  This.properties.references.serviceWorker = registration;
1241
- // console.log('====registration', registration);
1242
- // console.log('navigator.serviceWorker.controller', navigator.serviceWorker.controller);
1017
+
1243
1018
  // TODO: https://googlechrome.github.io/samples/service-worker/post-message/
1244
1019
  // --- leverage this example ^^^ for caching! It's grat and you can do one page at a time through postMessage!
1245
1020
 
@@ -1273,10 +1048,6 @@ function Manager() {
1273
1048
  // }
1274
1049
  // listenForWaitingServiceWorker(registration, promptUserToRefresh);
1275
1050
 
1276
- // registration.update();
1277
- This.properties.page.status.masterSWRegistered = true;
1278
-
1279
-
1280
1051
  // This.log('SW Registered.');
1281
1052
  //@@@NOTIFICATIONS
1282
1053
  // _setupTokenRefreshHandler(This);
@@ -1284,14 +1055,12 @@ function Manager() {
1284
1055
  try {
1285
1056
  // Normally, notifications are not displayed when user is ON PAGE but we will display it here anyway
1286
1057
  firebase.messaging().onMessage(function (payload) {
1287
- // console.log('---payload', payload);
1288
1058
  new Notification(payload.notification.title, payload.notification)
1289
1059
  .onclick = function(event) {
1290
1060
  event.preventDefault(); // prevent the browser from focusing the Notification's tab
1291
1061
  window.open(payload.notification.click_action, '_blank');
1292
1062
  }
1293
1063
  })
1294
- // console.log('---SKIPPING ONMESSAGE');
1295
1064
  } catch (e) {
1296
1065
  console.error(e);
1297
1066
  }
@@ -1307,7 +1076,44 @@ function Manager() {
1307
1076
  // });
1308
1077
  }
1309
1078
 
1079
+ function showExitPopup(This) {
1080
+ var exitPopupSettings = This.properties.options.exitPopup;
1081
+
1082
+ if (!exitPopupSettings.enabled) return;
1083
+
1084
+ var lastTriggered = new Date(storage.get('exitPopup.lastTriggered', 0));
1085
+ var now = new Date();
1086
+ var diff = now - lastTriggered;
1087
+
1088
+ if (diff < exitPopupSettings.config.timeout) return;
1089
+
1090
+ showBootstrapModal(exitPopupSettings);
1091
+
1092
+ storage.set('exitPopup.lastTriggered', now.toISOString());
1093
+ }
1094
+
1095
+ function showBootstrapModal(exitPopupSettings) {
1096
+ var proceed = exitPopupSettings.config.handler
1097
+ ? exitPopupSettings.config.handler()
1098
+ : true;
1099
+
1100
+ if (!proceed) { return }
1101
+
1102
+ var $el = document.getElementById('modal-exit-popup');
1103
+ var modal = new bootstrap.Modal($el);
1104
+ modal.show();
1105
+ $el.removeAttribute('hidden');
1310
1106
 
1107
+ var $title = $el.querySelector('.modal-title');
1108
+ var $message = $el.querySelector('.modal-body');
1109
+ var $okButton = $el.querySelector('.modal-footer .btn-primary');
1110
+ var config = exitPopupSettings.config;
1111
+
1112
+ $title.innerHTML = config.title;
1113
+ $message.innerHTML = config.message;
1114
+ $okButton.innerHTML = config.okButton.text;
1115
+ $okButton.setAttribute('href', config.okButton.link);
1116
+ }
1311
1117
 
1312
1118
  /*
1313
1119
  EXTERNAL LIBS
@@ -1589,17 +1395,6 @@ function Manager() {
1589
1395
  }
1590
1396
  }
1591
1397
 
1592
- // Manager.prototype.time = function(mode, name) {
1593
- // console.log('&&& called time ', mode, name);
1594
- // if (this.properties.meta.environment == 'development') {
1595
- // if (mode == 'start') {
1596
- // console.time(name);
1597
- // } else {
1598
- // console.timeEnd(name);
1599
- // }
1600
- // }
1601
- // }
1602
-
1603
1398
  function init_loadPolyfills(This, configuration, cb) {
1604
1399
  // https://github.com/jquintozamora/polyfill-io-feature-detection/blob/master/index.js
1605
1400
  var featuresDefault = (
@@ -1612,7 +1407,6 @@ function Manager() {
1612
1407
  } else {
1613
1408
  loadScript({src: 'https://polyfill.io/v3/polyfill.min.js?flags=always%2Cgated&features=default%2Ces5%2Ces6%2Ces7%2CPromise.prototype.finally%2C%7Ehtml5-elements%2ClocalStorage%2Cfetch%2CURLSearchParams'})
1614
1409
  .then(function() {
1615
- // This.log('Loaded polyfill.io')
1616
1410
  cb();
1617
1411
  })
1618
1412
  }
package/lib/account.js CHANGED
@@ -17,61 +17,6 @@ function Account(init) {
17
17
  } catch (e) {
18
18
  console.error('Failed to initialize libraries');
19
19
  }
20
-
21
- // var pastDate = new Date(0);
22
- // self.properties = {
23
- // auth: {
24
- // uid: _.get(settings, 'auth.uid', null),
25
- // email: _.get(settings, 'auth.email', null),
26
- // temporary: _.get(settings, 'auth.temporary', useDefaults ? false : null),
27
- // },
28
- // roles: {
29
- // admin: _.get(settings, 'roles.admin', useDefaults ? false : null),
30
- // betaTester: _.get(settings, 'roles.betaTester', useDefaults ? false : null),
31
- // developer: _.get(settings, 'roles.developer', useDefaults ? false : null),
32
- // },
33
- // plan: {
34
- // id: _.get(settings, 'plan.id', useDefaults ? 'basic' : null), // intro | basic | advanced | premium
35
- // expires: {
36
- // timestamp: _.get(settings, 'plan.expires.timestamp', useDefaults ? oldDate : null),
37
- // timestampUNIX: _.get(settings, 'plan.expires.timestampUNIX', useDefaults ? oldDateUNIX : null),
38
- // },
39
- // limits: {
40
- // devices: _.get(settings, 'plan.limits.devices', useDefaults ? 1 : null),
41
- // },
42
- // payment: {
43
- // processor: _.get(settings, 'plan.payment.processor', null), // paypal | stripe | chargebee, etc
44
- // orderId: _.get(settings, 'plan.payment.orderId', null), // xxx-xxx-xxx
45
- // resourceId: _.get(settings, 'plan.payment.resourceId', null), // x-xxxxxx
46
- // frequency: _.get(settings, 'plan.payment.frequency', null), // monthly || annually
47
- // startDate: {
48
- // timestamp: _.get(settings, 'plan.payment.startDate.timestamp', useDefaults ? now : null), // x-xxxxxx
49
- // timestampUNIX: _.get(settings, 'plan.payment.startDate.timestampUNIX', useDefaults ? nowUNIX : null), // x-xxxxxx
50
- // }
51
- // }
52
- // },
53
- // affiliate: {
54
- // code: _.get(settings, 'affiliate.code', useDefaults ? shortid.generate() : null),
55
- // referrals: {
56
- //
57
- // },
58
- // referrer: _.get(settings, 'affiliate.referrer', null),
59
- // },
60
- // activity: {
61
- // lastActivity: {
62
- // timestamp: _.get(settings, 'activity.lastActivity.timestamp', useDefaults ? now : null),
63
- // timestampUNIX: _.get(settings, 'activity.lastActivity.timestampUNIX', useDefaults ? nowUNIX : null),
64
- // },
65
- // created: {
66
- // timestamp: _.get(settings, 'activity.created.timestamp', useDefaults ? now : null),
67
- // timestampUNIX: _.get(settings, 'activity.created.timestampUNIX', useDefaults ? nowUNIX : null),
68
- // },
69
- // },
70
- // api: {
71
- // clientId: _.get(settings, 'api.clientId', useDefaults ? `${uuid4()}` : null),
72
- // privateKey: _.get(settings, 'api.privateKey', useDefaults ? `${uidgen.generateSync()}` : null),
73
- // },
74
- // }
75
20
  }
76
21
 
77
22
  Account.prototype.initializeAccountPage = function (options) {
@@ -83,7 +28,7 @@ Account.prototype.initializeAccountPage = function (options) {
83
28
  if (event.target.matches('.auth-delete-account-btn')) {
84
29
  self.delete().catch(function (e) {});
85
30
  }
86
- }, false)
31
+ })
87
32
 
88
33
  self.accountPageInitialized = true;
89
34
 
@@ -160,18 +105,64 @@ Account.prototype.resolve = function (account, options) {
160
105
 
161
106
  // If there is no user logged in or we choose not to fetch the account, resolve a default account
162
107
  if (!currentUser || !currentUser.uid || options.fetchNewAccount === false) {
163
- return resolve(self._resolveAccount(currentUser, account, options));
108
+ return resolve(
109
+ self.handleAccount(
110
+ self._resolveAccount(currentUser, account, options)
111
+ )
112
+ );
164
113
  }
165
114
 
166
115
  // Otherwise, fetch the account from the database and resolve it
167
116
  firebase.firestore().doc('users/' + currentUser.uid)
168
117
  .get()
169
118
  .then(function (doc) {
170
- return resolve(self._resolveAccount(currentUser, doc.data(), options));
119
+ return resolve(
120
+ self.handleAccount(
121
+ self._resolveAccount(currentUser, doc.data(), options)
122
+ )
123
+ );
171
124
  })
172
125
  });
173
126
  }
174
127
 
128
+ Account.prototype.handleAccount = function (account) {
129
+ var self = this;
130
+
131
+ // Handle plans
132
+ handlePlanVisibility(account.plan.id);
133
+
134
+ // Handle others
135
+ // ...
136
+
137
+ return account;
138
+ }
139
+
140
+ function handlePlanVisibility(planId) {
141
+ var elements = document.querySelectorAll('[data-plan-id]');
142
+
143
+ // Initially hide all elements
144
+ elements.forEach(function(element) {
145
+ element.setAttribute('hidden', true);
146
+ });
147
+
148
+ // Toggle visibility based on plan
149
+ elements.forEach(function(element) {
150
+ var requiredPlans = element.getAttribute('data-plan-id').split(',');
151
+ var visibility = element.getAttribute('data-plan-visibility') || 'visible';
152
+
153
+ var shouldBeVisible = false;
154
+
155
+ // Special case for '$paid'
156
+ if (requiredPlans.includes('$paid')) {
157
+ shouldBeVisible = (planId !== 'basic');
158
+ } else {
159
+ shouldBeVisible = (requiredPlans.includes(planId));
160
+ }
161
+
162
+ element.setAttribute('hidden', shouldBeVisible ? (visibility === 'hidden') : (visibility === 'visible'));
163
+ });
164
+ }
165
+
175
166
  function uppercase(str) {
176
167
  return str.charAt(0).toUpperCase() + str.slice(1);
177
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.1.50",
3
+ "version": "3.1.52",
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": {
@@ -36,4 +36,4 @@
36
36
  "firebase": "^9.23.0",
37
37
  "lazysizes": "^5.3.2"
38
38
  }
39
- }
39
+ }