@subiz/widget-v4 4.0.83 → 4.0.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/.prettierrc.js +1 -1
  2. package/compiled_src/chatbox/AgentsAvatar.js +20 -3
  3. package/compiled_src/chatbox/ChatButton.js +11 -8
  4. package/compiled_src/chatbox/Event.js +12 -0
  5. package/compiled_src/chatbox/Events.js +1 -0
  6. package/compiled_src/chatbox/MessageInput.js +6 -0
  7. package/compiled_src/chatbox/Typing.js +1 -1
  8. package/compiled_src/chatbox/Widget.js +50 -38
  9. package/compiled_src/chatbox/main.js +10 -0
  10. package/compiled_src/popup/popup.js +21 -2
  11. package/compiled_src/store/store.js +24 -40
  12. package/compiled_src/util/common.js +10 -10
  13. package/dist/132.js +162 -44
  14. package/dist/178.js +174 -341
  15. package/dist/182ed9b853b.132.js +1 -0
  16. package/dist/182ed9b853b.178.js +1 -0
  17. package/dist/{17f00e48d38.213.js → 182ed9b853b.213.js} +1 -1
  18. package/dist/{17f00e48d38.335.js → 182ed9b853b.335.js} +1 -1
  19. package/dist/182ed9b853b.362.js +1 -0
  20. package/dist/182ed9b853b.441.js +1 -0
  21. package/dist/{17f00e48d38.605.js → 182ed9b853b.605.js} +0 -0
  22. package/dist/182ed9b853b.678.js +1 -0
  23. package/dist/182ed9b853b.782.js +1 -0
  24. package/dist/182ed9b853b.app.js +1 -0
  25. package/dist/{17f00e48d38.index.html → 182ed9b853b.index.html} +7 -3
  26. package/dist/{17f00e48d38.library.html → 182ed9b853b.library.html} +7 -3
  27. package/dist/182ed9b853b.library.js +1 -0
  28. package/dist/{17f00e48d38.preview.html → 182ed9b853b.preview.html} +1 -1
  29. package/dist/182ed9b853b.preview.js +1 -0
  30. package/dist/182ed9b853b.screenshoot.js +1 -0
  31. package/dist/213.js +28 -1
  32. package/dist/335.js +2 -2
  33. package/dist/362.js +21 -71
  34. package/dist/441.js +152 -57
  35. package/dist/678.js +20 -70
  36. package/dist/782.js +21 -118
  37. package/dist/HASH +1 -1
  38. package/dist/screenshoot.html +1 -1
  39. package/dist/screenshoot.js +208 -174
  40. package/index.html +1 -1
  41. package/package.json +16 -16
  42. package/src/chatbox/AgentsAvatar.js +32 -10
  43. package/src/chatbox/ChatButton.js +11 -4
  44. package/src/chatbox/Event.js +23 -4
  45. package/src/chatbox/Events.js +3 -1
  46. package/src/chatbox/MessageInput.js +14 -5
  47. package/src/chatbox/Typing.js +10 -11
  48. package/src/chatbox/Widget.js +17 -11
  49. package/src/chatbox/main.js +8 -1
  50. package/src/popup/popup.js +37 -12
  51. package/src/store/store.js +24 -36
  52. package/src/util/common.js +16 -19
  53. package/dist/0b82fa7e5c3b07b40a44.png +0 -1
  54. package/dist/0f4af006e38ee8b93633.png +0 -1
  55. package/dist/17f00e48d38.132.js +0 -1
  56. package/dist/17f00e48d38.178.js +0 -1
  57. package/dist/17f00e48d38.362.js +0 -1
  58. package/dist/17f00e48d38.441.js +0 -1
  59. package/dist/17f00e48d38.678.js +0 -1
  60. package/dist/17f00e48d38.782.js +0 -1
  61. package/dist/17f00e48d38.app.js +0 -1
  62. package/dist/17f00e48d38.library.js +0 -1
  63. package/dist/17f00e48d38.preview.js +0 -1
  64. package/dist/17f00e48d38.screenshoot.js +0 -1
  65. package/dist/1ea1c6cd21d25176810c.png +0 -1
  66. package/dist/292d42404e1b03398f61.png +0 -1
  67. package/dist/312d376370831b7bea83.png +0 -1
  68. package/dist/313d1bfc1cf776d1aefe.png +0 -1
  69. package/dist/4aa58bb7a66bb44975aa.png +0 -1
  70. package/dist/56ce063bc6c81adb7322.png +0 -1
  71. package/dist/6a411166ef5cc79e0714.png +0 -1
  72. package/dist/6faf403782fefacc1649.png +0 -1
  73. package/dist/79dca33c68fab79c067f.png +0 -1
  74. package/dist/82da1578fa84f9debaeb.png +0 -1
  75. package/dist/8b8e0f0824743974b282.png +0 -1
  76. package/dist/8d551390d81e39130a3c.png +0 -1
  77. package/dist/9fc61b9479877ebdb6c7.png +0 -1
  78. package/dist/a165d31dcb3dc90f1057.png +0 -1
  79. package/dist/a98d4a5698812c4426b3.png +0 -1
  80. package/dist/c41606bf9d1b604e46d5.png +0 -1
  81. package/dist/ce1f7450ce6c1aacd330.png +0 -1
  82. package/dist/cf8c01e88f4770a6e3e5.png +0 -1
  83. package/dist/dfbcfeab1d5622a737e2.png +0 -1
  84. package/dist/e4893ed8c2f7b8329919.png +0 -1
  85. package/dist/ec2ab4eb4ef73d186186.png +0 -1
@@ -13,7 +13,7 @@ cookie.defaults.expires = 3650 // 10 year
13
13
  const MAX_CONVO = 20
14
14
  const page_loaded = sb.Date.now()
15
15
 
16
- // available localstorage key mask, user, session, hasManuallyClosed, isopen, close_preview_at, lastview, bot_run_logs, plugin_run_logs
16
+ // available localstorage key mask, user, hasManuallyClosed, isopen, close_preview_at, lastview, bot_run_logs, plugin_run_logs
17
17
  export default class Store {
18
18
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi, agenttoken) {
19
19
  this.agent_token = agenttoken
@@ -98,7 +98,8 @@ export default class Store {
98
98
  }
99
99
 
100
100
  isInsync(key) {
101
- return sb.Date.now() - (this.g_sync[key] || 0) < 300000
101
+ // refetch after 10 mins
102
+ return sb.Date.now() - (this.g_sync[key] || 0) < 600000
102
103
  }
103
104
 
104
105
  async fetchShippingAddresses() {
@@ -114,6 +115,7 @@ export default class Store {
114
115
  updateOrder(order) {
115
116
  return this.api.updateOrder(order)
116
117
  }
118
+
117
119
  createShippingAddress(addr) {
118
120
  return this.api.createShippingAddress(addr)
119
121
  }
@@ -218,7 +220,6 @@ export default class Store {
218
220
 
219
221
  suggest_addresses = (keyword) => this.api.suggest_address(keyword)
220
222
 
221
- matchSession = () => this.kv.match('session') || {}
222
223
  matchAccount = () => this.cache.match('account')
223
224
  matchPaymentMethods = () => this.cache.match('payment_methods')
224
225
 
@@ -303,6 +304,8 @@ export default class Store {
303
304
  return {error}
304
305
  }
305
306
 
307
+ matchLocation = () => this.cache.match('location') || {}
308
+
306
309
  matchBot = () => this.cache.match('bot') || {}
307
310
 
308
311
  readyGate = new sb.Gate()
@@ -530,26 +533,6 @@ export default class Store {
530
533
  // user && session
531
534
  if (setting.user) {
532
535
  setting.user.account_id = setting.account.id
533
- let oldsession = this.matchSession()
534
- let session = setting.user.session
535
- if (session) {
536
- if (session.id === oldsession.id) {
537
- // refresh session, but keep old local fields
538
- session._urls = oldsession._urls
539
- } else {
540
- // session changed, clear all old data
541
- }
542
- } else {
543
- // dont change session
544
- session = oldsession
545
- }
546
-
547
- session._urls = session._urls || []
548
- session._urls.push(location.href)
549
- while (session._urls.length > 1000) session._urls.shift()
550
-
551
- this.kv.put('session', session)
552
-
553
536
  delete setting.user.session
554
537
  this._setUser(setting.user)
555
538
  }
@@ -561,6 +544,10 @@ export default class Store {
561
544
  delete setting.account
562
545
  }
563
546
 
547
+ // location
548
+ let location = sb.get(setting, 'location', [])
549
+ this.cache.put('location', location)
550
+
564
551
  // bot
565
552
  let bots = sb.get(setting, 'bots', [])
566
553
  let botM = {}
@@ -601,7 +588,7 @@ export default class Store {
601
588
  // send the content view, the first presence and record domain
602
589
  async track() {
603
590
  let user = this.kv.match('user') || {}
604
- await this.api.sendContentView(
591
+ let out = await this.api.sendContentView(
605
592
  this.device,
606
593
  location.href,
607
594
  document.title,
@@ -609,9 +596,15 @@ export default class Store {
609
596
  this._currentViewingProduct.source_id,
610
597
  this._currentViewingProduct.sku,
611
598
  )
599
+
600
+ let traffic_source = sb.get(out, 'body.by.device.source', '')
601
+ if (traffic_source) this.kv.put('traffic_source', traffic_source)
602
+
612
603
  this.sendPresence()
613
604
  }
614
605
 
606
+ matchTrafficSource = () => this.kv.match('traffic_source')
607
+
615
608
  async onWs(ev) {
616
609
  if (!ev || !ev.type) return
617
610
  ev.created = sb.getMs(ev.created)
@@ -925,17 +918,15 @@ export default class Store {
925
918
  }
926
919
 
927
920
  logBotRun(botid) {
928
- let session = this.matchSession()
929
921
  let log = this.kv.match('bot_run_logs') || {}
930
- log[botid] = {bot_id: botid, created: this.now(), session_id: session.id}
922
+ log[botid] = {bot_id: botid, created: this.now()}
931
923
  this.kv.put('bot_run_logs', log)
932
924
  }
933
925
 
934
926
  sendImpression(id) {
935
927
  let user = this.kv.match('user') || {}
936
928
  let log = this.kv.match('plugin_run_logs') || {}
937
- let session = this.matchSession()
938
- log[id] = {web_plugin_id: id, created: this.now(), session_id: session.id}
929
+ log[id] = {web_plugin_id: id, created: this.now()}
939
930
  this.kv.put('plugin_run_logs', log)
940
931
  return this.api.sendImpression({
941
932
  account_id: user.account_id,
@@ -944,7 +935,6 @@ export default class Store {
944
935
  user_id: user.id,
945
936
  url: window.location.href,
946
937
  device: this.device,
947
- session_id: session.id,
948
938
  })
949
939
  }
950
940
 
@@ -965,7 +955,6 @@ export default class Store {
965
955
  device: this.device,
966
956
  submission,
967
957
  impression_token: impressionToken,
968
- session_id: this.matchSession().id,
969
958
  })
970
959
  }
971
960
 
@@ -1007,7 +996,7 @@ export default class Store {
1007
996
  let startms = sb.Date.now()
1008
997
 
1009
998
  // store not init
1010
- if (!sb.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 120000)
999
+ if (!sb.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 240000)
1011
1000
 
1012
1001
  let {body: t, error} = await this.api.time()
1013
1002
  if (error) return setTimeout(() => this.loopTime(), 30000)
@@ -1015,7 +1004,7 @@ export default class Store {
1015
1004
  var serverMs = new sb.Date(t).getTime() + latences
1016
1005
  var localMs = sb.Date.now()
1017
1006
  this.timeDiff = Math.floor(serverMs - localMs)
1018
- setTimeout(() => this.loopTime(), 120000)
1007
+ setTimeout(() => this.loopTime(), 240000)
1019
1008
  }
1020
1009
 
1021
1010
  replaceFileUrl(src) {
@@ -1161,16 +1150,15 @@ function sendToFBPixel(category, action, label) {
1161
1150
  }
1162
1151
 
1163
1152
  function sendToGA(category, action, label) {
1164
- console.log('SENT.', category, action, label)
1153
+ // console.log('SENT.', category, action, label)
1154
+ if (window.gtag) window.gtag('event', category, {Action: action, Label: label})
1165
1155
  if (window.ga && window.ga.getAll) {
1156
+ // only send gtag when ga is not available
1166
1157
  const allTrackers = window.ga.getAll() || []
1167
1158
  allTrackers.forEach(function (tracker) {
1168
1159
  const name = tracker.get('name')
1169
1160
  window.ga(name + '.send', 'event', category, action, label)
1170
1161
  })
1171
- } else {
1172
- // only send gtag when ga is not available
1173
- if (window.gtag) window.gtag('event', category, {Action: action, Label: label})
1174
1162
  }
1175
1163
  }
1176
1164
 
@@ -247,13 +247,13 @@ export function throttle(func, wait, options) {
247
247
  var timeout = null
248
248
  var previous = 0
249
249
  if (!options) options = {}
250
- var later = function() {
250
+ var later = function () {
251
251
  previous = options.leading === false ? 0 : new Date().getTime()
252
252
  timeout = null
253
253
  result = func.apply(context, args)
254
254
  if (!timeout) context = args = null
255
255
  }
256
- return function() {
256
+ return function () {
257
257
  var now = new Date().getTime()
258
258
  if (!previous && options.leading === false) previous = now
259
259
  var remaining = wait - (now - previous)
@@ -331,7 +331,8 @@ export function isNumber(num) {
331
331
  }
332
332
 
333
333
  export function isEmail(email) {
334
- const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
334
+ const re =
335
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
335
336
  return re.test(String(email).toLowerCase())
336
337
  }
337
338
 
@@ -650,7 +651,7 @@ function browserName() {
650
651
  // Safari 3.0+ "[object HTMLElementConstructor]"
651
652
  var isSafari =
652
653
  /constructor/i.test(window.HTMLElement) ||
653
- (function(p) {
654
+ (function (p) {
654
655
  return p.toString() === '[object SafariRemoteNotification]'
655
656
  })(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification))
656
657
 
@@ -697,15 +698,10 @@ function osName() {
697
698
  // frequencty
698
699
  function check_frequently(freq, lastrun, store) {
699
700
  if (!lastrun) return true
700
- // only for popup?
701
- //var run = store.matchLastPluginRun(plugin.id)
702
- //if (!run) return true
703
-
704
701
  if (op.get(freq, 'once_per_user')) return false
705
702
 
706
- var session = store.matchSession() || {}
707
703
  if (op.get(freq, 'once_per_session')) {
708
- if (lastrun.session_id === session.id) return false
704
+ if (sameDay(lastrun.created, Date.now())) return false
709
705
  }
710
706
 
711
707
  if (op.get(freq, 'interval_sec')) {
@@ -718,7 +714,7 @@ function check_frequently(freq, lastrun, store) {
718
714
 
719
715
  export function checkRunConditions(freq, conds, lastrun, store) {
720
716
  var acc = store.matchAccount() || {}
721
- var session = store.matchSession() || {}
717
+ var location = store.matchLocation() || {}
722
718
 
723
719
  // check frequently first
724
720
  if (!check_frequently(freq, lastrun, store)) return false
@@ -754,13 +750,13 @@ export function checkRunConditions(freq, conds, lastrun, store) {
754
750
  if (size(cond.exclude_locations) > 0) {
755
751
  let found = find(cond.exclude_locations, (loc) => {
756
752
  if (loc.city_name && loc.country_code) {
757
- if (loc.city_name === session.city_name && loc.country_code === session.country_code) return true
753
+ if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true
758
754
  }
759
755
  if (loc.city_name && !loc.country_code) {
760
- if (loc.city_name === session.city_name) return true
756
+ if (loc.city_name === location.city_name) return true
761
757
  }
762
758
  if (!loc.city_name && loc.country_code) {
763
- if (loc.country_code === session.country_code) return true
759
+ if (loc.country_code === location.country_code) return true
764
760
  }
765
761
  })
766
762
  if (found) return false
@@ -769,13 +765,13 @@ export function checkRunConditions(freq, conds, lastrun, store) {
769
765
  if (size(cond.locations) > 0) {
770
766
  let found = find(cond.locations, (loc) => {
771
767
  if (loc.city_name && loc.country_code) {
772
- if (loc.city_name === session.city_name && loc.country_code === session.country_code) return true
768
+ if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true
773
769
  }
774
770
  if (loc.city_name && !loc.country_code) {
775
- if (loc.city_name === session.city_name) return true
771
+ if (loc.city_name === location.city_name) return true
776
772
  }
777
773
  if (!loc.city_name && loc.country_code) {
778
- if (loc.country_code === session.country_code) return true
774
+ if (loc.country_code === location.country_code) return true
779
775
  }
780
776
  })
781
777
  if (!found) return false
@@ -828,7 +824,8 @@ export function checkRunConditions(freq, conds, lastrun, store) {
828
824
  break
829
825
  case 'source':
830
826
  if (size(cond.sources) > 0) {
831
- if (!find(cond.sources, (src) => norm(src) === norm(session.source))) return false
827
+ let source = store.matchTrafficSource()
828
+ if (!find(cond.sources, (src) => norm(src) === norm(source))) return false
832
829
  }
833
830
  break
834
831
  case 'user_attribute':
@@ -1077,7 +1074,7 @@ export var sleep = (ms) => new Promise((res) => setTimeout(res, ms))
1077
1074
  export function formatCurrency(val) {
1078
1075
  if (!val) return '0 đ'
1079
1076
  val = Math.round(val)
1080
- return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')+ ' đ'
1077
+ return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') + ' đ'
1081
1078
  }
1082
1079
 
1083
1080
  function replaceFileUrl(src) {
@@ -1 +0,0 @@
1
- module.exports = __webpack_public_path__ + "assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png";
@@ -1 +0,0 @@
1
- module.exports = __webpack_public_path__ + "assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png";