@subiz/widget-v4 4.1.32 → 4.1.33

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.
@@ -32,6 +32,7 @@ function Plugin(plugin, store, $container, lib) {
32
32
  if (plugin.type === 'popup' && store.isConverted(plugin.id)) return;
33
33
  let lastrun = store.matchLastPluginRun(plugin.id);
34
34
  if (plugin.type === 'chatbox' || plugin.type === 'notification') lastrun = undefined;
35
+ if (!plugin.enabled) return;
35
36
  let match = _index.default.checkRunConditions(plugin.initiative_frequency, plugin.conditions, lastrun, store);
36
37
  if (!match) return;
37
38
  state = 'running';
@@ -10,7 +10,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
10
10
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
11
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
12
  const ajax = require('@subiz/ajax/src/ajax.js');
13
- ajax.env.XMLHttpRequest = window.XMLHttpRequest;
13
+ ajax.env.XMLHttpRequest = _index.default.XMLHttpRequest;
14
14
  function jsonifyTextPlain(param, done) {
15
15
  let req = param.request;
16
16
  if (req.content_type === 'text/plain' && req.body !== undefined) req.body = _index.default.stringify(req.body);
@@ -41,7 +41,7 @@ class _default {
41
41
  _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/seen`));
42
42
  _defineProperty(this, "getConversation", cid => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`));
43
43
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
44
- _defineProperty(this, "sendEvent", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
44
+ _defineProperty(this, "sendEvent", data => this.apireq.addQuery('shorten', true).post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
45
45
  _defineProperty(this, "sendTyping", cid => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`));
46
46
  _defineProperty(this, "sendLostFocus", (device, productid, source_id, sku) => this.sendEvent({
47
47
  by: {
@@ -367,7 +367,7 @@ class Store {
367
367
  account_id: accid,
368
368
  user_ref: userRef,
369
369
  user_mask: mask
370
- });
370
+ }, xhrsend);
371
371
  this.realtime.onEvent(this.onWs.bind(this));
372
372
  this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id));
373
373
  this.seenLoop();
@@ -1080,4 +1080,29 @@ let cleanMyLocalStorage = () => {
1080
1080
  }
1081
1081
  }
1082
1082
  });
1083
+ };
1084
+ function dofetch(method, url, body, cb) {
1085
+ let headers = {};
1086
+ if (body) headers['content-type'] = 'text/plain';
1087
+ fetch(url, {
1088
+ method: method,
1089
+ headers: headers,
1090
+ body: body
1091
+ }).then(res => res.text().then(text => cb && cb(text, res.status))).catch(err => cb && cb(err, -1));
1092
+ }
1093
+ var xhrsend = function (method, url, body, cb) {
1094
+ if (typeof _index.default.XMLHttpRequest === 'undefined') return dofetch(method, url, body, cb);
1095
+ var request = new _index.default.XMLHttpRequest();
1096
+ request.onreadystatechange = function (e) {
1097
+ if (request.readyState !== 4) return;
1098
+ cb && cb(request.responseText, request.status);
1099
+ cb = undefined;
1100
+ };
1101
+ request.onerror = function () {
1102
+ cb && cb(request.responseText, -1);
1103
+ cb = undefined;
1104
+ };
1105
+ request.open(method, url);
1106
+ if (body) request.setRequestHeader('content-type', 'text/plain');
1107
+ request.send(body);
1083
1108
  };
@@ -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);
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Date = exports.DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = exports.DEFVAL = void 0;
6
+ exports.XMLHttpRequest = exports.Date = exports.DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = exports.DEFVAL = void 0;
7
7
  exports.agentsOfConvo = agentsOfConvo;
8
8
  exports.checkRunConditions = checkRunConditions;
9
9
  exports.clearTimeout = exports.clearInterval = void 0;
@@ -90,6 +90,8 @@ var clearInterval = f.contentWindow.clearInterval.bind(f.contentWindow);
90
90
  exports.clearInterval = clearInterval;
91
91
  var clearTimeout = f.contentWindow.clearTimeout.bind(f.contentWindow);
92
92
  exports.clearTimeout = clearTimeout;
93
+ var XMLHttpRequest = f.contentWindow.XMLHttpRequest;
94
+ exports.XMLHttpRequest = XMLHttpRequest;
93
95
  function convoOfEv(ev) {
94
96
  if (!ev) return '';
95
97
  switch (ev.type) {
@@ -157,10 +159,7 @@ function getMsgField(ev, fieldName) {
157
159
  function isObject(item) {
158
160
  return item && typeof item === 'object' && !Array.isArray(item);
159
161
  }
160
- function merge(target) {
161
- for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
162
- sources[_key - 1] = arguments[_key];
163
- }
162
+ function merge(target, ...sources) {
164
163
  if (!sources.length) return target;
165
164
  const source = sources.shift();
166
165
  if (isObject(target) && isObject(source)) {
@@ -959,8 +958,7 @@ function getUrlParameter() {
959
958
  }
960
959
  var sleep = ms => new Promise(res => setTimeout(res, ms));
961
960
  exports.sleep = sleep;
962
- function formatCurrency(val) {
963
- let currency = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'VND';
961
+ function formatCurrency(val, currency = 'VND') {
964
962
  let currencyObj = ALL_CURRENCIES.find(cur => cur.code === currency) || {
965
963
  name: 'Dong',
966
964
  code: 'VND',
@@ -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] = [];
package/dist/HASH ADDED
@@ -0,0 +1 @@
1
+ 188ffa9633f
@@ -0,0 +1,13 @@
1
+ let hash = 'XXXXXXXX' // do not change, will be replaced to real hash
2
+
3
+ window._subiz_init_2094850928430 = true
4
+ window._subiz_init_2094850928430_keep_loading = true
5
+ var tag = document.createElement('script')
6
+ tag.async = 1
7
+ tag.src = 'https://public-gcs.subiz-cdn.com/widget-v4/public/' + hash + '.app.js'
8
+ document.body.appendChild(tag)
9
+
10
+ // record which domain still use old code
11
+ var xhttp = new XMLHttpRequest()
12
+ xhttp.open('GET', 'https://api.sbz.vn/4.0/old', true)
13
+ xhttp.send()
@@ -1373,6 +1373,7 @@ __webpack_require__.r(__webpack_exports__);
1373
1373
  /* harmony export */ DEFVAL: () => (/* binding */ DEFVAL),
1374
1374
  /* harmony export */ DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL: () => (/* binding */ DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL),
1375
1375
  /* harmony export */ Date: () => (/* binding */ Date),
1376
+ /* harmony export */ XMLHttpRequest: () => (/* binding */ XMLHttpRequest),
1376
1377
  /* harmony export */ agentsOfConvo: () => (/* binding */ agentsOfConvo),
1377
1378
  /* harmony export */ checkRunConditions: () => (/* binding */ checkRunConditions),
1378
1379
  /* harmony export */ clearInterval: () => (/* binding */ clearInterval),
@@ -1454,6 +1455,7 @@ var setTimeout = f.contentWindow.setTimeout.bind(f.contentWindow);
1454
1455
  var setInterval = f.contentWindow.setInterval.bind(f.contentWindow);
1455
1456
  var clearInterval = f.contentWindow.clearInterval.bind(f.contentWindow);
1456
1457
  var clearTimeout = f.contentWindow.clearTimeout.bind(f.contentWindow);
1458
+ var XMLHttpRequest = f.contentWindow.XMLHttpRequest;
1457
1459
  function convoOfEv(ev) {
1458
1460
  if (!ev) return '';
1459
1461
  switch (ev.type) {
@@ -4038,7 +4040,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
4038
4040
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4039
4041
 
4040
4042
  const ajax = __webpack_require__(7460);
4041
- ajax.env.XMLHttpRequest = window.XMLHttpRequest;
4043
+ ajax.env.XMLHttpRequest = util/* default */.Z.XMLHttpRequest;
4042
4044
  function jsonifyTextPlain(param, done) {
4043
4045
  let req = param.request;
4044
4046
  if (req.content_type === 'text/plain' && req.body !== undefined) req.body = util/* default */.Z.stringify(req.body);
@@ -4069,7 +4071,7 @@ function jsonifyTextPlain(param, done) {
4069
4071
  _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/seen`));
4070
4072
  _defineProperty(this, "getConversation", cid => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`));
4071
4073
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
4072
- _defineProperty(this, "sendEvent", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
4074
+ _defineProperty(this, "sendEvent", data => this.apireq.addQuery('shorten', true).post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
4073
4075
  _defineProperty(this, "sendTyping", cid => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`));
4074
4076
  _defineProperty(this, "sendLostFocus", (device, productid, source_id, sku) => this.sendEvent({
4075
4077
  by: {
@@ -5079,7 +5081,7 @@ class Store {
5079
5081
  account_id: accid,
5080
5082
  user_ref: userRef,
5081
5083
  user_mask: mask
5082
- });
5084
+ }, xhrsend);
5083
5085
  this.realtime.onEvent(this.onWs.bind(this));
5084
5086
  this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id));
5085
5087
  this.seenLoop();
@@ -5792,6 +5794,31 @@ let cleanMyLocalStorage = () => {
5792
5794
  }
5793
5795
  });
5794
5796
  };
5797
+ function dofetch(method, url, body, cb) {
5798
+ let headers = {};
5799
+ if (body) headers['content-type'] = 'text/plain';
5800
+ fetch(url, {
5801
+ method: method,
5802
+ headers: headers,
5803
+ body: body
5804
+ }).then(res => res.text().then(text => cb && cb(text, res.status))).catch(err => cb && cb(err, -1));
5805
+ }
5806
+ var xhrsend = function (method, url, body, cb) {
5807
+ if (typeof util/* default */.Z.XMLHttpRequest === 'undefined') return dofetch(method, url, body, cb);
5808
+ var request = new util/* default */.Z.XMLHttpRequest();
5809
+ request.onreadystatechange = function (e) {
5810
+ if (request.readyState !== 4) return;
5811
+ cb && cb(request.responseText, request.status);
5812
+ cb = undefined;
5813
+ };
5814
+ request.onerror = function () {
5815
+ cb && cb(request.responseText, -1);
5816
+ cb = undefined;
5817
+ };
5818
+ request.open(method, url);
5819
+ if (body) request.setRequestHeader('content-type', 'text/plain');
5820
+ request.send(body);
5821
+ };
5795
5822
  // EXTERNAL MODULE: ./src/common.js
5796
5823
  var common = __webpack_require__(2493);
5797
5824
  // EXTERNAL MODULE: ./node_modules/preact/dist/preact.module.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.32",
3
+ "version": "4.1.33",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -32,8 +32,8 @@
32
32
  "babel-plugin-syntax-jsx": "^6.18.0",
33
33
  "html-webpack-plugin": "^5.5.3",
34
34
  "prettier": "^2.8.8",
35
- "puppeteer": "^20.7.2",
36
- "webpack": "^5.87.0",
35
+ "puppeteer": "^20.7.3",
36
+ "webpack": "^5.88.0",
37
37
  "webpack-bundle-analyzer": "^4.9.0",
38
38
  "webpack-cli": "^5.1.4",
39
39
  "webpack-dev-server": "^4.15.1"
package/src/store/api.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import sb from '../util/index.js'
2
2
  const ajax = require('@subiz/ajax/src/ajax.js')
3
- ajax.env.XMLHttpRequest = window.XMLHttpRequest
3
+ ajax.env.XMLHttpRequest = sb.XMLHttpRequest
4
4
 
5
5
  function jsonifyTextPlain(param, done) {
6
6
  let req = param.request
@@ -216,7 +216,8 @@ export default class {
216
216
 
217
217
  getConversation = (cid) => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`)
218
218
  getLocaleContent = (locale) => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`)
219
- sendEvent = (data) => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, data)
219
+ sendEvent = (data) =>
220
+ this.apireq.addQuery('shorten', true).post(`/accounts/${this.accid}/users/${this.uid}/events`, data)
220
221
  sendTyping = (cid) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`)
221
222
 
222
223
  sendLostFocus = (device, productid, source_id, sku) =>
@@ -420,7 +420,8 @@ export default class Store {
420
420
 
421
421
  if (this.realtime) this.realtime.stop()
422
422
  if (this.fake) this.realtime = new RealtimeFake()
423
- else this.realtime = new Realtime(this.RealtimeURL, {account_id: accid, user_ref: userRef, user_mask: mask})
423
+ else
424
+ this.realtime = new Realtime(this.RealtimeURL, {account_id: accid, user_ref: userRef, user_mask: mask}, xhrsend)
424
425
 
425
426
  this.realtime.onEvent(this.onWs.bind(this))
426
427
  this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id))
@@ -654,7 +655,7 @@ export default class Store {
654
655
 
655
656
  // send the content view, the first presence and record domain
656
657
  async track() {
657
- let out = await this.api.sendContentView(
658
+ let out = await this.api.sendContentView(
658
659
  this.device,
659
660
  location.href,
660
661
  document.title,
@@ -1302,3 +1303,31 @@ let cleanMyLocalStorage = () => {
1302
1303
  }
1303
1304
  })
1304
1305
  }
1306
+
1307
+ function dofetch(method, url, body, cb) {
1308
+ let headers = {}
1309
+ if (body) headers['content-type'] = 'text/plain'
1310
+ fetch(url, {method: method, headers: headers, body: body})
1311
+ .then((res) => res.text().then((text) => cb && cb(text, res.status)))
1312
+ .catch((err) => cb && cb(err, -1))
1313
+ }
1314
+
1315
+ // xhrsend sends an HTTP request
1316
+ var xhrsend = function (method, url, body, cb) {
1317
+ if (typeof sb.XMLHttpRequest === 'undefined') return dofetch(method, url, body, cb)
1318
+ var request = new sb.XMLHttpRequest()
1319
+ request.onreadystatechange = function (e) {
1320
+ if (request.readyState !== 4) return
1321
+ cb && cb(request.responseText, request.status)
1322
+ cb = undefined // dont call cb anymore
1323
+ }
1324
+
1325
+ request.onerror = function () {
1326
+ cb && cb(request.responseText, -1) // network error
1327
+ cb = undefined // dont call cb anymore
1328
+ }
1329
+
1330
+ request.open(method, url)
1331
+ if (body) request.setRequestHeader('content-type', 'text/plain')
1332
+ request.send(body)
1333
+ }
@@ -18,6 +18,7 @@ export var setTimeout = f.contentWindow.setTimeout.bind(f.contentWindow)
18
18
  export var setInterval = f.contentWindow.setInterval.bind(f.contentWindow)
19
19
  export var clearInterval = f.contentWindow.clearInterval.bind(f.contentWindow)
20
20
  export var clearTimeout = f.contentWindow.clearTimeout.bind(f.contentWindow)
21
+ export var XMLHttpRequest = f.contentWindow.XMLHttpRequest
21
22
 
22
23
  // convoOfEv extracts the ID of the conversation
23
24
  // that event is sent to