web-manager 3.1.52 → 3.2.0
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.
- package/index.js +244 -190
- package/lib/account.js +7 -1
- package/package.json +3 -3
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
|
|
@@ -1100,25 +1103,29 @@ function Manager() {
|
|
1100
1103
|
if (!proceed) { return }
|
1101
1104
|
|
1102
1105
|
var $el = document.getElementById('modal-exit-popup');
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1106
|
+
try {
|
1107
|
+
var modal = new bootstrap.Modal($el);
|
1108
|
+
modal.show();
|
1109
|
+
$el.removeAttribute('hidden');
|
1110
|
+
|
1111
|
+
var $title = $el.querySelector('.modal-title');
|
1112
|
+
var $message = $el.querySelector('.modal-body');
|
1113
|
+
var $okButton = $el.querySelector('.modal-footer .btn-primary');
|
1114
|
+
var config = exitPopupSettings.config;
|
1115
|
+
|
1116
|
+
$title.innerHTML = config.title;
|
1117
|
+
$message.innerHTML = config.message;
|
1118
|
+
$okButton.innerHTML = config.okButton.text;
|
1119
|
+
$okButton.setAttribute('href', config.okButton.link);
|
1120
|
+
} catch (e) {
|
1121
|
+
console.warn(e);
|
1122
|
+
}
|
1116
1123
|
}
|
1117
1124
|
|
1118
1125
|
/*
|
1119
1126
|
EXTERNAL LIBS
|
1120
1127
|
*/
|
1121
|
-
var load_firebase = function(
|
1128
|
+
var load_firebase = function(self, options) {
|
1122
1129
|
return new Promise(function(resolve, reject) {
|
1123
1130
|
// if (typeof window.firebase !== 'undefined') {
|
1124
1131
|
// return resolve();
|
@@ -1126,21 +1133,21 @@ function Manager() {
|
|
1126
1133
|
var setting = options.libraries.firebase_app
|
1127
1134
|
if (setting.enabled === true) {
|
1128
1135
|
function _post() {
|
1129
|
-
//
|
1136
|
+
// self.log('Loaded Firebase.');
|
1130
1137
|
// console.log('_post.');
|
1131
1138
|
window.app = firebase.initializeApp(setting.config);
|
1132
1139
|
|
1133
1140
|
Promise.all([
|
1134
|
-
load_firebase_auth(
|
1135
|
-
load_firebase_firestore(
|
1136
|
-
load_firebase_messaging(
|
1137
|
-
load_firebase_appCheck(
|
1141
|
+
load_firebase_auth(self, options),
|
1142
|
+
load_firebase_firestore(self, options),
|
1143
|
+
load_firebase_messaging(self, options),
|
1144
|
+
load_firebase_appCheck(self, options),
|
1138
1145
|
])
|
1139
1146
|
.then(resolve)
|
1140
1147
|
.catch(reject);
|
1141
1148
|
}
|
1142
1149
|
if (setting.load) {
|
1143
|
-
setting.load(
|
1150
|
+
setting.load(self)
|
1144
1151
|
.then(_post)
|
1145
1152
|
.catch(reject);
|
1146
1153
|
} else {
|
@@ -1159,7 +1166,7 @@ function Manager() {
|
|
1159
1166
|
}
|
1160
1167
|
|
1161
1168
|
|
1162
|
-
var load_firebase_auth = function(
|
1169
|
+
var load_firebase_auth = function(self, options) {
|
1163
1170
|
return new Promise(function(resolve, reject) {
|
1164
1171
|
// if (typeof utilities.get(window, 'firebase.auth', undefined) !== 'undefined') {
|
1165
1172
|
// return resolve();
|
@@ -1167,7 +1174,7 @@ function Manager() {
|
|
1167
1174
|
var setting = options.libraries.firebase_auth;
|
1168
1175
|
if (setting.enabled === true) {
|
1169
1176
|
if (setting.load) {
|
1170
|
-
setting.load(
|
1177
|
+
setting.load(self)
|
1171
1178
|
.then(resolve)
|
1172
1179
|
.catch(reject);
|
1173
1180
|
} else {
|
@@ -1184,7 +1191,7 @@ function Manager() {
|
|
1184
1191
|
}
|
1185
1192
|
|
1186
1193
|
|
1187
|
-
var load_firebase_firestore = function(
|
1194
|
+
var load_firebase_firestore = function(self, options) {
|
1188
1195
|
return new Promise(function(resolve, reject) {
|
1189
1196
|
// if (typeof utilities.get(window, 'firebase.firestore', undefined) !== 'undefined') {
|
1190
1197
|
// return resolve();
|
@@ -1192,7 +1199,7 @@ function Manager() {
|
|
1192
1199
|
var setting = options.libraries.firebase_firestore;
|
1193
1200
|
if (setting.enabled === true) {
|
1194
1201
|
if (setting.load) {
|
1195
|
-
setting.load(
|
1202
|
+
setting.load(self)
|
1196
1203
|
.then(resolve)
|
1197
1204
|
.catch(reject);
|
1198
1205
|
} else {
|
@@ -1207,7 +1214,7 @@ function Manager() {
|
|
1207
1214
|
});
|
1208
1215
|
}
|
1209
1216
|
|
1210
|
-
var load_firebase_messaging = function(
|
1217
|
+
var load_firebase_messaging = function(self, options) {
|
1211
1218
|
return new Promise(function(resolve, reject) {
|
1212
1219
|
// if (typeof utilities.get(window, 'firebase.messaging', undefined) !== 'undefined') {
|
1213
1220
|
// return resolve();
|
@@ -1215,7 +1222,7 @@ function Manager() {
|
|
1215
1222
|
var setting = options.libraries.firebase_messaging;
|
1216
1223
|
if (setting.enabled === true) {
|
1217
1224
|
if (setting.load) {
|
1218
|
-
setting.load(
|
1225
|
+
setting.load(self)
|
1219
1226
|
.then(resolve)
|
1220
1227
|
.catch(reject);
|
1221
1228
|
} else {
|
@@ -1230,12 +1237,12 @@ function Manager() {
|
|
1230
1237
|
});
|
1231
1238
|
}
|
1232
1239
|
|
1233
|
-
var load_firebase_appCheck = function(
|
1240
|
+
var load_firebase_appCheck = function(self, options) {
|
1234
1241
|
return new Promise(function(resolve, reject) {
|
1235
1242
|
var setting = options.libraries.firebase_appCheck;
|
1236
1243
|
if (setting.enabled === true) {
|
1237
1244
|
if (setting.load) {
|
1238
|
-
setting.load(
|
1245
|
+
setting.load(self)
|
1239
1246
|
.then(resolve)
|
1240
1247
|
.catch(reject);
|
1241
1248
|
} else {
|
@@ -1264,7 +1271,7 @@ function Manager() {
|
|
1264
1271
|
});
|
1265
1272
|
}
|
1266
1273
|
|
1267
|
-
var load_lazysizes = function(
|
1274
|
+
var load_lazysizes = function(self, options) {
|
1268
1275
|
return new Promise(function(resolve, reject) {
|
1269
1276
|
// if (typeof window.lazysizes !== 'undefined') {
|
1270
1277
|
// return resolve();
|
@@ -1281,7 +1288,7 @@ function Manager() {
|
|
1281
1288
|
expand: expand,
|
1282
1289
|
expFactor: expand < 380 ? 3 : 2,
|
1283
1290
|
};
|
1284
|
-
//
|
1291
|
+
// self.log('Loaded Lazysizes.');
|
1285
1292
|
})
|
1286
1293
|
.catch(reject);
|
1287
1294
|
} else {
|
@@ -1290,7 +1297,7 @@ function Manager() {
|
|
1290
1297
|
});
|
1291
1298
|
}
|
1292
1299
|
|
1293
|
-
var load_cookieconsent = function(
|
1300
|
+
var load_cookieconsent = function(self, options) {
|
1294
1301
|
return new Promise(function(resolve, reject) {
|
1295
1302
|
// if (typeof window.cookieconsent !== 'undefined') {
|
1296
1303
|
// return resolve();
|
@@ -1299,7 +1306,7 @@ function Manager() {
|
|
1299
1306
|
import('cookieconsent')
|
1300
1307
|
.then(function(mod) {
|
1301
1308
|
window.cookieconsent.initialise(options.libraries.cookieconsent.config);
|
1302
|
-
//
|
1309
|
+
// self.log('Loaded Cookieconsent.');
|
1303
1310
|
resolve();
|
1304
1311
|
})
|
1305
1312
|
.catch(reject);
|
@@ -1310,12 +1317,12 @@ function Manager() {
|
|
1310
1317
|
});
|
1311
1318
|
}
|
1312
1319
|
|
1313
|
-
var load_chatsy = function(
|
1320
|
+
var load_chatsy = function(self, options) {
|
1314
1321
|
return new Promise(function(resolve, reject) {
|
1315
1322
|
|
1316
1323
|
if (
|
1317
1324
|
options.libraries.chatsy.enabled === true
|
1318
|
-
&& !
|
1325
|
+
&& !self.properties.page._chatsyRequested
|
1319
1326
|
) {
|
1320
1327
|
var chatsyPath = 'libraries.chatsy.config';
|
1321
1328
|
|
@@ -1344,24 +1351,62 @@ function Manager() {
|
|
1344
1351
|
resolve();
|
1345
1352
|
})
|
1346
1353
|
|
1347
|
-
|
1354
|
+
self.properties.page._chatsyRequested = true;
|
1348
1355
|
} else {
|
1349
1356
|
resolve();
|
1350
1357
|
}
|
1351
1358
|
});
|
1352
1359
|
}
|
1353
1360
|
|
1354
|
-
var load_sentry = function(
|
1361
|
+
var load_sentry = function(self, options) {
|
1355
1362
|
return new Promise(function(resolve, reject) {
|
1356
1363
|
if (options.libraries.sentry.enabled === true) {
|
1357
1364
|
import('@sentry/browser')
|
1358
1365
|
.then(function(mod) {
|
1359
1366
|
window.Sentry = mod;
|
1360
1367
|
var config = options.libraries.sentry.config;
|
1361
|
-
config.release = config.release + '@' +
|
1362
|
-
config.environment =
|
1368
|
+
config.release = config.release + '@' + self.properties.global.version;
|
1369
|
+
config.environment = self.properties.meta.environment;
|
1370
|
+
|
1371
|
+
// if (self.isDevelopment()) {
|
1372
|
+
// config.dsn = 'https://901db748bbb9469f860dc36fb07a4374@o1120154.ingest.sentry.io/6155285';
|
1373
|
+
// }
|
1374
|
+
|
1375
|
+
if (config.replaysSessionSampleRate > 0 || config.replaysOnErrorSampleRate > 0) {
|
1376
|
+
config.integrations = [
|
1377
|
+
new Sentry.Replay({
|
1378
|
+
// Additional SDK configuration goes in here, for example:
|
1379
|
+
// maskAllText: true,
|
1380
|
+
// blockAllMedia: true,
|
1381
|
+
}),
|
1382
|
+
]
|
1383
|
+
}
|
1384
|
+
|
1385
|
+
config.beforeSend = function (event, hint) {
|
1386
|
+
var startTime = self.properties.page.startTime;
|
1387
|
+
var hoursSinceStart = (new Date() - startTime) / (1000 * 3600);
|
1388
|
+
|
1389
|
+
event.tags = event.tags || {};
|
1390
|
+
event.tags['process.type'] = event.tags['process.type'] || 'browser';
|
1391
|
+
|
1392
|
+
// event.tags['usage.total.opens'] = parseInt(usage.total.opens);
|
1393
|
+
// event.tags['usage.total.hours'] = usage.total.hours;
|
1394
|
+
event.tags['usage.session.hours'] = hoursSinceStart.toFixed(2);
|
1395
|
+
// event.tags['store'] = self.properties().isStore();
|
1396
|
+
event.user = event.user || {};
|
1397
|
+
event.user.email = storage.get('user.auth.email', '')
|
1398
|
+
event.user.uid = storage.get('user.auth.uid', '');
|
1399
|
+
// event.user.ip = storage.get('user.ip', '');
|
1400
|
+
|
1401
|
+
console.error('[SENTRY] Caught error', event, hint);
|
1402
|
+
|
1403
|
+
if (self.isDevelopment()) {
|
1404
|
+
return null;
|
1405
|
+
}
|
1406
|
+
|
1407
|
+
return event;
|
1408
|
+
}
|
1363
1409
|
Sentry.init(config);
|
1364
|
-
// This.log('Loaded Sentry.');
|
1365
1410
|
resolve();
|
1366
1411
|
})
|
1367
1412
|
.catch(reject);
|
@@ -1372,12 +1417,14 @@ function Manager() {
|
|
1372
1417
|
}
|
1373
1418
|
|
1374
1419
|
Manager.prototype.log = function() {
|
1375
|
-
|
1420
|
+
var self = this;
|
1421
|
+
|
1422
|
+
if (self.isDevelopment()) {
|
1376
1423
|
// 1. Convert args to a normal array
|
1377
1424
|
var args = Array.prototype.slice.call(arguments);
|
1378
1425
|
|
1379
1426
|
// 2. Prepend log prefix log string
|
1380
|
-
args.unshift('[
|
1427
|
+
args.unshift('[DEV @ ' + new Date().toLocaleTimeString() + ']');
|
1381
1428
|
|
1382
1429
|
// 3. Pass along arguments to console.log
|
1383
1430
|
if (args[1] === 'error') {
|
@@ -1395,7 +1442,7 @@ function Manager() {
|
|
1395
1442
|
}
|
1396
1443
|
}
|
1397
1444
|
|
1398
|
-
function init_loadPolyfills(
|
1445
|
+
function init_loadPolyfills(self, configuration, cb) {
|
1399
1446
|
// https://github.com/jquintozamora/polyfill-io-feature-detection/blob/master/index.js
|
1400
1447
|
var featuresDefault = (
|
1401
1448
|
typeof Symbol !== 'undefined'
|
@@ -1459,6 +1506,7 @@ function Manager() {
|
|
1459
1506
|
|
1460
1507
|
Manager.prototype.account = function() {
|
1461
1508
|
var self = this;
|
1509
|
+
|
1462
1510
|
return {
|
1463
1511
|
import: function () {
|
1464
1512
|
return import('./lib/account.js')
|
@@ -1532,8 +1580,14 @@ function Manager() {
|
|
1532
1580
|
|| self.properties.global.validRedirectHosts.includes(returnUrlObject.host)
|
1533
1581
|
}
|
1534
1582
|
|
1583
|
+
Manager.prototype.isDevelopment = function () {
|
1584
|
+
var self = this;
|
1585
|
+
|
1586
|
+
return self.properties.meta.environment === 'development';
|
1587
|
+
}
|
1588
|
+
|
1535
1589
|
// Manager.prototype.performance = function() {
|
1536
|
-
// var
|
1590
|
+
// var self = this;
|
1537
1591
|
//
|
1538
1592
|
// return {
|
1539
1593
|
// 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
|
// ...
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "web-manager",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.2.00",
|
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,9 +31,9 @@
|
|
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"
|
38
38
|
}
|
39
|
-
}
|
39
|
+
}
|