@subiz/widget-v4 4.1.40 → 4.1.42

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 (59) hide show
  1. package/compiled_src/call/css.js +1 -2
  2. package/compiled_src/chatbox/css.js +1 -2
  3. package/compiled_src/common.js +1 -2
  4. package/compiled_src/contact/contact.js +2 -3
  5. package/compiled_src/contact/css.js +1 -2
  6. package/compiled_src/lib.js +5 -2
  7. package/compiled_src/notif/css.js +1 -2
  8. package/compiled_src/plugin.js +1 -2
  9. package/compiled_src/popup/css.js +1 -2
  10. package/compiled_src/popup/tick.core.commonjs.js +1 -2
  11. package/compiled_src/store/api.js +2 -1
  12. package/compiled_src/store/store.js +28 -10
  13. package/compiled_src/util/campaign.js +2 -6
  14. package/compiled_src/util/common.js +12 -26
  15. package/compiled_src/util/index.js +1 -2
  16. package/compiled_src/util/order.js +2 -4
  17. package/compiled_src/util/pubsub.js +3 -6
  18. package/dist/132.js +531 -525
  19. package/dist/18a3a577516.132.js +1 -0
  20. package/dist/18a3a577516.213.js +1 -0
  21. package/dist/18a3a577516.335.js +1 -0
  22. package/dist/{18a02a9c54e.362.js → 18a3a577516.362.js} +1 -1
  23. package/dist/18a3a577516.441.js +1 -0
  24. package/dist/18a3a577516.605.js +1 -0
  25. package/dist/{18a02a9c54e.782.js → 18a3a577516.782.js} +1 -1
  26. package/dist/18a3a577516.app.js +1 -0
  27. package/dist/{18a02a9c54e.index.html → 18a3a577516.index.html} +4 -4
  28. package/dist/{18a02a9c54e.library.html → 18a3a577516.library.html} +4 -4
  29. package/dist/18a3a577516.library.js +1 -0
  30. package/dist/{18a02a9c54e.preview.html → 18a3a577516.preview.html} +1 -1
  31. package/dist/18a3a577516.preview.js +1 -0
  32. package/dist/18a3a577516.screenshoot.js +1 -0
  33. package/dist/18a3a577516.webview.js +1 -0
  34. package/dist/213.js +118 -100
  35. package/dist/335.js +25 -25
  36. package/dist/362.js +1 -1
  37. package/dist/441.js +2441 -2597
  38. package/dist/605.js +50 -50
  39. package/dist/782.js +1 -1
  40. package/dist/HASH +1 -1
  41. package/dist/screenshoot.html +1 -1
  42. package/dist/screenshoot.js +396 -412
  43. package/package.json +11 -11
  44. package/src/lib.js +6 -0
  45. package/src/plugin.js +2 -3
  46. package/src/store/api.js +3 -1
  47. package/src/store/store.js +28 -11
  48. package/dist/18a02a9c54e.132.js +0 -1
  49. package/dist/18a02a9c54e.213.js +0 -1
  50. package/dist/18a02a9c54e.335.js +0 -1
  51. package/dist/18a02a9c54e.441.js +0 -1
  52. package/dist/18a02a9c54e.605.js +0 -1
  53. package/dist/18a02a9c54e.app.js +0 -1
  54. package/dist/18a02a9c54e.library.js +0 -1
  55. package/dist/18a02a9c54e.preview.js +0 -1
  56. package/dist/18a02a9c54e.screenshoot.js +0 -1
  57. package/dist/18a02a9c54e.webview.js +0 -1
  58. /package/dist/{18a02a9c54e.178.js → 18a3a577516.178.js} +0 -0
  59. /package/dist/{18a02a9c54e.678.js → 18a3a577516.678.js} +0 -0
@@ -4,5 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = require('css-loader!less-loader!../../assets/less/notif.less');
8
- exports.default = _default;
7
+ var _default = exports.default = require('css-loader!less-loader!../../assets/less/notif.less');
@@ -4,5 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = require('css-loader!less-loader!../../assets/less/chatbox.less');
8
- exports.default = _default;
7
+ var _default = exports.default = require('css-loader!less-loader!../../assets/less/chatbox.less');
@@ -65,8 +65,7 @@ const getLocale = (plugin, loc) => {
65
65
  return plugin.locale || 'en-US';
66
66
  };
67
67
  exports.getLocale = getLocale;
68
- let langMessages = {};
69
- exports.langMessages = langMessages;
68
+ let langMessages = exports.langMessages = {};
70
69
  let downloadLock = false;
71
70
  function downloadLanguage(store, locale, force) {
72
71
  if (downloadLock) return new Promise(resolve => _index.default.setTimeout(() => downloadLanguage(store, locale, force).then(resolve), 100));
@@ -356,10 +356,9 @@ function replaceCssVariable(css, setting) {
356
356
  }
357
357
  return ret.join('');
358
358
  }
359
- const DEFVAL = {
359
+ const DEFVAL = exports.DEFVAL = {
360
360
  font_size: '16px',
361
361
  font_family: 'roboto',
362
362
  text_color: '#333',
363
363
  primary_color: '#333'
364
- };
365
- exports.DEFVAL = DEFVAL;
364
+ };
@@ -4,5 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = require('css-loader!less-loader!../../assets/less/contact.less');
8
- exports.default = _default;
7
+ var _default = exports.default = require('css-loader!less-loader!../../assets/less/contact.less');
@@ -205,6 +205,10 @@ class Widget {
205
205
  _overrideDeviceType(type) {
206
206
  this.store.overrideDeviceType(type);
207
207
  }
208
+ unload() {
209
+ if (this.pluginMgr) this.pluginMgr.destroy();
210
+ this.store.destroy();
211
+ }
208
212
  _overridePlugin(plugins) {
209
213
  this.store.overridePlugin(plugins);
210
214
  }
@@ -239,5 +243,4 @@ class Widget {
239
243
  }
240
244
  }
241
245
  window.__sbz_WIDGET = Widget;
242
- var _default = Widget;
243
- exports.default = _default;
246
+ var _default = exports.default = Widget;
@@ -4,5 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = require('css-loader!less-loader!../../assets/less/notif.less');
8
- exports.default = _default;
7
+ var _default = exports.default = require('css-loader!less-loader!../../assets/less/notif.less');
@@ -295,8 +295,7 @@ class PluginMgr {
295
295
  }
296
296
  destroy() {
297
297
  _index.default.map(this.pluginM, (conf, id) => {
298
- if (this.pluginM[id]) return;
299
- this.pluginM[id].destroy();
298
+ conf.destroy();
300
299
  delete this.pluginM[id];
301
300
  });
302
301
  this._destroy = true;
@@ -4,5 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = require('css-loader!less-loader!../../assets/less/popup.less');
8
- exports.default = _default;
7
+ var _default = exports.default = require('css-loader!less-loader!../../assets/less/popup.less');
@@ -1333,5 +1333,4 @@ let obj = function () {
1333
1333
  module.exports = API;
1334
1334
  return module.exports;
1335
1335
  }();
1336
- var _default = obj;
1337
- exports.default = _default;
1336
+ var _default = exports.default = obj;
@@ -145,8 +145,9 @@ class _default {
145
145
  let outuser;
146
146
  for (let i = 0; true; i++) {
147
147
  outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-user-ref', this.ref).setParser('json').get(`/accounts/${this.accid}/users/${this.ref}`);
148
+ if (outuser.error && _index.default.get(outuser, 'body.code', '').indexOf('locked_account') != -1) break;
148
149
  if (!_index.default.get(outuser, 'body.id')) {
149
- let sleeptime = Math.min(2000 + i * 200, 60000);
150
+ let sleeptime = Math.min(2000 + i * 400, 60000);
150
151
  await _index.default.sleep(sleeptime);
151
152
  continue;
152
153
  }
@@ -64,6 +64,7 @@ class Store {
64
64
  return this.cache.match('convo_' + id);
65
65
  });
66
66
  _defineProperty(this, "fetchConvo", async cid => {
67
+ if (this._die) return dieErr;
67
68
  await this.readyGate.entry();
68
69
  await this.reconnectGate.entry(undefined, true);
69
70
  if (this.isInsync(cid)) return this.reconnectGate.open();
@@ -119,6 +120,7 @@ class Store {
119
120
  _defineProperty(this, "matchHasManuallyClosed", () => !!this.kv.match('hasManuallyClosed'));
120
121
  _defineProperty(this, "matchClosePreviewAt", () => this.kv.match('close_preview_at') || 0);
121
122
  _defineProperty(this, "sendPresence", _index.default.throttle(async () => {
123
+ if (this._die) return dieErr;
122
124
  await this.readyGate.entry();
123
125
  if (!_index.default.get(this.cache.match('user'), 'id')) return;
124
126
  if (_index.default.isUserBanned(this.cache.match('user'))) return;
@@ -165,6 +167,7 @@ class Store {
165
167
  });
166
168
  _defineProperty(this, "timeDiff", 0);
167
169
  this.g_sync = {};
170
+ this._die = false;
168
171
  this.forceDevice = null;
169
172
  this.forcePlugins = {};
170
173
  this.forceAcc = {};
@@ -192,11 +195,18 @@ class Store {
192
195
  this.chain = new _storage.default.chain(new _storage.default.lsdb('cbz2023', true), 'ch');
193
196
  this.getLocaleContent = this.api.getLocaleContent;
194
197
  this.g_haveSentSeenM = {};
195
- window.addEventListener('blur', () => this.sendPresence());
196
- window.addEventListener('focus', () => this.sendPresence());
197
- _index.default.setInterval(() => this.browserVisibility === 'visible' && document.hasFocus() && this.sendPresence(), 20000);
198
- _index.default.setInterval(() => (this.browserVisibility !== 'visible' || document.hasFocus()) && this.sendPresence(), 60000);
198
+ window.addEventListener('blur', this.sendPresence);
199
+ window.addEventListener('focus', this.sendPresence);
200
+ this._presenceInterval1 = _index.default.setInterval(() => {
201
+ if (this._die) return _index.default.clearInterval(this._presenceInterval1);
202
+ if (this.browserVisibility === 'visible' && document.hasFocus()) this.sendPresence();
203
+ }, 20000);
204
+ this._presenceInterval2 = _index.default.setInterval(() => {
205
+ if (this._die) return _index.default.clearInterval(this._presenceInterval2);
206
+ if (this.browserVisibility !== 'visible' || document.hasFocus()) this.sendPresence();
207
+ }, 60000);
199
208
  onVisibilityChange(val => {
209
+ if (this._die) return;
200
210
  this.browserVisibility = val;
201
211
  this.sendPresence();
202
212
  });
@@ -304,6 +314,7 @@ class Store {
304
314
  return page_loaded;
305
315
  }
306
316
  overridePlugin(plugins) {
317
+ if (this._die) return dieErr;
307
318
  if (!Array.isArray(plugins)) throw 'plugins must be be an array';
308
319
  let pluginM = {};
309
320
  _index.default.map(plugins, function (plugin) {
@@ -349,9 +360,7 @@ class Store {
349
360
  }
350
361
  }
351
362
  }
352
- if (this.cookie.get('__sbref', userRef) != userRef) {
353
- cleanMyLocalStorage();
354
- }
363
+ if (this.cookie.get('__sbref', userRef) != userRef) cleanMyLocalStorage();
355
364
  this.api.setAuth({
356
365
  accid: accid
357
366
  });
@@ -361,7 +370,7 @@ class Store {
361
370
  mask: mask,
362
371
  ref: userRef
363
372
  });
364
- if (user.error) return;
373
+ if (user.error) return console.error(user);
365
374
  if (this.realtime) this.realtime.stop();
366
375
  if (this.fake) this.realtime = new _realtime_fake.default();else this.realtime = new Realtime(this.RealtimeURL, {
367
376
  account_id: accid,
@@ -377,6 +386,7 @@ class Store {
377
386
  return user;
378
387
  }
379
388
  async login(accid, user_id, tokenGenerator) {
389
+ if (this._die) return dieErr;
380
390
  let user = await this.api.setAuth({
381
391
  accid: accid,
382
392
  profile_id: user_id,
@@ -409,6 +419,7 @@ class Store {
409
419
  this.seenQueue = [];
410
420
  _index.default.clearInterval(this._seenInterval);
411
421
  this._seenInterval = _index.default.setInterval(() => {
422
+ if (this._die) return _index.default.clearInterval(this._seenInterval);
412
423
  this.seenQueue = [...new Set(this.seenQueue)];
413
424
  let user = this.cache.match('user') || {};
414
425
  _index.default.map(this.seenQueue, id => {
@@ -558,6 +569,7 @@ class Store {
558
569
  this.wsGate.open();
559
570
  }
560
571
  async _onWs(ev) {
572
+ if (this._die) return;
561
573
  if (!ev || !ev.type) return;
562
574
  ev.created = _index.default.getMs(ev.created);
563
575
  if (ev.type === 'user_info_updated') {
@@ -901,6 +913,7 @@ class Store {
901
913
  return [events, anchor];
902
914
  }
903
915
  async loopTime() {
916
+ if (this._die) return;
904
917
  let startms = _index.default.Date.now();
905
918
  if (!_index.default.get(this.cache.match('user'), 'id')) return _index.default.setTimeout(() => this.loopTime(), 240000);
906
919
  let {
@@ -946,9 +959,13 @@ class Store {
946
959
  }
947
960
  destroy() {
948
961
  this._die = true;
949
- this.clearBrowserData();
962
+ if (this.kv) this.kv.destroy();
963
+ if (this.chain) this.chain.destroy();
964
+ _index.default.clearInterval(this._seenInterval);
950
965
  if (this.realtime) this.realtime.stop();
951
966
  this.readyGate.close();
967
+ window.removeEventListener('blur', this.sendPresence);
968
+ window.removeEventListener('focus', this.sendPresence);
952
969
  }
953
970
  }
954
971
  exports.default = Store;
@@ -1113,4 +1130,5 @@ var xhrsend = function (method, url, body, cb) {
1113
1130
  request.open(method, url);
1114
1131
  if (body) request.setRequestHeader('content-type', 'text/plain');
1115
1132
  request.send(body);
1116
- };
1133
+ };
1134
+ const dieErr = new Error('sdk unloaded');
@@ -37,9 +37,7 @@ function trackAreaClicked(selector, cb) {
37
37
  on('click', selector, cb);
38
38
  });
39
39
  }
40
- function trackInactivity() {
41
- let seconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
42
- let cb = arguments.length > 1 ? arguments[1] : undefined;
40
+ function trackInactivity(seconds = 0, cb) {
43
41
  let events = ['scroll', 'keyup', 'keydown', 'mousemove', 'mousewheel', 'mouseenter', 'mouseover', 'mousedown', 'touchstart', 'touchmove', 'touchenter'];
44
42
  let inactiveSeconds = 0;
45
43
  let resetTime = () => {
@@ -62,9 +60,7 @@ let timeOnPage = 0;
62
60
  common.setInterval(() => {
63
61
  timeOnPage += 5;
64
62
  }, 5000);
65
- function trackTimeOnPage() {
66
- let seconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
67
- let cb = arguments.length > 1 ? arguments[1] : undefined;
63
+ function trackTimeOnPage(seconds = 0, cb) {
68
64
  if (seconds < 1) {
69
65
  return common.setTimeout(function () {
70
66
  cb(seconds);
@@ -75,23 +75,15 @@ function parseJSON(str) {
75
75
  var f = document.createElement('iframe');
76
76
  f.style.display = 'none';
77
77
  document.documentElement.appendChild(f);
78
- var stringify = f.contentWindow.JSON.stringify;
79
- exports.stringify = stringify;
78
+ var stringify = exports.stringify = f.contentWindow.JSON.stringify;
80
79
  var parse = f.contentWindow.JSON.parse;
81
- var Date = f.contentWindow.Date;
82
- exports.Date = Date;
83
- var requestAnimationFrame = f.contentWindow.requestAnimationFrame;
84
- exports.requestAnimationFrame = requestAnimationFrame;
85
- var setTimeout = f.contentWindow.setTimeout.bind(f.contentWindow);
86
- exports.setTimeout = setTimeout;
87
- var setInterval = f.contentWindow.setInterval.bind(f.contentWindow);
88
- exports.setInterval = setInterval;
89
- var clearInterval = f.contentWindow.clearInterval.bind(f.contentWindow);
90
- exports.clearInterval = clearInterval;
91
- var clearTimeout = f.contentWindow.clearTimeout.bind(f.contentWindow);
92
- exports.clearTimeout = clearTimeout;
93
- var XMLHttpRequest = f.contentWindow.XMLHttpRequest;
94
- exports.XMLHttpRequest = XMLHttpRequest;
80
+ var Date = exports.Date = f.contentWindow.Date;
81
+ var requestAnimationFrame = exports.requestAnimationFrame = f.contentWindow.requestAnimationFrame;
82
+ var setTimeout = exports.setTimeout = f.contentWindow.setTimeout.bind(f.contentWindow);
83
+ var setInterval = exports.setInterval = f.contentWindow.setInterval.bind(f.contentWindow);
84
+ var clearInterval = exports.clearInterval = f.contentWindow.clearInterval.bind(f.contentWindow);
85
+ var clearTimeout = exports.clearTimeout = f.contentWindow.clearTimeout.bind(f.contentWindow);
86
+ var XMLHttpRequest = exports.XMLHttpRequest = f.contentWindow.XMLHttpRequest;
95
87
  function convoOfEv(ev) {
96
88
  if (!ev) return '';
97
89
  switch (ev.type) {
@@ -159,10 +151,7 @@ function getMsgField(ev, fieldName) {
159
151
  function isObject(item) {
160
152
  return item && typeof item === 'object' && !Array.isArray(item);
161
153
  }
162
- function merge(target) {
163
- for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
164
- sources[_key - 1] = arguments[_key];
165
- }
154
+ function merge(target, ...sources) {
166
155
  if (!sources.length) return target;
167
156
  const source = sources.shift();
168
157
  if (isObject(target) && isObject(source)) {
@@ -555,9 +544,8 @@ function setCss(id, $css, css) {
555
544
  $css.appendChild(document.createTextNode(css));
556
545
  }
557
546
  }
558
- const DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = 'https://vcdn.subiz-cdn.com/file/bubble_11.svg?v=5';
559
- exports.DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL;
560
- const DEFVAL = {
547
+ const DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = exports.DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = 'https://vcdn.subiz-cdn.com/file/bubble_11.svg?v=5';
548
+ const DEFVAL = exports.DEFVAL = {
561
549
  primary_color: '#0265FF',
562
550
  secondary_color: '#555555',
563
551
  background: 'linear-gradient(280.16deg, #0053d3 22.03%, #0265ff 78.2%)',
@@ -584,7 +572,6 @@ const DEFVAL = {
584
572
  widget_position: 'fixed',
585
573
  z_index: 2000000000
586
574
  };
587
- exports.DEFVAL = DEFVAL;
588
575
  function js2css(js, onlyprops, variables) {
589
576
  var newjs = {};
590
577
  for (var prop in js) {
@@ -963,8 +950,7 @@ function getUrlParameter() {
963
950
  }
964
951
  var sleep = ms => new Promise(res => setTimeout(res, ms));
965
952
  exports.sleep = sleep;
966
- function formatCurrency(val) {
967
- let currency = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'VND';
953
+ function formatCurrency(val, currency = 'VND') {
968
954
  let currencyObj = ALL_CURRENCIES.find(cur => cur.code === currency) || {
969
955
  name: 'Dong',
970
956
  code: 'VND',
@@ -21,5 +21,4 @@ sb.Pubsub = require('./pubsub.js').default;
21
21
  sb = Object.assign(sb, extractor);
22
22
  sb = Object.assign(sb, campaign);
23
23
  sb = Object.assign(sb, order);
24
- var _default = sb;
25
- exports.default = _default;
24
+ var _default = exports.default = sb;
@@ -14,8 +14,7 @@ op.map = common.map;
14
14
  op.each = common.each;
15
15
  op.size = common.size;
16
16
  op.find = common.find;
17
- function getProductPropName(product) {
18
- let seperator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' - ';
17
+ function getProductPropName(product, seperator = ' - ') {
19
18
  let options = op.get(product, 'options', []);
20
19
  let props = op.get(product, 'props', []);
21
20
  let multiPropsOptions = op.filter(options, option => op.size(option.values) > 1);
@@ -26,8 +25,7 @@ function getProductPropName(product) {
26
25
  });
27
26
  return names.join(seperator);
28
27
  }
29
- function getOrderDisplayName() {
30
- let order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
+ function getOrderDisplayName(order = {}) {
31
29
  return order.number || order.id || '';
32
30
  }
33
31
  function displayOrderShippingAddress(order, isShorten) {
@@ -14,12 +14,9 @@ class Pubsub {
14
14
  }
15
15
  publish(topic, payload, payload2, payload3) {
16
16
  this.listeners[topic] = filter(this.listeners[topic], sub => sub.obj._isMounted);
17
- map(this.listeners[topic], _ref => {
18
- let {
19
- cb
20
- } = _ref;
21
- return cb(payload, payload2, payload3);
22
- });
17
+ map(this.listeners[topic], ({
18
+ cb
19
+ }) => cb(payload, payload2, payload3));
23
20
  }
24
21
  on2(obj, topic, cb) {
25
22
  if (!this.listeners[topic]) this.listeners[topic] = [];