web-manager 3.1.15 → 3.1.17

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -44,7 +44,7 @@ npm install web-manager
44
44
  * Firebase (Firebase app, Firestore, Auth, & Messaging)
45
45
  * Lazysizes to lazyload images
46
46
  * Sentry to report errors
47
- * Tawk to implement a chatbox
47
+ * [Chatsy.ai](https://chatsy.ai) AI chatbot integration
48
48
  * Cookieconsent to comply with GDPR
49
49
 
50
50
  ## Example Setup
package/index.js CHANGED
@@ -184,7 +184,7 @@ function Manager() {
184
184
  } else if (event.target.matches('.auth-forgot-email-btn')) {
185
185
  This.auth().forgot();
186
186
  } else if (event.target.matches('#prechat-btn')) {
187
- load_tawk(This, This.properties.options);
187
+ load_chatsy(This, This.properties.options);
188
188
  } else if (event.target.matches('.auth-subscribe-notifications-btn')) {
189
189
  This.notifications().subscribe()
190
190
  }
@@ -549,12 +549,12 @@ function Manager() {
549
549
  release: ''
550
550
  }
551
551
  },
552
- tawk: {
552
+ chatsy: {
553
553
  enabled: true,
554
554
  config: {
555
+ accountId: '',
555
556
  chatId: '',
556
- widgetId: 'default',
557
- prechatColor: '#02A84E'
557
+ options: {},
558
558
  }
559
559
  },
560
560
  cookieconsent: {
@@ -589,21 +589,22 @@ function Manager() {
589
589
  var options_user = {};
590
590
  function eachRecursive(obj, parent) {
591
591
  parent = (!parent) ? '' : parent;
592
- for (var key in obj) {
593
- if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
594
- eachRecursive(obj[key], parent + key + '.');
595
- } else {
596
- utilities.set(options_user, parent + key, utilities.get(options_defaults, parent + key) );
597
- var t_globalItem = utilities.get(configuration, 'global.settings.' + parent + key, undefined);
598
- var t_pageItem = utilities.get(configuration, 'page.settings.' + parent + key, undefined);
599
- if (typeof t_globalItem !== 'undefined') {
600
- utilities.set(options_user, parent + key, t_globalItem);
601
- }
602
- if (typeof t_pageItem !== 'undefined') {
603
- utilities.set(options_user, parent + key, t_pageItem);
604
- }
592
+
593
+ for (var key in obj) {
594
+ if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
595
+ eachRecursive(obj[key], parent + key + '.');
596
+ } else {
597
+ utilities.set(options_user, parent + key, utilities.get(options_defaults, parent + key) );
598
+ var t_globalItem = utilities.get(configuration, 'global.settings.' + parent + key, undefined);
599
+ var t_pageItem = utilities.get(configuration, 'page.settings.' + parent + key, undefined);
600
+ if (typeof t_globalItem !== 'undefined') {
601
+ utilities.set(options_user, parent + key, t_globalItem);
602
+ }
603
+ if (typeof t_pageItem !== 'undefined') {
604
+ utilities.set(options_user, parent + key, t_pageItem);
605
605
  }
606
606
  }
607
+ }
607
608
  }
608
609
 
609
610
  eachRecursive(options_defaults);
@@ -678,9 +679,9 @@ function Manager() {
678
679
  console.error(e);
679
680
  }
680
681
 
681
- var tawkOps = options_user.libraries.tawk;
682
- if (tawkOps.enabled) {
683
- This.dom().select('#prechat-btn').css({background: tawkOps.config.prechatColor}).show();
682
+ var chatsyOps = options_user.libraries.chatsy;
683
+ if (chatsyOps.enabled) {
684
+ This.dom().select('#prechat-btn').css({background: chatsyOps.config.prechatColor}).show();
684
685
  }
685
686
 
686
687
  // load non-critical libraries
@@ -1406,24 +1407,29 @@ function Manager() {
1406
1407
  });
1407
1408
  }
1408
1409
 
1409
- var load_tawk = function(This, options) {
1410
+ var load_chatsy = function(This, options) {
1410
1411
  var dom = This.dom();
1411
1412
  return new Promise(function(resolve, reject) {
1412
- // if (typeof window.Tawk_API !== 'undefined') {
1413
- // return resolve();
1414
- // }
1415
- if (options.libraries.tawk.enabled === true) {
1416
- window.Tawk_API = window.Tawk_API || {}, window.Tawk_LoadStart = new Date();
1417
- window.Tawk_API.onLoad = function(){
1418
- dom.select('#prechat-btn').hide();
1419
- Tawk_API.maximize();
1420
- };
1421
- var tawkPath = 'libraries.tawk.config';
1422
- dom.loadScript({src: 'https://embed.tawk.to/' + utilities.get(options, tawkPath + '.chatId', '') + '/' + (utilities.get(options, tawkPath + '.widgetId') || 'default'), crossorigin: true}, function(e) {
1413
+ if (options.libraries.chatsy.enabled === true) {
1414
+ var chatsyPath = 'libraries.chatsy.config';
1415
+
1416
+ dom.loadScript({
1417
+ // src: 'https://embed.tawk.to/' + utilities.get(options, tawkPath + '.chatId', '') + '/' + (utilities.get(options, tawkPath + '.widgetId') || 'default'),
1418
+ src: 'https://app.chatsy.ai/resources/script.js',
1419
+ // src: 'http://192.168.86.248:4001/resources/script.js',
1420
+ attributes: [
1421
+ {name: 'data-account-id', value: utilities.get(options, chatsyPath + '.accountId', '')},
1422
+ {name: 'data-chat-id', value: utilities.get(options, chatsyPath + '.chatId', '')},
1423
+ ],
1424
+ crossorigin: true,
1425
+ }, function(e) {
1423
1426
  if (e) {
1424
1427
  return reject(e);
1425
1428
  }
1426
- // This.log('Loaded tawk.');
1429
+ // This.log('Loaded chatsy.');
1430
+ chatsy.open();
1431
+ dom.select('#prechat-btn').hide();
1432
+
1427
1433
  resolve();
1428
1434
  })
1429
1435
 
package/lib/account.js CHANGED
@@ -156,6 +156,9 @@ Account.prototype.resolve = function (account, options) {
156
156
  return new Promise(function(resolve, reject) {
157
157
  var currentUser = firebase.auth().currentUser;
158
158
 
159
+ account = account || {};
160
+ options = options || {};
161
+
159
162
  // If there is no user logged in or we choose not to fetch the account, resolve a default account
160
163
  if (!currentUser || !currentUser.uid || options.fetchNewAccount === false) {
161
164
  return resolve(self._resolveAccount(currentUser, account, options));
package/lib/dom.js CHANGED
@@ -255,7 +255,11 @@ Dom.loadScript = function(options, callback) {
255
255
  options.async = typeof options.async === 'undefined' ? false : options.async;
256
256
  options.crossorigin = typeof options.crossorigin === 'undefined' ? false : options.crossorigin;
257
257
  options.cacheBreaker = typeof options.cacheBreaker === 'undefined' ? true : options.cacheBreaker;
258
+ options.attributes = typeof options.attributes === 'undefined' ? [] : options.attributes;
258
259
 
260
+ var s = document.createElement('script');
261
+
262
+ // Set the script cache breaker
259
263
  if (options.cacheBreaker) {
260
264
  var src = options.src.split('?');
261
265
  var query = new URLSearchParams(src[1])
@@ -264,12 +268,21 @@ Dom.loadScript = function(options, callback) {
264
268
  options.src = src[0] + '?' + query.toString();
265
269
  }
266
270
 
267
- var s = document.createElement('script');
268
- s.src = options.src;
269
- s.async = options.async;
271
+ // If crossorigin is set, set the attribute
270
272
  if (options.crossorigin) {
271
- s.setAttribute('crossorigin','*');
273
+ options.attributes.push({name: 'crossorigin', value: '*'});
272
274
  }
275
+
276
+ // Set the script attributes
277
+ options.attributes
278
+ .forEach(attribute => {
279
+ s.setAttribute(attribute.name, attribute.value);
280
+ });
281
+
282
+ // Set the script source
283
+ s.async = options.async;
284
+ s.src = options.src;
285
+
273
286
  s.onload = function() {
274
287
  if (callback) { callback(); }
275
288
  return resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.1.15",
3
+ "version": "3.1.17",
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": {