@subiz/widget-v4 4.1.12 → 4.1.14

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 (99) hide show
  1. package/assets/less/form.less +5 -0
  2. package/compiled_src/chatbox/Widget.js +2 -1
  3. package/compiled_src/store/store.js +62 -36
  4. package/compiled_src/util/common.js +2 -2
  5. package/dist/132.js +6612 -0
  6. package/dist/178.js +406 -0
  7. package/dist/1857b1f5c4f.132.js +1 -0
  8. package/dist/1857b1f5c4f.178.js +1 -0
  9. package/dist/1857b1f5c4f.213.js +1 -0
  10. package/dist/1857b1f5c4f.335.js +1 -0
  11. package/dist/1857b1f5c4f.362.js +1 -0
  12. package/dist/1857b1f5c4f.441.js +1 -0
  13. package/dist/1857b1f5c4f.605.js +1 -0
  14. package/dist/1857b1f5c4f.678.js +1 -0
  15. package/dist/1857b1f5c4f.782.js +1 -0
  16. package/dist/1857b1f5c4f.app.js +1 -0
  17. package/dist/1857b1f5c4f.index.html +26 -0
  18. package/dist/1857b1f5c4f.library.html +26 -0
  19. package/dist/1857b1f5c4f.library.js +1 -0
  20. package/dist/1857b1f5c4f.preview.html +759 -0
  21. package/dist/1857b1f5c4f.preview.js +1 -0
  22. package/dist/1857b1f5c4f.screenshoot.js +1 -0
  23. package/dist/1857b1f5c4f.webview.js +1 -0
  24. package/dist/213.js +2774 -0
  25. package/dist/335.js +372 -0
  26. package/dist/362.js +107 -0
  27. package/dist/441.js +2855 -0
  28. package/dist/605.js +305 -0
  29. package/dist/678.js +107 -0
  30. package/dist/782.js +107 -0
  31. package/dist/HASH +1 -0
  32. package/dist/assets/img/Facebook.64607ec.png +0 -0
  33. package/dist/assets/img/Zalo.6845707.png +0 -0
  34. package/dist/assets/img/award1a.1a58e10.png +0 -0
  35. package/dist/assets/img/award3a.3b74423.png +0 -0
  36. package/dist/assets/img/award4a.ed6ccd4.png +0 -0
  37. package/dist/assets/img/award5.39eb7ae.png +0 -0
  38. package/dist/assets/img/bubble_default.7d5e4ab.svg +20 -0
  39. package/dist/assets/img/caret.998eb8f.svg +1 -0
  40. package/dist/assets/img/convos_empty.2353007.svg +72 -0
  41. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  42. package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
  43. package/dist/assets/img/done_gray.d7e8203.svg +4 -0
  44. package/dist/assets/img/done_green.b817fd4.svg +4 -0
  45. package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
  46. package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
  47. package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
  48. package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
  49. package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
  50. package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
  51. package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
  52. package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
  53. package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
  54. package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
  55. package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
  56. package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
  57. package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
  58. package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
  59. package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
  60. package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
  61. package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
  62. package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
  63. package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
  64. package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
  65. package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
  66. package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
  67. package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
  68. package/dist/assets/img/empty.29bed2d.svg +23 -0
  69. package/dist/assets/img/empty_1.0b98af0.svg +11 -0
  70. package/dist/assets/img/examplte_logo.f86535f.svg +1 -0
  71. package/dist/assets/img/external-link.90577cc.svg +1 -0
  72. package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
  73. package/dist/assets/img/ghn.070f8e3.svg +17 -0
  74. package/dist/assets/img/ghtk.326eac1.svg +18 -0
  75. package/dist/assets/img/image_default.be0698b.png +0 -0
  76. package/dist/assets/img/info.ebce7ea.svg +1 -0
  77. package/dist/assets/img/loader.37000a7.svg +1 -0
  78. package/dist/assets/img/loading_static.8f403ae.svg +10 -0
  79. package/dist/assets/img/main-service1.d536cc2.png +0 -0
  80. package/dist/assets/img/main-service2.9b99549.png +0 -0
  81. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  82. package/dist/assets/img/package.8d37d0f.svg +5 -0
  83. package/dist/assets/img/package_fade.763c001.svg +1 -0
  84. package/dist/assets/img/rating--average.1ea492c.svg +12 -0
  85. package/dist/assets/img/rating--great.e3d712e.svg +16 -0
  86. package/dist/assets/img/rating--poor.2938a25.svg +12 -0
  87. package/dist/assets/img/search.f9705ff.svg +1 -0
  88. package/dist/assets/img/send.6db52a9.svg +3 -0
  89. package/dist/assets/img/shop.f7dc7d8.svg +1 -0
  90. package/dist/assets/img/shop_faded.df7845a.svg +1 -0
  91. package/dist/assets/img/subiz-mono.877e9f5.svg +3 -0
  92. package/dist/assets/img/x.26fdfa3.svg +5 -0
  93. package/dist/malicious-app.js +13 -0
  94. package/dist/screenshoot.html +7 -0
  95. package/dist/screenshoot.js +5607 -0
  96. package/package.json +4 -4
  97. package/src/chatbox/Widget.js +3 -1
  98. package/src/store/store.js +61 -32
  99. package/src/util/common.js +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.12",
3
+ "version": "4.1.14",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -14,7 +14,7 @@
14
14
  "@subiz/storage": "0.0.8",
15
15
  "@subiz/wsclient": "^3.1.9",
16
16
  "cookie_js": "1.4.2",
17
- "core-js": "^3.27.0",
17
+ "core-js": "^3.27.1",
18
18
  "css-loader": "5.2.7",
19
19
  "file-loader": "^6.2.0",
20
20
  "less": "^4.1.3",
@@ -24,11 +24,11 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@babel/cli": "^7.20.7",
27
- "@babel/core": "^7.20.7",
27
+ "@babel/core": "^7.20.12",
28
28
  "@babel/plugin-proposal-class-properties": "^7.18.6",
29
29
  "@babel/plugin-transform-react-jsx": "^7.20.7",
30
30
  "@babel/preset-env": "^7.20.2",
31
- "babel-loader": "^9.1.0",
31
+ "babel-loader": "^9.1.2",
32
32
  "babel-plugin-syntax-jsx": "^6.18.0",
33
33
  "html-webpack-plugin": "^5.5.0",
34
34
  "prettier": "^2.8.1",
@@ -169,7 +169,7 @@ export default class Widget extends Com {
169
169
  is_lead = is_lead || key == 'emails' || key == 'phones'
170
170
  if (field.type === 'number') attr.number = parseInt(field.value)
171
171
  if (field.type === 'datetime') attr.datetime = new sb.Date(field.value).toISOString()
172
- if (field.type === 'list') attr.list = field.value
172
+ if (field.type === 'list') attr.text = field.value
173
173
  if (field.type === 'text' || field.type === 'boolean') attr[field.type] = field.value
174
174
  sb.setUserAttr(user, attr)
175
175
  })
@@ -502,6 +502,8 @@ export default class Widget extends Com {
502
502
  onRemoveItem={(item) => this.onListRemoveItem(key, item)}
503
503
  />
504
504
  )
505
+ // workaround, treat list type like text
506
+ $field = this.renderDropdownField(field)
505
507
  } else if (field.type === 'datetime') {
506
508
  $field = (
507
509
  <input
@@ -47,10 +47,11 @@ export default class Store {
47
47
  this.cookie = inmemCookie
48
48
  }
49
49
 
50
+ cleanLocalStorage()
50
51
  this.pubsub = new sb.Pubsub()
51
- this.kv = new stor8.kv(new stor8.lsdb('sbz2020', this.inmem), 'kv')
52
- this.cache = new stor8.kv(new stor8.lsdb('sbz2020', true), 'kv')
53
- this.chain = new stor8.chain(new stor8.lsdb('cbz2020', true), 'ch')
52
+ this.kv = new stor8.kv(new stor8.lsdb('sbz2023', this.inmem), 'kv')
53
+ this.cache = new stor8.kv(new stor8.lsdb('sbz2023', true), 'kv')
54
+ this.chain = new stor8.chain(new stor8.lsdb('cbz2023', true), 'ch')
54
55
  this.getLocaleContent = this.api.getLocaleContent
55
56
 
56
57
  // dont dupplicate seen
@@ -60,9 +61,9 @@ export default class Store {
60
61
  window.addEventListener('focus', () => this.sendPresence())
61
62
 
62
63
  // faster send rate when has focus
63
- setInterval(() => this.browserVisibility === 'visible' && document.hasFocus() && this.sendPresence(), 20000) // dont bother delete this
64
+ sb.setInterval(() => this.browserVisibility === 'visible' && document.hasFocus() && this.sendPresence(), 20000) // dont bother delete this
64
65
  // slower send rate send when no focus
65
- setInterval(() => (this.browserVisibility !== 'visible' || document.hasFocus()) && this.sendPresence(), 60000) // dont bother delete this
66
+ sb.setInterval(() => (this.browserVisibility !== 'visible' || document.hasFocus()) && this.sendPresence(), 60000) // dont bother delete this
66
67
 
67
68
  onVisibilityChange((val) => {
68
69
  this.browserVisibility = val
@@ -73,8 +74,8 @@ export default class Store {
73
74
  this.device = this.getDeviceInfo()
74
75
 
75
76
  // try to get Google Analytics tracking id and client id by periodically checking it after an interval
76
- const _gaInterval = setInterval(() => {
77
- let user = this.kv.match('user') || {}
77
+ const _gaInterval = sb.setInterval(() => {
78
+ let user = this.cache.match('user') || {}
78
79
  if (!user.id) return // store not init
79
80
  var dev = this.getDeviceInfo()
80
81
  if (!dev.ga_tracking_ids || !dev.ga_client_id) return
@@ -142,7 +143,7 @@ export default class Store {
142
143
  await this.readyGate.entry()
143
144
  this.disconnect('account')
144
145
  await this.reconnect()
145
- setTimeout(this.pubsub.publish('resetCSS'), 10)
146
+ sb.setTimeout(this.pubsub.publish('resetCSS'), 10)
146
147
  }
147
148
 
148
149
  getDeviceInfo() {
@@ -225,7 +226,7 @@ export default class Store {
225
226
  // must ensure only call this function after init is done
226
227
  matchUser = () => {
227
228
  this._touchAcc()
228
- return this.kv.match('user')
229
+ return this.cache.match('user')
229
230
  }
230
231
 
231
232
  suggest_addresses = (keyword) => this.api.suggest_address(keyword)
@@ -293,7 +294,7 @@ export default class Store {
293
294
  listEvents = (id) => {
294
295
  if (!id || id === '*' || typeof id !== 'string') return
295
296
  if (!this.isInsync('events' + id)) {
296
- setTimeout(async () => {
297
+ sb.setTimeout(async () => {
297
298
  await this.readyGate.entry()
298
299
  await this.reconnectGate.entry(undefined, true)
299
300
  if (this.isInsync('events' + id)) return this.reconnectGate.open()
@@ -324,7 +325,16 @@ export default class Store {
324
325
  wsGate = new sb.Gate(true)
325
326
 
326
327
  // last widget screen
327
- matchLastview = () => this.kv.match('lastview') || {}
328
+ matchLastview = () => {
329
+ let lastView = this.kv.match('lastview') || {}
330
+
331
+ // make sure last view of correct user
332
+ let user = this.cache.match('user') || {}
333
+ if (!user.id) return {}
334
+ if (lastView.user_id != user.id) return {}
335
+ return lastView
336
+ }
337
+
328
338
  matchIsOpen = () => !!this.kv.match('isopen') // is widget currently open
329
339
  matchHasManuallyClosed = () => !!this.kv.match('hasManuallyClosed') // true if user has ever closed the widget
330
340
  matchClosePreviewAt = () => this.kv.match('close_preview_at') || 0
@@ -332,8 +342,8 @@ export default class Store {
332
342
  sendPresence = sb.throttle(
333
343
  async () => {
334
344
  await this.readyGate.entry()
335
- if (!sb.get(this.kv.match('user'), 'id')) return // store not init
336
- if (sb.isUserBanned(this.kv.match('user'))) return
345
+ if (!sb.get(this.cache.match('user'), 'id')) return // store not init
346
+ if (sb.isUserBanned(this.cache.match('user'))) return
337
347
 
338
348
  let hasfocus = this.browserVisibility === 'visible' && document.hasFocus()
339
349
  if (!hasfocus) {
@@ -454,10 +464,10 @@ export default class Store {
454
464
  // periodically send seen
455
465
  this.seenQueue = []
456
466
  clearInterval(this._seenInterval)
457
- this._seenInterval = setInterval(() => {
467
+ this._seenInterval = sb.setInterval(() => {
458
468
  // deduplicate
459
469
  this.seenQueue = [...new Set(this.seenQueue)]
460
- let user = this.kv.match('user') || {}
470
+ let user = this.cache.match('user') || {}
461
471
  sb.map(this.seenQueue, (id) => {
462
472
  var events = this.listEvents(id)
463
473
  if (!events) return
@@ -550,7 +560,7 @@ export default class Store {
550
560
 
551
561
  _setUser(user) {
552
562
  user = sb.cloneDeep(user)
553
- let olduser = this.kv.match('user') || {}
563
+ let olduser = this.cache.match('user') || {}
554
564
  var accid = olduser.account_id || user.account_id
555
565
  var id = olduser.id || user.id
556
566
 
@@ -567,7 +577,7 @@ export default class Store {
567
577
  olduser.account_id = accid
568
578
  olduser.id = id
569
579
 
570
- this.kv.put('user', olduser)
580
+ this.cache.put('user', olduser)
571
581
  this.pubsub.publish('account')
572
582
  }
573
583
 
@@ -666,7 +676,7 @@ export default class Store {
666
676
  if (!ev || !ev.type) return
667
677
  ev.created = sb.getMs(ev.created)
668
678
  if (ev.type === 'user_info_updated') {
669
- let user = sb.cloneDeep(this.kv.match('user'))
679
+ let user = sb.cloneDeep(this.cache.match('user'))
670
680
  let attrs = sb.get(ev, 'data.user.attributes') || []
671
681
  sb.map(attrs, (attr) => sb.setUserAttr(user, attr))
672
682
  this._setUser(user)
@@ -674,7 +684,7 @@ export default class Store {
674
684
  }
675
685
 
676
686
  // convo events
677
- let user = this.kv.match('user') || {}
687
+ let user = this.cache.match('user') || {}
678
688
  let cid = sb.convoOfEv(ev)
679
689
  let convo
680
690
 
@@ -702,7 +712,7 @@ export default class Store {
702
712
  // so re-get events of this conversation to ensure we dont miss any event
703
713
  if (ev.type === 'conversation_joined') {
704
714
  let members = sb.get(ev, 'data.conversation.members', [])
705
- let me = sb.find(members, (m) => m.id === this.kv.match('user').id)
715
+ let me = sb.find(members, (m) => m.id === this.cache.match('user').id)
706
716
  if (me) {
707
717
  await this.chain.reload(cid, (type, anchor, limit) => this.listmessageapi(type, anchor, limit))
708
718
  this.markSync('events' + cid)
@@ -733,7 +743,7 @@ export default class Store {
733
743
  }
734
744
 
735
745
  async restConvoEvent(ev) {
736
- let user = this.kv.match('user')
746
+ let user = this.cache.match('user')
737
747
  let cid = sb.convoOfEv(ev)
738
748
  let convo = this.cache.match('convo_' + cid) || {}
739
749
  if (ev.type === 'conversation_state_updated') {
@@ -858,7 +868,7 @@ export default class Store {
858
868
  await this.readyGate.entry()
859
869
  var idempotency = sb.randomString(36)
860
870
 
861
- let user = this.kv.match('user') || {}
871
+ let user = this.cache.match('user') || {}
862
872
 
863
873
  var event = {
864
874
  id: idempotency,
@@ -925,7 +935,7 @@ export default class Store {
925
935
  let count = 0
926
936
 
927
937
  // ignore invalid conversation
928
- let user = this.kv.match('user')
938
+ let user = this.cache.match('user')
929
939
 
930
940
  let channel = sb.get(convo, 'touchpoint.channel', '')
931
941
  if (channel && channel != 'subiz') return
@@ -964,7 +974,11 @@ export default class Store {
964
974
  }
965
975
  }
966
976
  closePreview = () => this.kv.put('close_preview_at', new sb.Date().getTime())
967
- setLastview = (view, opts) => this.kv.put('lastview', {view, opts})
977
+ setLastview = (view, opts) => {
978
+ let user = this.cache.match('user') || {}
979
+ if (!user.id) return // store not init
980
+ this.kv.put('lastview', {user_id: user.id, view, opts})
981
+ }
968
982
 
969
983
  matchLastPluginRun(pluginid) {
970
984
  let log = this.kv.match('plugin_run_logs') || {}
@@ -983,7 +997,7 @@ export default class Store {
983
997
  }
984
998
 
985
999
  sendImpression(id) {
986
- let user = this.kv.match('user') || {}
1000
+ let user = this.cache.match('user') || {}
987
1001
  let log = this.kv.match('plugin_run_logs') || {}
988
1002
  log[id] = {web_plugin_id: id, created: this.now()}
989
1003
  this.kv.put('plugin_run_logs', log)
@@ -998,7 +1012,7 @@ export default class Store {
998
1012
  }
999
1013
 
1000
1014
  sendConversion(id, fields, impressionToken) {
1001
- let user = this.kv.match('user') || {}
1015
+ let user = this.cache.match('user') || {}
1002
1016
  let submission = {account_id: user.account_id, user_id: user.id, fields: fields}
1003
1017
 
1004
1018
  let conv = this.kv.match('conversions') || {}
@@ -1034,7 +1048,7 @@ export default class Store {
1034
1048
  })
1035
1049
 
1036
1050
  // mark conversation as received
1037
- let user = this.kv.match('user') || {}
1051
+ let user = this.cache.match('user') || {}
1038
1052
  for (let i = 0; i < events.length; i++) {
1039
1053
  let ev = events[i].value
1040
1054
 
@@ -1055,15 +1069,15 @@ export default class Store {
1055
1069
  let startms = sb.Date.now()
1056
1070
 
1057
1071
  // store not init
1058
- if (!sb.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 240000)
1072
+ if (!sb.get(this.cache.match('user'), 'id')) return sb.setTimeout(() => this.loopTime(), 240000)
1059
1073
 
1060
1074
  let {body: t, error} = await this.api.time()
1061
- if (error) return setTimeout(() => this.loopTime(), 30000)
1075
+ if (error) return sb.setTimeout(() => this.loopTime(), 30000)
1062
1076
  var latences = Math.abs(sb.Date.now() - startms) / 2
1063
1077
  var serverMs = new sb.Date(t).getTime() + latences
1064
1078
  var localMs = sb.Date.now()
1065
1079
  this.timeDiff = Math.floor(serverMs - localMs)
1066
- setTimeout(() => this.loopTime(), 240000)
1080
+ sb.setTimeout(() => this.loopTime(), 240000)
1067
1081
  }
1068
1082
 
1069
1083
  replaceFileUrl(src) {
@@ -1098,9 +1112,9 @@ export default class Store {
1098
1112
  if ((k || '').startsWith('__sb')) this.cookie.remove(k)
1099
1113
  })
1100
1114
  this.kv.destroy()
1101
- this.kv = new stor8.kv(new stor8.lsdb('sbz2020', this.inmem), 'kv')
1115
+ this.kv = new stor8.kv(new stor8.lsdb('sbz2023', this.inmem), 'kv')
1102
1116
  this.chain.destroy()
1103
- this.chain = new stor8.chain(new stor8.lsdb('cbz2020', true), 'ch')
1117
+ this.chain = new stor8.chain(new stor8.lsdb('cbz2023', true), 'ch')
1104
1118
  }
1105
1119
 
1106
1120
  destroy() {
@@ -1245,3 +1259,18 @@ let tabletCheck =
1245
1259
  /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(
1246
1260
  navigator.userAgent,
1247
1261
  )
1262
+
1263
+ let cleanLocalStorage = () => {
1264
+ try {
1265
+ localStorage
1266
+ } catch (e) {
1267
+ return
1268
+ }
1269
+ sb.setTimeout(() => {
1270
+ for (var key in localStorage) {
1271
+ if ((key && key.startsWith('cbz2020')) || key.startsWith('sbz2020')) {
1272
+ localStorage.removeItem(key)
1273
+ }
1274
+ }
1275
+ })
1276
+ }
@@ -14,8 +14,8 @@ export var stringify = f.contentWindow.JSON.stringify
14
14
  var parse = f.contentWindow.JSON.parse
15
15
  export var Date = f.contentWindow.Date
16
16
  export var requestAnimationFrame = f.contentWindow.requestAnimationFrame
17
- export var setTimeout = f.contentWindow.setTimeout
18
- export var setInterval = f.contentWindow.setInterval
17
+ export var setTimeout = f.contentWindow.setTimeout.bind(f.contentWindow)
18
+ export var setInterval = f.contentWindow.setInterval.bind(f.contentWindow)
19
19
 
20
20
  // convoOfEv extracts the ID of the conversation
21
21
  // that event is sent to