web-manager 3.1.51 → 3.1.53
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +228 -178
- package/lib/account.js +9 -3
- package/package.json +2 -2
package/index.js
CHANGED
@@ -43,23 +43,13 @@ function ieVersion() {
|
|
43
43
|
}
|
44
44
|
|
45
45
|
function Manager() {
|
46
|
+
var self = this;
|
47
|
+
var iev = ieVersion();
|
48
|
+
|
46
49
|
/**
|
47
50
|
* OPTIONS
|
48
51
|
*/
|
49
|
-
|
50
|
-
// var parseDELETE = function (req) {
|
51
|
-
// var result;
|
52
|
-
// try {
|
53
|
-
// result = JSON.parse(req.responseText);
|
54
|
-
// } catch (e) {
|
55
|
-
// result = req.responseText;
|
56
|
-
// }
|
57
|
-
// return [result, req];
|
58
|
-
// };
|
59
|
-
|
60
|
-
// var t1 = '16'; //@@@ Delete later
|
61
|
-
iev = ieVersion();
|
62
|
-
this.properties = {
|
52
|
+
self.properties = {
|
63
53
|
options: {
|
64
54
|
page: {},
|
65
55
|
global: {},
|
@@ -76,8 +66,8 @@ function Manager() {
|
|
76
66
|
// initSecondaryReady: false,
|
77
67
|
queryString: {},
|
78
68
|
// libErrors: [],
|
79
|
-
isSupportedBrowser: (!iev || iev >= 11) // https://makandracards.com/makandra/53475-minimal-javascript-function-to-detect-version-of-internet-explorer-or-edge
|
80
|
-
|
69
|
+
isSupportedBrowser: (!iev || iev >= 11), // https://makandracards.com/makandra/53475-minimal-javascript-function-to-detect-version-of-internet-explorer-or-edge
|
70
|
+
startTime: new Date(),
|
81
71
|
// auth: {
|
82
72
|
// status: undefined,
|
83
73
|
// lastAction: 'unknown',
|
@@ -121,93 +111,97 @@ function Manager() {
|
|
121
111
|
};
|
122
112
|
|
123
113
|
try {
|
124
|
-
|
114
|
+
self.properties.page.url = window.location.href;
|
125
115
|
} catch (e) {
|
126
116
|
|
127
117
|
}
|
128
118
|
|
129
|
-
select =
|
130
|
-
loadScript =
|
131
|
-
store =
|
119
|
+
select = self.dom().select;
|
120
|
+
loadScript = self.dom().loadScript;
|
121
|
+
store = self.storage();
|
132
122
|
}
|
133
123
|
|
134
124
|
/**
|
135
125
|
* METHODS
|
136
126
|
*/
|
137
127
|
Manager.prototype.get = function(path) {
|
138
|
-
|
128
|
+
var self = this;
|
129
|
+
|
130
|
+
return utilities.get(self, 'properties.' + path);
|
139
131
|
}
|
140
132
|
|
141
133
|
Manager.prototype.set = function(path, value) {
|
142
|
-
|
134
|
+
var self = this;
|
135
|
+
|
136
|
+
return utilities.set(self, 'properties.' + path, value);
|
143
137
|
}
|
144
138
|
|
145
139
|
Manager.prototype.setEventListeners = function() {
|
146
|
-
var
|
140
|
+
var self = this;
|
147
141
|
|
148
142
|
// Setup click handler
|
149
143
|
document.addEventListener('click', function (event) {
|
150
144
|
// auth events
|
151
145
|
if (event.target.matches('.auth-signin-email-btn')) {
|
152
|
-
|
146
|
+
self.auth().signIn('email');
|
153
147
|
} else if (event.target.matches('.auth-signup-email-btn')) {
|
154
|
-
|
148
|
+
self.auth().signUp('email');
|
155
149
|
} else if (event.target.matches('.auth-signin-provider-btn')) {
|
156
|
-
|
150
|
+
self.auth().signIn(event.target.getAttribute('data-provider'));
|
157
151
|
} else if (event.target.matches('.auth-signup-provider-btn')) {
|
158
|
-
|
152
|
+
self.auth().signUp(event.target.getAttribute('data-provider'));
|
159
153
|
} else if (event.target.matches('.auth-signout-all-btn')) {
|
160
|
-
|
154
|
+
self.auth().signOut();
|
161
155
|
} else if (event.target.matches('.auth-forgot-email-btn')) {
|
162
|
-
|
156
|
+
self.auth().forgot();
|
163
157
|
} else if (event.target.matches('#prechat-btn')) {
|
164
|
-
load_chatsy(
|
158
|
+
load_chatsy(self, self.properties.options);
|
165
159
|
} else if (event.target.matches('.auth-subscribe-notifications-btn')) {
|
166
|
-
|
160
|
+
self.notifications().subscribe()
|
167
161
|
}
|
168
162
|
|
169
163
|
// Autorequest
|
170
|
-
if (!
|
171
|
-
|
164
|
+
if (!self._notificationRequested && self.properties.options.pushNotifications.autoRequest) {
|
165
|
+
self._notificationRequested = true;
|
172
166
|
|
173
167
|
setTimeout(function () {
|
174
|
-
|
175
|
-
},
|
168
|
+
self.notifications().subscribe()
|
169
|
+
}, self.properties.options.pushNotifications.autoRequest * 1000);
|
176
170
|
}
|
177
171
|
|
178
172
|
});
|
179
173
|
|
180
174
|
// Mouse leave event
|
181
175
|
document.addEventListener('mouseleave', function() {
|
182
|
-
showExitPopup(
|
176
|
+
showExitPopup(self);
|
183
177
|
});
|
184
178
|
|
185
179
|
// Window blur event
|
186
180
|
window.addEventListener('blur', function() {
|
187
|
-
showExitPopup(
|
181
|
+
showExitPopup(self);
|
188
182
|
});
|
189
183
|
}
|
190
184
|
|
191
|
-
function _authStateHandler(
|
192
|
-
//
|
185
|
+
function _authStateHandler(self, user) {
|
186
|
+
// self.log('----authStateHandler', user);
|
193
187
|
if (user) {
|
194
188
|
if (!user.isAnonymous) {
|
195
|
-
_authHandle_in(
|
189
|
+
_authHandle_in(self, user);
|
196
190
|
|
197
|
-
|
191
|
+
self.notifications().subscribe().catch(function (e) {
|
198
192
|
console.error(e);
|
199
193
|
});
|
200
194
|
} else {
|
201
|
-
_authHandle_out(
|
195
|
+
_authHandle_out(self);
|
202
196
|
}
|
203
197
|
} else {
|
204
|
-
_authHandle_out(
|
198
|
+
_authHandle_out(self);
|
205
199
|
}
|
206
200
|
}
|
207
201
|
|
208
|
-
function _authHandle_in(
|
209
|
-
//
|
210
|
-
// if (
|
202
|
+
function _authHandle_in(self, user) {
|
203
|
+
// self.log('_authHandle_in', user);
|
204
|
+
// if (self.properties.page.status.didSignUp) {
|
211
205
|
var done;
|
212
206
|
var hoursSinceCreation = Math.abs(new Date() - new Date(+user.metadata.createdAt)) / 36e5;
|
213
207
|
|
@@ -215,7 +209,7 @@ function Manager() {
|
|
215
209
|
if (!done) {
|
216
210
|
done = true;
|
217
211
|
store.set('didSignUp', true)
|
218
|
-
_authHandle_in_normal(
|
212
|
+
_authHandle_in_normal(self, user);
|
219
213
|
}
|
220
214
|
}
|
221
215
|
|
@@ -223,7 +217,7 @@ function Manager() {
|
|
223
217
|
user.getIdToken(false)
|
224
218
|
.then(function(token) {
|
225
219
|
|
226
|
-
fetch('https://us-central1-' +
|
220
|
+
fetch('https://us-central1-' + self.properties.options.libraries.firebase_app.config.projectId + '.cloudfunctions.net/bm_api', {
|
227
221
|
method: 'POST',
|
228
222
|
body: JSON.stringify({
|
229
223
|
authenticationToken: token,
|
@@ -254,14 +248,14 @@ function Manager() {
|
|
254
248
|
|
255
249
|
|
256
250
|
|
257
|
-
function _authHandle_in_normal(
|
258
|
-
var returnUrl =
|
259
|
-
if (returnUrl &&
|
251
|
+
function _authHandle_in_normal(self, user) {
|
252
|
+
var returnUrl = self.properties.page.queryString.get('auth_redirect');
|
253
|
+
if (returnUrl && self.isValidRedirectUrl(returnUrl)) {
|
260
254
|
window.location.href = decodeURIComponent(returnUrl);
|
261
255
|
return;
|
262
256
|
}
|
263
|
-
if (
|
264
|
-
window.location.href =
|
257
|
+
if (self.properties.options.auth.state === 'prohibited') {
|
258
|
+
window.location.href = self.properties.options.auth.sends.prohibited;
|
265
259
|
return;
|
266
260
|
}
|
267
261
|
select('.auth-signedin-true-element').show();
|
@@ -282,9 +276,9 @@ function Manager() {
|
|
282
276
|
});
|
283
277
|
}
|
284
278
|
|
285
|
-
function _authHandle_out(
|
286
|
-
if (
|
287
|
-
var sendSplit =
|
279
|
+
function _authHandle_out(self) {
|
280
|
+
if (self.properties.options.auth.state === 'required') {
|
281
|
+
var sendSplit = self.properties.options.auth.sends.required.split('?');
|
288
282
|
var newQuery = new URLSearchParams(sendSplit[1]);
|
289
283
|
newQuery.set('auth_redirect', window.location.href);
|
290
284
|
window.location.href = sendSplit[0] + '?' + newQuery.toString();
|
@@ -296,8 +290,9 @@ function Manager() {
|
|
296
290
|
}
|
297
291
|
|
298
292
|
Manager.prototype.ready = function(fn, options) {
|
299
|
-
var
|
293
|
+
var self = this;
|
300
294
|
var waitFor = true;
|
295
|
+
|
301
296
|
options = options || {};
|
302
297
|
options.interval = options.interval || 100;
|
303
298
|
|
@@ -305,24 +300,26 @@ function Manager() {
|
|
305
300
|
|
306
301
|
if (!utilities.get(this, 'properties.page.status.ready', false) || !waitFor) {
|
307
302
|
setTimeout(function () {
|
308
|
-
|
303
|
+
self.ready(fn, options);
|
309
304
|
}, options.interval);
|
310
305
|
} else {
|
311
306
|
// Performance
|
312
|
-
|
307
|
+
self.performance().mark('manager_ready');
|
313
308
|
|
314
309
|
return fn();
|
315
310
|
}
|
316
311
|
}
|
317
312
|
|
318
313
|
Manager.prototype.serviceWorker = function() {
|
319
|
-
var
|
314
|
+
var self = this;
|
320
315
|
var SWAvailable = 'serviceWorker' in navigator;
|
316
|
+
|
321
317
|
if (SWAvailable) {
|
322
318
|
try {
|
323
|
-
var swref =
|
319
|
+
var swref = self.properties.references.serviceWorker.active || navigator.serviceWorker.controller;
|
324
320
|
} catch (e) {}
|
325
321
|
}
|
322
|
+
|
326
323
|
return {
|
327
324
|
postMessage: function() {
|
328
325
|
// var args = getArgs(arguments);
|
@@ -343,9 +340,9 @@ function Manager() {
|
|
343
340
|
}
|
344
341
|
|
345
342
|
// if (!navigator.serviceWorker.controller) {
|
346
|
-
//
|
343
|
+
// self.log('postMessage...');
|
347
344
|
// setTimeout(function () {
|
348
|
-
//
|
345
|
+
// self.serviceWorker().postMessage(args[0], args[1]);
|
349
346
|
// }, 100);
|
350
347
|
// } else {
|
351
348
|
// // post message: https://stackoverflow.com/questions/30177782/chrome-serviceworker-postmessage
|
@@ -363,27 +360,32 @@ function Manager() {
|
|
363
360
|
|
364
361
|
// init with polyfills
|
365
362
|
Manager.prototype.init = function(configuration, callback) {
|
366
|
-
var
|
367
|
-
|
363
|
+
var self = this;
|
364
|
+
var status = self.properties.page.status;
|
365
|
+
|
366
|
+
if (
|
367
|
+
!status.ready
|
368
|
+
&& !status.initilizing
|
369
|
+
) {
|
368
370
|
|
369
371
|
// Performance
|
370
|
-
|
372
|
+
self.performance().mark('manager_init');
|
371
373
|
|
372
374
|
// set initializing to true
|
373
|
-
|
375
|
+
self.properties.page.status.initializing = true;
|
374
376
|
|
375
377
|
// set other properties
|
376
|
-
|
378
|
+
self.properties.meta.environment = window.location.host.match(/:40|ngrok/)
|
377
379
|
? 'development'
|
378
380
|
: 'production';
|
379
381
|
|
380
382
|
// Load polyfills
|
381
|
-
init_loadPolyfills(
|
382
|
-
|
383
|
-
//
|
383
|
+
init_loadPolyfills(self, configuration, function() {
|
384
|
+
self.properties.page.status.initializing = false;
|
385
|
+
// self.properties.genericPromise = new Promise(resolve => { resolve() });
|
384
386
|
var options_defaults = {
|
385
387
|
// debug: {
|
386
|
-
// environment:
|
388
|
+
// environment: self.properties.meta.environment,
|
387
389
|
// },
|
388
390
|
// queryString: {
|
389
391
|
// saveToStorage: false
|
@@ -523,27 +525,27 @@ function Manager() {
|
|
523
525
|
}
|
524
526
|
|
525
527
|
eachRecursive(options_defaults);
|
526
|
-
|
528
|
+
self.properties.options = options_user;
|
527
529
|
|
528
530
|
// set non-option properties
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
531
|
+
self.properties.global.app = configuration.global.app;
|
532
|
+
self.properties.global.version = configuration.global.version;
|
533
|
+
self.properties.global.url = configuration.global.url;
|
534
|
+
self.properties.global.cacheBreaker = configuration.global.cacheBreaker;
|
533
535
|
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
536
|
+
self.properties.global.brand = configuration.global.brand;
|
537
|
+
self.properties.global.contact = configuration.global.contact;
|
538
|
+
self.properties.global.download = configuration.global.download;
|
539
|
+
self.properties.global.extension = configuration.global.extension;
|
538
540
|
|
539
|
-
|
540
|
-
|
541
|
-
|
541
|
+
self.properties.global.validRedirectHosts = configuration.global.validRedirectHosts;
|
542
|
+
self.properties.meta.environment = utilities.get(configuration, 'global.settings.debug.environment', self.properties.meta.environment);
|
543
|
+
self.properties.page.queryString = new URLSearchParams(window.location.search);
|
542
544
|
|
543
545
|
var pagePathname = window.location.pathname;
|
544
546
|
var redirect = false;
|
545
547
|
|
546
|
-
|
548
|
+
self.properties.page.queryString.forEach(function(value, key) {
|
547
549
|
if (key.startsWith('utm_')) {
|
548
550
|
store.set('utm.tags.' + key, value);
|
549
551
|
store.set('utm.timestamp', new Date().toISOString());
|
@@ -559,7 +561,7 @@ function Manager() {
|
|
559
561
|
}
|
560
562
|
})
|
561
563
|
|
562
|
-
if (redirect &&
|
564
|
+
if (redirect && self.isValidRedirectUrl(redirect)) {
|
563
565
|
return window.location.href = redirect;
|
564
566
|
}
|
565
567
|
|
@@ -577,18 +579,18 @@ function Manager() {
|
|
577
579
|
// handle firebase user
|
578
580
|
if (typeof firebase !== 'undefined' && firebase.auth) {
|
579
581
|
firebase.auth().onAuthStateChanged(function(user) {
|
580
|
-
|
581
|
-
|
582
|
-
_authStateHandler(
|
582
|
+
self.properties.page.status.authReady = true;
|
583
|
+
self.properties.auth.user = user || false;
|
584
|
+
_authStateHandler(self, user);
|
583
585
|
})
|
584
586
|
}
|
585
587
|
|
586
588
|
// setup
|
587
|
-
|
589
|
+
self.setEventListeners();
|
588
590
|
|
589
591
|
// display outdated if it is
|
590
592
|
try {
|
591
|
-
if (!
|
593
|
+
if (!self.properties.page.isSupportedBrowser) {
|
592
594
|
var box = document.getElementsByClassName('master-alert-outdated')[0];
|
593
595
|
box.style.display = 'block';
|
594
596
|
document.body.insertBefore(box, document.body.firstChild);
|
@@ -596,7 +598,7 @@ function Manager() {
|
|
596
598
|
} catch (e) {}
|
597
599
|
|
598
600
|
// run the init callback
|
599
|
-
|
601
|
+
self.properties.page.status.ready = true;
|
600
602
|
|
601
603
|
try {
|
602
604
|
callback();
|
@@ -626,17 +628,17 @@ function Manager() {
|
|
626
628
|
}
|
627
629
|
|
628
630
|
// load non-critical libraries
|
629
|
-
load_lazysizes(
|
630
|
-
load_cookieconsent(
|
631
|
-
subscriptionManager(
|
631
|
+
load_lazysizes(self, options_user);
|
632
|
+
load_cookieconsent(self, options_user);
|
633
|
+
subscriptionManager(self, options_user);
|
632
634
|
|
633
|
-
//
|
635
|
+
// self.log('Manager', self);
|
634
636
|
return;
|
635
637
|
}
|
636
638
|
|
637
639
|
Promise.all([
|
638
|
-
load_sentry(
|
639
|
-
load_firebase(
|
640
|
+
load_sentry(self, options_user),
|
641
|
+
load_firebase(self, options_user),
|
640
642
|
])
|
641
643
|
.then(function() {
|
642
644
|
postCrucial();
|
@@ -675,7 +677,7 @@ function Manager() {
|
|
675
677
|
}
|
676
678
|
|
677
679
|
Manager.prototype.auth = function() {
|
678
|
-
var
|
680
|
+
var self = this;
|
679
681
|
var firebaseActive = typeof firebase !== 'undefined';
|
680
682
|
var erel = '.auth-error-message-element';
|
681
683
|
|
@@ -717,17 +719,17 @@ function Manager() {
|
|
717
719
|
ready: function (fn, options) {
|
718
720
|
options = options || {};
|
719
721
|
options.interval = options.interval || 100;
|
720
|
-
// if ( (
|
722
|
+
// if ( (self.get('page.status.authReady', false) === false) ) {
|
721
723
|
// Manager.log('--- authReady() REAL');
|
722
|
-
if (!utilities.get(
|
724
|
+
if (!utilities.get(self, 'properties.page.status.authReady', false)) {
|
723
725
|
setTimeout(function () {
|
724
|
-
|
726
|
+
self.auth().ready(fn, options);
|
725
727
|
}, options.interval);
|
726
728
|
} else {
|
727
729
|
|
728
730
|
// Set up listener for redirect (for provider login)
|
729
|
-
if (!
|
730
|
-
|
731
|
+
if (!self._redirectResultSetup) {
|
732
|
+
self._redirectResultSetup = true;
|
731
733
|
firebase.auth()
|
732
734
|
.getRedirectResult()
|
733
735
|
.catch(function (error) {
|
@@ -736,16 +738,16 @@ function Manager() {
|
|
736
738
|
}
|
737
739
|
|
738
740
|
// Performance
|
739
|
-
|
741
|
+
self.performance().mark('manager_authReady');
|
740
742
|
|
741
|
-
return fn(
|
743
|
+
return fn(self.auth().getUser());
|
742
744
|
}
|
743
745
|
},
|
744
746
|
signIn: function (method, email, password) {
|
745
747
|
var mode = 'signin';
|
746
748
|
method = method || 'email';
|
747
749
|
_preDisplayError();
|
748
|
-
//
|
750
|
+
// self.log('Signin attempt: ', method, email, password);
|
749
751
|
if (method === 'email') {
|
750
752
|
// email = (email || select('.auth-email-input').getValue()).trim().toLowerCase();
|
751
753
|
email = resolveAuthInput(email, mode, 'email');
|
@@ -758,20 +760,20 @@ function Manager() {
|
|
758
760
|
|
759
761
|
firebase.auth().signInWithEmailAndPassword(email, password)
|
760
762
|
.then(function(credential) {
|
761
|
-
// _postAuthSubscriptionCheck(
|
763
|
+
// _postAuthSubscriptionCheck(self)
|
762
764
|
// .then(function () {
|
763
765
|
//
|
764
766
|
// })
|
765
|
-
|
767
|
+
self.properties.page.status.didSignIn = true;
|
766
768
|
// signinButtonDisabled(false);
|
767
769
|
setAuthButtonDisabled(mode, false);
|
768
|
-
//
|
770
|
+
// self.log('Good signin');
|
769
771
|
})
|
770
772
|
.catch(function(error) {
|
771
773
|
// signinButtonDisabled(false);
|
772
774
|
setAuthButtonDisabled(mode, false);
|
773
775
|
_displayError(error.message);
|
774
|
-
//
|
776
|
+
// self.log('Error', error.message);
|
775
777
|
});
|
776
778
|
} else {
|
777
779
|
firebase.auth().signInWithRedirect(new firebase.auth.OAuthProvider(method))
|
@@ -785,7 +787,7 @@ function Manager() {
|
|
785
787
|
method = method || 'email';
|
786
788
|
|
787
789
|
_preDisplayError();
|
788
|
-
//
|
790
|
+
// self.log('Signup attempt: ', method, email, password, passwordConfirm);
|
789
791
|
// var acceptedTerms
|
790
792
|
// var termEl = select('.auth-terms-input');
|
791
793
|
// if (termEl.exists() && !termEl.getValue() === true) {
|
@@ -814,43 +816,43 @@ function Manager() {
|
|
814
816
|
setAuthButtonDisabled(mode, true);
|
815
817
|
firebase.auth().createUserWithEmailAndPassword(email, password)
|
816
818
|
.then(function(credential) {
|
817
|
-
//
|
818
|
-
//
|
819
|
+
// self.properties.page.status.didSignUp = true;
|
820
|
+
// self.log('Good signup');
|
819
821
|
// signupButtonDisabled(false);
|
820
822
|
})
|
821
823
|
.catch(function(error) {
|
822
824
|
// signupButtonDisabled(false);
|
823
825
|
setAuthButtonDisabled(mode, false);
|
824
826
|
_displayError(error.message);
|
825
|
-
//
|
827
|
+
// self.log('error', error.message);
|
826
828
|
});
|
827
829
|
} else {
|
828
830
|
_displayError("Passwords don't match.");
|
829
831
|
}
|
830
832
|
} else {
|
831
|
-
|
833
|
+
self.auth().signIn(method);
|
832
834
|
}
|
833
835
|
|
834
836
|
},
|
835
837
|
signOut: function() {
|
836
|
-
//
|
837
|
-
// var
|
838
|
+
// self.log('signOut()');
|
839
|
+
// var self = this;
|
838
840
|
return firebase.auth().signOut()
|
839
841
|
.catch(function(e) {
|
840
842
|
console.error(e);
|
841
|
-
//
|
843
|
+
// self.log('signOut failed: ', error);
|
842
844
|
});
|
843
845
|
// return firebase.auth().signOut()
|
844
846
|
// .then(function() {
|
845
|
-
// //
|
847
|
+
// // self.log('signOut success.');
|
846
848
|
// })
|
847
849
|
// .catch(function(e) {
|
848
850
|
// // console.error(e);
|
849
|
-
// //
|
851
|
+
// // self.log('signOut failed: ', error);
|
850
852
|
// });
|
851
853
|
},
|
852
854
|
forgot: function(email) {
|
853
|
-
//
|
855
|
+
// self.log('forgot()');
|
854
856
|
var mode = 'forgot';
|
855
857
|
// email = email || select('.auth-email-input').getValue();
|
856
858
|
email = resolveAuthInput(email, mode, 'email')
|
@@ -863,13 +865,13 @@ function Manager() {
|
|
863
865
|
.then(function() {
|
864
866
|
// forgotButtonDisabled(false);
|
865
867
|
setAuthButtonDisabled(mode, false);
|
866
|
-
//
|
868
|
+
// self.log('forgot success.');
|
867
869
|
_displayError('A reset link has been sent to you.');
|
868
870
|
})
|
869
871
|
.catch(function(error) {
|
870
872
|
// forgotButtonDisabled(false);
|
871
873
|
setAuthButtonDisabled(mode, false);
|
872
|
-
//
|
874
|
+
// self.log('forgot failed: ', error);
|
873
875
|
_displayError(error.message);
|
874
876
|
});
|
875
877
|
},
|
@@ -879,28 +881,29 @@ function Manager() {
|
|
879
881
|
|
880
882
|
//@@@NOTIFICATIONS
|
881
883
|
Manager.prototype.notifications = function(options) {
|
884
|
+
var self = this;
|
882
885
|
var supported = (typeof firebase.messaging !== 'undefined') && ('serviceWorker' in navigator) && ('Notification' in window);
|
883
|
-
|
886
|
+
|
884
887
|
return {
|
885
888
|
isSubscribed: function () {
|
886
|
-
//
|
889
|
+
// self.log('isSubscribed()');
|
887
890
|
return new Promise(function(resolve, reject) {
|
888
891
|
if (!supported || Notification.permission !== 'granted') {return resolve(false)};
|
889
892
|
return resolve(true);
|
890
893
|
})
|
891
894
|
},
|
892
895
|
subscribe: function () {
|
893
|
-
//
|
896
|
+
// self.log('subscribe()');
|
894
897
|
return new Promise(function(resolve, reject) {
|
895
|
-
// var subscribed = !
|
898
|
+
// var subscribed = !self.notifications().isSubscribed();
|
896
899
|
if (!supported) {
|
897
900
|
return resolve(false)
|
898
901
|
}
|
899
902
|
firebase.messaging().getToken({
|
900
|
-
serviceWorkerRegistration:
|
903
|
+
serviceWorkerRegistration: self.properties.references.serviceWorker,
|
901
904
|
})
|
902
905
|
.then(function (token) {
|
903
|
-
var user =
|
906
|
+
var user = self.auth().getUser();
|
904
907
|
var localSubscription = store.get('notifications', {});
|
905
908
|
var localHash = localSubscription.token + '|' + localSubscription.uid;
|
906
909
|
var userHash = token + '|' + user.uid;
|
@@ -920,14 +923,14 @@ function Manager() {
|
|
920
923
|
|
921
924
|
function saveLocal() {
|
922
925
|
// console.log('---------saveLocal');
|
923
|
-
//
|
926
|
+
// self.log('Saved local token: ', token);
|
924
927
|
store.set('notifications', {uid: user.uid, token: token, lastSynced: timestamp});
|
925
928
|
}
|
926
929
|
|
927
930
|
function saveServer(doc) {
|
928
|
-
// console.log('-------saveServer', !doc.exists, !
|
931
|
+
// console.log('-------saveServer', !doc.exists, !self.utilities().get(doc.data(), 'link.user.data.uid', ''), user.uid);
|
929
932
|
// Run if it (DOES NOT EXIST on server) OR (it does AND the uid field is null AND the current user is not null)
|
930
|
-
if (!doc.exists || (doc.exists && !
|
933
|
+
if (!doc.exists || (doc.exists && !self.utilities().get(doc.data(), 'link.user.data.uid', '') && user.uid)) {
|
931
934
|
subscriptionRef
|
932
935
|
.set(
|
933
936
|
{
|
@@ -959,13 +962,13 @@ function Manager() {
|
|
959
962
|
}
|
960
963
|
)
|
961
964
|
.then(function(data) {
|
962
|
-
//
|
965
|
+
// self.log('Updated token: ', token);
|
963
966
|
saveLocal();
|
964
967
|
resolve(true);
|
965
968
|
})
|
966
969
|
} else {
|
967
970
|
saveLocal();
|
968
|
-
//
|
971
|
+
// self.log('Skip sync, server data exists.');
|
969
972
|
resolve(false);
|
970
973
|
}
|
971
974
|
}
|
@@ -980,7 +983,7 @@ function Manager() {
|
|
980
983
|
saveServer({exists: false})
|
981
984
|
})
|
982
985
|
} else {
|
983
|
-
//
|
986
|
+
// self.log('Skip sync, recently done.');
|
984
987
|
resolve(false);
|
985
988
|
}
|
986
989
|
|
@@ -996,24 +999,24 @@ function Manager() {
|
|
996
999
|
/*
|
997
1000
|
HELPERS
|
998
1001
|
*/
|
999
|
-
function subscriptionManager(
|
1002
|
+
function subscriptionManager(self, options_user) {
|
1000
1003
|
if (!('serviceWorker' in navigator) || !(typeof firebase.messaging !== 'undefined')) {return}
|
1001
1004
|
|
1002
1005
|
// service worker guide: https://developers.google.com/web/updates/2018/06/fresher-sw
|
1003
1006
|
navigator.serviceWorker.register(
|
1004
1007
|
'/' + (options_user.serviceWorker.path || 'master-service-worker.js')
|
1005
1008
|
+ '?config=' + encodeURIComponent(JSON.stringify({
|
1006
|
-
name:
|
1007
|
-
app:
|
1008
|
-
env:
|
1009
|
-
v:
|
1010
|
-
cb:
|
1009
|
+
name: self.properties.global.brand.name,
|
1010
|
+
app: self.properties.global.app,
|
1011
|
+
env: self.properties.meta.environment,
|
1012
|
+
v: self.properties.global.version,
|
1013
|
+
cb: self.properties.global.cacheBreaker,
|
1011
1014
|
firebase: options_user.libraries.firebase_app.config
|
1012
1015
|
}))
|
1013
1016
|
)
|
1014
1017
|
.then(function (registration) {
|
1015
1018
|
// firebase.messaging().useServiceWorker(registration);
|
1016
|
-
|
1019
|
+
self.properties.references.serviceWorker = registration;
|
1017
1020
|
|
1018
1021
|
// TODO: https://googlechrome.github.io/samples/service-worker/post-message/
|
1019
1022
|
// --- leverage this example ^^^ for caching! It's grat and you can do one page at a time through postMessage!
|
@@ -1048,9 +1051,9 @@ function Manager() {
|
|
1048
1051
|
// }
|
1049
1052
|
// listenForWaitingServiceWorker(registration, promptUserToRefresh);
|
1050
1053
|
|
1051
|
-
//
|
1054
|
+
// self.log('SW Registered.');
|
1052
1055
|
//@@@NOTIFICATIONS
|
1053
|
-
// _setupTokenRefreshHandler(
|
1056
|
+
// _setupTokenRefreshHandler(self);
|
1054
1057
|
|
1055
1058
|
try {
|
1056
1059
|
// Normally, notifications are not displayed when user is ON PAGE but we will display it here anyway
|
@@ -1076,8 +1079,8 @@ function Manager() {
|
|
1076
1079
|
// });
|
1077
1080
|
}
|
1078
1081
|
|
1079
|
-
function showExitPopup(
|
1080
|
-
var exitPopupSettings =
|
1082
|
+
function showExitPopup(self) {
|
1083
|
+
var exitPopupSettings = self.properties.options.exitPopup;
|
1081
1084
|
|
1082
1085
|
if (!exitPopupSettings.enabled) return;
|
1083
1086
|
|
@@ -1102,6 +1105,7 @@ function Manager() {
|
|
1102
1105
|
var $el = document.getElementById('modal-exit-popup');
|
1103
1106
|
var modal = new bootstrap.Modal($el);
|
1104
1107
|
modal.show();
|
1108
|
+
$el.removeAttribute('hidden');
|
1105
1109
|
|
1106
1110
|
var $title = $el.querySelector('.modal-title');
|
1107
1111
|
var $message = $el.querySelector('.modal-body');
|
@@ -1112,13 +1116,12 @@ function Manager() {
|
|
1112
1116
|
$message.innerHTML = config.message;
|
1113
1117
|
$okButton.innerHTML = config.okButton.text;
|
1114
1118
|
$okButton.setAttribute('href', config.okButton.link);
|
1115
|
-
|
1116
1119
|
}
|
1117
1120
|
|
1118
1121
|
/*
|
1119
1122
|
EXTERNAL LIBS
|
1120
1123
|
*/
|
1121
|
-
var load_firebase = function(
|
1124
|
+
var load_firebase = function(self, options) {
|
1122
1125
|
return new Promise(function(resolve, reject) {
|
1123
1126
|
// if (typeof window.firebase !== 'undefined') {
|
1124
1127
|
// return resolve();
|
@@ -1126,21 +1129,21 @@ function Manager() {
|
|
1126
1129
|
var setting = options.libraries.firebase_app
|
1127
1130
|
if (setting.enabled === true) {
|
1128
1131
|
function _post() {
|
1129
|
-
//
|
1132
|
+
// self.log('Loaded Firebase.');
|
1130
1133
|
// console.log('_post.');
|
1131
1134
|
window.app = firebase.initializeApp(setting.config);
|
1132
1135
|
|
1133
1136
|
Promise.all([
|
1134
|
-
load_firebase_auth(
|
1135
|
-
load_firebase_firestore(
|
1136
|
-
load_firebase_messaging(
|
1137
|
-
load_firebase_appCheck(
|
1137
|
+
load_firebase_auth(self, options),
|
1138
|
+
load_firebase_firestore(self, options),
|
1139
|
+
load_firebase_messaging(self, options),
|
1140
|
+
load_firebase_appCheck(self, options),
|
1138
1141
|
])
|
1139
1142
|
.then(resolve)
|
1140
1143
|
.catch(reject);
|
1141
1144
|
}
|
1142
1145
|
if (setting.load) {
|
1143
|
-
setting.load(
|
1146
|
+
setting.load(self)
|
1144
1147
|
.then(_post)
|
1145
1148
|
.catch(reject);
|
1146
1149
|
} else {
|
@@ -1159,7 +1162,7 @@ function Manager() {
|
|
1159
1162
|
}
|
1160
1163
|
|
1161
1164
|
|
1162
|
-
var load_firebase_auth = function(
|
1165
|
+
var load_firebase_auth = function(self, options) {
|
1163
1166
|
return new Promise(function(resolve, reject) {
|
1164
1167
|
// if (typeof utilities.get(window, 'firebase.auth', undefined) !== 'undefined') {
|
1165
1168
|
// return resolve();
|
@@ -1167,7 +1170,7 @@ function Manager() {
|
|
1167
1170
|
var setting = options.libraries.firebase_auth;
|
1168
1171
|
if (setting.enabled === true) {
|
1169
1172
|
if (setting.load) {
|
1170
|
-
setting.load(
|
1173
|
+
setting.load(self)
|
1171
1174
|
.then(resolve)
|
1172
1175
|
.catch(reject);
|
1173
1176
|
} else {
|
@@ -1184,7 +1187,7 @@ function Manager() {
|
|
1184
1187
|
}
|
1185
1188
|
|
1186
1189
|
|
1187
|
-
var load_firebase_firestore = function(
|
1190
|
+
var load_firebase_firestore = function(self, options) {
|
1188
1191
|
return new Promise(function(resolve, reject) {
|
1189
1192
|
// if (typeof utilities.get(window, 'firebase.firestore', undefined) !== 'undefined') {
|
1190
1193
|
// return resolve();
|
@@ -1192,7 +1195,7 @@ function Manager() {
|
|
1192
1195
|
var setting = options.libraries.firebase_firestore;
|
1193
1196
|
if (setting.enabled === true) {
|
1194
1197
|
if (setting.load) {
|
1195
|
-
setting.load(
|
1198
|
+
setting.load(self)
|
1196
1199
|
.then(resolve)
|
1197
1200
|
.catch(reject);
|
1198
1201
|
} else {
|
@@ -1207,7 +1210,7 @@ function Manager() {
|
|
1207
1210
|
});
|
1208
1211
|
}
|
1209
1212
|
|
1210
|
-
var load_firebase_messaging = function(
|
1213
|
+
var load_firebase_messaging = function(self, options) {
|
1211
1214
|
return new Promise(function(resolve, reject) {
|
1212
1215
|
// if (typeof utilities.get(window, 'firebase.messaging', undefined) !== 'undefined') {
|
1213
1216
|
// return resolve();
|
@@ -1215,7 +1218,7 @@ function Manager() {
|
|
1215
1218
|
var setting = options.libraries.firebase_messaging;
|
1216
1219
|
if (setting.enabled === true) {
|
1217
1220
|
if (setting.load) {
|
1218
|
-
setting.load(
|
1221
|
+
setting.load(self)
|
1219
1222
|
.then(resolve)
|
1220
1223
|
.catch(reject);
|
1221
1224
|
} else {
|
@@ -1230,12 +1233,12 @@ function Manager() {
|
|
1230
1233
|
});
|
1231
1234
|
}
|
1232
1235
|
|
1233
|
-
var load_firebase_appCheck = function(
|
1236
|
+
var load_firebase_appCheck = function(self, options) {
|
1234
1237
|
return new Promise(function(resolve, reject) {
|
1235
1238
|
var setting = options.libraries.firebase_appCheck;
|
1236
1239
|
if (setting.enabled === true) {
|
1237
1240
|
if (setting.load) {
|
1238
|
-
setting.load(
|
1241
|
+
setting.load(self)
|
1239
1242
|
.then(resolve)
|
1240
1243
|
.catch(reject);
|
1241
1244
|
} else {
|
@@ -1264,7 +1267,7 @@ function Manager() {
|
|
1264
1267
|
});
|
1265
1268
|
}
|
1266
1269
|
|
1267
|
-
var load_lazysizes = function(
|
1270
|
+
var load_lazysizes = function(self, options) {
|
1268
1271
|
return new Promise(function(resolve, reject) {
|
1269
1272
|
// if (typeof window.lazysizes !== 'undefined') {
|
1270
1273
|
// return resolve();
|
@@ -1281,7 +1284,7 @@ function Manager() {
|
|
1281
1284
|
expand: expand,
|
1282
1285
|
expFactor: expand < 380 ? 3 : 2,
|
1283
1286
|
};
|
1284
|
-
//
|
1287
|
+
// self.log('Loaded Lazysizes.');
|
1285
1288
|
})
|
1286
1289
|
.catch(reject);
|
1287
1290
|
} else {
|
@@ -1290,7 +1293,7 @@ function Manager() {
|
|
1290
1293
|
});
|
1291
1294
|
}
|
1292
1295
|
|
1293
|
-
var load_cookieconsent = function(
|
1296
|
+
var load_cookieconsent = function(self, options) {
|
1294
1297
|
return new Promise(function(resolve, reject) {
|
1295
1298
|
// if (typeof window.cookieconsent !== 'undefined') {
|
1296
1299
|
// return resolve();
|
@@ -1299,7 +1302,7 @@ function Manager() {
|
|
1299
1302
|
import('cookieconsent')
|
1300
1303
|
.then(function(mod) {
|
1301
1304
|
window.cookieconsent.initialise(options.libraries.cookieconsent.config);
|
1302
|
-
//
|
1305
|
+
// self.log('Loaded Cookieconsent.');
|
1303
1306
|
resolve();
|
1304
1307
|
})
|
1305
1308
|
.catch(reject);
|
@@ -1310,12 +1313,12 @@ function Manager() {
|
|
1310
1313
|
});
|
1311
1314
|
}
|
1312
1315
|
|
1313
|
-
var load_chatsy = function(
|
1316
|
+
var load_chatsy = function(self, options) {
|
1314
1317
|
return new Promise(function(resolve, reject) {
|
1315
1318
|
|
1316
1319
|
if (
|
1317
1320
|
options.libraries.chatsy.enabled === true
|
1318
|
-
&& !
|
1321
|
+
&& !self.properties.page._chatsyRequested
|
1319
1322
|
) {
|
1320
1323
|
var chatsyPath = 'libraries.chatsy.config';
|
1321
1324
|
|
@@ -1344,24 +1347,62 @@ function Manager() {
|
|
1344
1347
|
resolve();
|
1345
1348
|
})
|
1346
1349
|
|
1347
|
-
|
1350
|
+
self.properties.page._chatsyRequested = true;
|
1348
1351
|
} else {
|
1349
1352
|
resolve();
|
1350
1353
|
}
|
1351
1354
|
});
|
1352
1355
|
}
|
1353
1356
|
|
1354
|
-
var load_sentry = function(
|
1357
|
+
var load_sentry = function(self, options) {
|
1355
1358
|
return new Promise(function(resolve, reject) {
|
1356
1359
|
if (options.libraries.sentry.enabled === true) {
|
1357
1360
|
import('@sentry/browser')
|
1358
1361
|
.then(function(mod) {
|
1359
1362
|
window.Sentry = mod;
|
1360
1363
|
var config = options.libraries.sentry.config;
|
1361
|
-
config.release = config.release + '@' +
|
1362
|
-
config.environment =
|
1364
|
+
config.release = config.release + '@' + self.properties.global.version;
|
1365
|
+
config.environment = self.properties.meta.environment;
|
1366
|
+
|
1367
|
+
// if (self.isDevelopment()) {
|
1368
|
+
// config.dsn = 'https://901db748bbb9469f860dc36fb07a4374@o1120154.ingest.sentry.io/6155285';
|
1369
|
+
// }
|
1370
|
+
|
1371
|
+
if (config.replaysSessionSampleRate > 0 || config.replaysOnErrorSampleRate > 0) {
|
1372
|
+
config.integrations = [
|
1373
|
+
new Sentry.Replay({
|
1374
|
+
// Additional SDK configuration goes in here, for example:
|
1375
|
+
// maskAllText: true,
|
1376
|
+
// blockAllMedia: true,
|
1377
|
+
}),
|
1378
|
+
]
|
1379
|
+
}
|
1380
|
+
|
1381
|
+
config.beforeSend = function (event, hint) {
|
1382
|
+
var startTime = self.properties.page.startTime;
|
1383
|
+
var hoursSinceStart = (new Date() - startTime) / (1000 * 3600);
|
1384
|
+
|
1385
|
+
event.tags = event.tags || {};
|
1386
|
+
event.tags['process.type'] = event.tags['process.type'] || 'browser';
|
1387
|
+
|
1388
|
+
// event.tags['usage.total.opens'] = parseInt(usage.total.opens);
|
1389
|
+
// event.tags['usage.total.hours'] = usage.total.hours;
|
1390
|
+
event.tags['usage.session.hours'] = hoursSinceStart.toFixed(2);
|
1391
|
+
// event.tags['store'] = self.properties().isStore();
|
1392
|
+
event.user = event.user || {};
|
1393
|
+
event.user.email = storage.get('user.auth.email', '')
|
1394
|
+
event.user.uid = storage.get('user.auth.uid', '');
|
1395
|
+
// event.user.ip = storage.get('user.ip', '');
|
1396
|
+
|
1397
|
+
console.log('[SENTRY] Caught error', event, hint);
|
1398
|
+
|
1399
|
+
if (self.isDevelopment()) {
|
1400
|
+
return null;
|
1401
|
+
}
|
1402
|
+
|
1403
|
+
return event;
|
1404
|
+
}
|
1363
1405
|
Sentry.init(config);
|
1364
|
-
// This.log('Loaded Sentry.');
|
1365
1406
|
resolve();
|
1366
1407
|
})
|
1367
1408
|
.catch(reject);
|
@@ -1372,12 +1413,14 @@ function Manager() {
|
|
1372
1413
|
}
|
1373
1414
|
|
1374
1415
|
Manager.prototype.log = function() {
|
1375
|
-
|
1416
|
+
var self = this;
|
1417
|
+
|
1418
|
+
if (self.isDevelopment()) {
|
1376
1419
|
// 1. Convert args to a normal array
|
1377
1420
|
var args = Array.prototype.slice.call(arguments);
|
1378
1421
|
|
1379
1422
|
// 2. Prepend log prefix log string
|
1380
|
-
args.unshift('[
|
1423
|
+
args.unshift('[DEV @ ' + new Date().toLocaleTimeString() + ']');
|
1381
1424
|
|
1382
1425
|
// 3. Pass along arguments to console.log
|
1383
1426
|
if (args[1] === 'error') {
|
@@ -1395,7 +1438,7 @@ function Manager() {
|
|
1395
1438
|
}
|
1396
1439
|
}
|
1397
1440
|
|
1398
|
-
function init_loadPolyfills(
|
1441
|
+
function init_loadPolyfills(self, configuration, cb) {
|
1399
1442
|
// https://github.com/jquintozamora/polyfill-io-feature-detection/blob/master/index.js
|
1400
1443
|
var featuresDefault = (
|
1401
1444
|
typeof Symbol !== 'undefined'
|
@@ -1459,6 +1502,7 @@ function Manager() {
|
|
1459
1502
|
|
1460
1503
|
Manager.prototype.account = function() {
|
1461
1504
|
var self = this;
|
1505
|
+
|
1462
1506
|
return {
|
1463
1507
|
import: function () {
|
1464
1508
|
return import('./lib/account.js')
|
@@ -1532,8 +1576,14 @@ function Manager() {
|
|
1532
1576
|
|| self.properties.global.validRedirectHosts.includes(returnUrlObject.host)
|
1533
1577
|
}
|
1534
1578
|
|
1579
|
+
Manager.prototype.isDevelopment = function () {
|
1580
|
+
var self = this;
|
1581
|
+
|
1582
|
+
return self.properties.meta.environment === 'development';
|
1583
|
+
}
|
1584
|
+
|
1535
1585
|
// Manager.prototype.performance = function() {
|
1536
|
-
// var
|
1586
|
+
// var self = this;
|
1537
1587
|
//
|
1538
1588
|
// return {
|
1539
1589
|
// mark2: function () {
|
package/lib/account.js
CHANGED
@@ -127,9 +127,15 @@ Account.prototype.resolve = function (account, options) {
|
|
127
127
|
|
128
128
|
Account.prototype.handleAccount = function (account) {
|
129
129
|
var self = this;
|
130
|
+
var planId = account.plan.id;
|
130
131
|
|
131
132
|
// Handle plans
|
132
|
-
handlePlanVisibility(
|
133
|
+
handlePlanVisibility(planId);
|
134
|
+
|
135
|
+
// Enable exit popup if it's already enabled and the plan is basic
|
136
|
+
if (self.Manager.properties.options.exitPopup.enabled === true) {
|
137
|
+
self.Manager.properties.options.exitPopup.enabled = planId === 'basic';
|
138
|
+
}
|
133
139
|
|
134
140
|
// Handle others
|
135
141
|
// ...
|
@@ -142,7 +148,7 @@ function handlePlanVisibility(planId) {
|
|
142
148
|
|
143
149
|
// Initially hide all elements
|
144
150
|
elements.forEach(function(element) {
|
145
|
-
element.hidden
|
151
|
+
element.setAttribute('hidden', true);
|
146
152
|
});
|
147
153
|
|
148
154
|
// Toggle visibility based on plan
|
@@ -159,7 +165,7 @@ function handlePlanVisibility(planId) {
|
|
159
165
|
shouldBeVisible = (requiredPlans.includes(planId));
|
160
166
|
}
|
161
167
|
|
162
|
-
element.hidden
|
168
|
+
element.setAttribute('hidden', shouldBeVisible ? (visibility === 'hidden') : (visibility === 'visible'));
|
163
169
|
});
|
164
170
|
}
|
165
171
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "web-manager",
|
3
|
-
"version": "3.1.
|
3
|
+
"version": "3.1.53",
|
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": {
|
@@ -31,7 +31,7 @@
|
|
31
31
|
}
|
32
32
|
},
|
33
33
|
"dependencies": {
|
34
|
-
"@sentry/browser": "^
|
34
|
+
"@sentry/browser": "^7.72.0",
|
35
35
|
"cookieconsent": "^3.1.1",
|
36
36
|
"firebase": "^9.23.0",
|
37
37
|
"lazysizes": "^5.3.2"
|