@subiz/widget-v4 4.0.58 → 4.0.63

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 (156) hide show
  1. package/assets/img/caret.svg +1 -0
  2. package/assets/img/done_green.svg +4 -0
  3. package/assets/img/empty_1.svg +11 -0
  4. package/assets/img/ghn.svg +17 -0
  5. package/assets/img/ghtk.svg +18 -0
  6. package/assets/img/home.svg +1 -0
  7. package/assets/img/info.svg +1 -0
  8. package/assets/img/loader.svg +1 -0
  9. package/assets/img/map-pin.svg +1 -0
  10. package/assets/img/not_found_search.png +0 -0
  11. package/assets/img/package.svg +5 -0
  12. package/assets/img/package_fade.svg +1 -0
  13. package/assets/img/phone.svg +1 -0
  14. package/assets/img/search.svg +1 -0
  15. package/assets/img/shop.svg +1 -0
  16. package/assets/img/shop_faded.svg +1 -0
  17. package/assets/img/user.svg +1 -0
  18. package/assets/img/x.svg +5 -0
  19. package/assets/less/chatbox.less +35 -0
  20. package/assets/less/dropdown_select.less +130 -0
  21. package/assets/less/form.less +7 -20
  22. package/assets/less/order.less +489 -0
  23. package/assets/less/rating.less +3 -8
  24. package/compiled_src/call/call.js +12 -15
  25. package/compiled_src/chatbox/DropdownSelect.js +239 -0
  26. package/compiled_src/chatbox/Event.js +4 -2
  27. package/compiled_src/chatbox/Events.js +1 -0
  28. package/compiled_src/chatbox/MessageInput.js +4 -7
  29. package/compiled_src/chatbox/Order.js +281 -0
  30. package/compiled_src/chatbox/OrderAttachments.js +2 -1
  31. package/compiled_src/chatbox/Rating.js +7 -10
  32. package/compiled_src/chatbox/TextMessage.js +9 -2
  33. package/compiled_src/chatbox/Widget.js +40 -3
  34. package/compiled_src/chatbox/main.js +2 -1
  35. package/compiled_src/chatbox/spinner.js +1 -1
  36. package/compiled_src/chatbox/time.js +3 -1
  37. package/compiled_src/common.js +40 -1
  38. package/compiled_src/contact/contact.js +7 -12
  39. package/compiled_src/lib.js +9 -14
  40. package/compiled_src/notif/notif.js +12 -15
  41. package/compiled_src/order/address_picker.js +241 -0
  42. package/compiled_src/order/icon.js +62 -0
  43. package/compiled_src/order/index.js +113 -0
  44. package/compiled_src/order/order.js +1220 -0
  45. package/compiled_src/plugin.js +9 -42
  46. package/compiled_src/popup/countdown.js +4 -7
  47. package/compiled_src/popup/popup.js +40 -13
  48. package/compiled_src/store/api.js +80 -90
  49. package/compiled_src/store/api_fake.js +55 -82
  50. package/compiled_src/store/store.js +163 -158
  51. package/compiled_src/util/common.js +40 -4
  52. package/dist/0b82fa7e5c3b07b40a44.png +1 -0
  53. package/dist/0f4af006e38ee8b93633.png +1 -0
  54. package/dist/{74.js → 132.js} +2234 -236
  55. package/dist/178.js +341 -174
  56. package/dist/17e757ccadd.132.js +1 -0
  57. package/dist/17e757ccadd.178.js +1 -0
  58. package/dist/17e757ccadd.213.js +1 -0
  59. package/dist/17e757ccadd.335.js +1 -0
  60. package/dist/17e757ccadd.362.js +1 -0
  61. package/dist/17e757ccadd.441.js +1 -0
  62. package/dist/17e757ccadd.605.js +1 -0
  63. package/dist/17e757ccadd.678.js +1 -0
  64. package/dist/17e757ccadd.782.js +1 -0
  65. package/dist/17e757ccadd.app.js +1 -0
  66. package/dist/{17d938a5acb.index.html → 17e757ccadd.index.html} +3 -18
  67. package/dist/{17d938a5acb.library.html → 17e757ccadd.library.html} +3 -18
  68. package/dist/17e757ccadd.library.js +1 -0
  69. package/dist/{17d938a5acb.preview.html → 17e757ccadd.preview.html} +1 -1
  70. package/dist/17e757ccadd.preview.js +1 -0
  71. package/dist/17e757ccadd.screenshoot.js +1 -0
  72. package/dist/1ea1c6cd21d25176810c.png +1 -0
  73. package/dist/213.js +46 -87
  74. package/dist/292d42404e1b03398f61.png +1 -0
  75. package/dist/312d376370831b7bea83.png +1 -0
  76. package/dist/313d1bfc1cf776d1aefe.png +1 -0
  77. package/dist/335.js +408 -0
  78. package/dist/362.js +71 -21
  79. package/dist/441.js +69 -43
  80. package/dist/4aa58bb7a66bb44975aa.png +1 -0
  81. package/dist/56ce063bc6c81adb7322.png +1 -0
  82. package/dist/605.js +13 -79
  83. package/dist/678.js +70 -20
  84. package/dist/6a411166ef5cc79e0714.png +1 -0
  85. package/dist/6faf403782fefacc1649.png +1 -0
  86. package/dist/782.js +118 -21
  87. package/dist/79dca33c68fab79c067f.png +1 -0
  88. package/dist/82da1578fa84f9debaeb.png +1 -0
  89. package/dist/8b8e0f0824743974b282.png +1 -0
  90. package/dist/8d551390d81e39130a3c.png +1 -0
  91. package/dist/9fc61b9479877ebdb6c7.png +1 -0
  92. package/dist/HASH +1 -1
  93. package/dist/a165d31dcb3dc90f1057.png +1 -0
  94. package/dist/a98d4a5698812c4426b3.png +1 -0
  95. package/dist/assets/img/caret.998eb8f.svg +1 -0
  96. package/dist/assets/img/done_green.b817fd4.svg +4 -0
  97. package/dist/assets/img/empty_1.0b98af0.svg +11 -0
  98. package/dist/assets/img/ghn.070f8e3.svg +17 -0
  99. package/dist/assets/img/ghtk.326eac1.svg +18 -0
  100. package/dist/assets/img/info.ebce7ea.svg +1 -0
  101. package/dist/assets/img/loader.37000a7.svg +1 -0
  102. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  103. package/dist/assets/img/package.8d37d0f.svg +5 -0
  104. package/dist/assets/img/package_fade.763c001.svg +1 -0
  105. package/dist/assets/img/search.f9705ff.svg +1 -0
  106. package/dist/assets/img/shop.f7dc7d8.svg +1 -0
  107. package/dist/assets/img/shop_faded.df7845a.svg +1 -0
  108. package/dist/assets/img/x.26fdfa3.svg +5 -0
  109. package/dist/c41606bf9d1b604e46d5.png +1 -0
  110. package/dist/ce1f7450ce6c1aacd330.png +1 -0
  111. package/dist/cf8c01e88f4770a6e3e5.png +1 -0
  112. package/dist/dfbcfeab1d5622a737e2.png +1 -0
  113. package/dist/e4893ed8c2f7b8329919.png +1 -0
  114. package/dist/ec2ab4eb4ef73d186186.png +1 -0
  115. package/dist/screenshoot.html +1 -1
  116. package/dist/screenshoot.js +452 -389
  117. package/index.html +3 -18
  118. package/order.html +32 -0
  119. package/package.json +13 -14
  120. package/src/chatbox/DropdownSelect.js +229 -0
  121. package/src/chatbox/Event.js +2 -2
  122. package/src/chatbox/Events.js +43 -42
  123. package/src/chatbox/Order.js +232 -0
  124. package/src/chatbox/OrderAttachments.js +2 -1
  125. package/src/chatbox/TextMessage.js +21 -12
  126. package/src/chatbox/Widget.js +34 -4
  127. package/src/chatbox/main.js +2 -2
  128. package/src/chatbox/spinner.js +1 -1
  129. package/src/chatbox/time.js +1 -1
  130. package/src/common.js +52 -8
  131. package/src/contact/contact.js +1 -1
  132. package/src/order/address_picker.js +235 -0
  133. package/src/order/icon.js +32 -0
  134. package/src/order/index.js +86 -0
  135. package/src/order/order.js +1157 -0
  136. package/src/order/scratch +211 -0
  137. package/src/plugin.js +7 -52
  138. package/src/popup/popup.js +27 -2
  139. package/src/store/api.js +26 -1
  140. package/src/store/store.js +46 -9
  141. package/src/util/common.js +52 -4
  142. package/webpack.dev.js +2 -0
  143. package/dist/17d938a5acb.178.js +0 -1
  144. package/dist/17d938a5acb.213.js +0 -1
  145. package/dist/17d938a5acb.362.js +0 -1
  146. package/dist/17d938a5acb.441.js +0 -1
  147. package/dist/17d938a5acb.605.js +0 -1
  148. package/dist/17d938a5acb.619.js +0 -1
  149. package/dist/17d938a5acb.678.js +0 -1
  150. package/dist/17d938a5acb.74.js +0 -1
  151. package/dist/17d938a5acb.782.js +0 -1
  152. package/dist/17d938a5acb.app.js +0 -1
  153. package/dist/17d938a5acb.library.js +0 -1
  154. package/dist/17d938a5acb.preview.js +0 -1
  155. package/dist/17d938a5acb.screenshoot.js +0 -1
  156. package/dist/619.js +0 -777
@@ -1343,6 +1343,103 @@ function toString(obj) {
1343
1343
 
1344
1344
  /***/ }),
1345
1345
 
1346
+ /***/ 2493:
1347
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1348
+
1349
+ "use strict";
1350
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1351
+ /* harmony export */ "up": () => (/* binding */ Com),
1352
+ /* harmony export */ "u$": () => (/* binding */ Clickaway),
1353
+ /* harmony export */ "Kd": () => (/* binding */ getLocale),
1354
+ /* harmony export */ "Rs": () => (/* binding */ langMessages),
1355
+ /* harmony export */ "WW": () => (/* binding */ downloadLanguage)
1356
+ /* harmony export */ });
1357
+ /* harmony import */ var preact__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6400);
1358
+ /* harmony import */ var _util_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(819);
1359
+
1360
+
1361
+ class Com extends preact__WEBPACK_IMPORTED_MODULE_0__/* .Component */ .wA {
1362
+ constructor(props) {
1363
+ super(props);
1364
+ this._isMounted = true;
1365
+ setTimeout(() => {
1366
+ if (this.componentWillUnmount) {
1367
+ let old = this.componentWillUnmount.bind(this);
1368
+
1369
+ this.componentWillUnmount = () => {
1370
+ old();
1371
+ this._isMounted = false;
1372
+ };
1373
+ }
1374
+ }, 10);
1375
+ }
1376
+
1377
+ }
1378
+ class Clickaway extends Com {
1379
+ constructor(props) {
1380
+ super(props);
1381
+ this.setWrapperRef = this.setWrapperRef.bind(this);
1382
+ this.onClick = this.onClick.bind(this);
1383
+ }
1384
+
1385
+ componentDidMount() {
1386
+ document.addEventListener('mousedown', this.onClick);
1387
+ }
1388
+
1389
+ componentWillUnmount() {
1390
+ document.removeEventListener('mousedown', this.onClick);
1391
+ }
1392
+
1393
+ setWrapperRef(node) {
1394
+ this.wrapperRef = node;
1395
+ }
1396
+
1397
+ onClick(event) {
1398
+ if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
1399
+ this.props.onClickaway && this.props.onClickaway();
1400
+ }
1401
+ }
1402
+
1403
+ render() {
1404
+ return (0,preact__WEBPACK_IMPORTED_MODULE_0__.h)("div", {
1405
+ ref: this.setWrapperRef
1406
+ }, this.props.children);
1407
+ }
1408
+
1409
+ }
1410
+ const getLocale = (plugin, loc) => {
1411
+ if (!loc) loc = '';
1412
+ let found = _util_index_js__WEBPACK_IMPORTED_MODULE_1__/* ["default"].find */ .Z.find(plugin.locales, l => l.toLowerCase().trim() === loc.toLowerCase().trim());
1413
+ if (found) return found;
1414
+ found = _util_index_js__WEBPACK_IMPORTED_MODULE_1__/* ["default"].find */ .Z.find(plugin.locales, l => {
1415
+ l = l.replace('-', '_').split('_')[0].trim().toLowerCase();
1416
+ let compareloc = loc.replace('-', '_').split('_')[0].trim().toLowerCase();
1417
+ return l == compareloc;
1418
+ });
1419
+ if (found) return found;
1420
+ return plugin.locale || 'en-US';
1421
+ };
1422
+ let langMessages = {};
1423
+ let downloadLock = false;
1424
+ function downloadLanguage(store, locale, force) {
1425
+ if (downloadLock) return new Promise(resolve => setTimeout(() => downloadLanguage(store, locale, force).then(resolve), 100));
1426
+ downloadLock = true;
1427
+ let messages;
1428
+
1429
+ if (locale === 'debug' || langMessages[locale] && !force) {
1430
+ downloadLock = false;
1431
+ return Promise.resolve();
1432
+ }
1433
+
1434
+ return store.getLocaleContent(locale).then(res => {
1435
+ downloadLock = false;
1436
+ messages = _util_index_js__WEBPACK_IMPORTED_MODULE_1__/* ["default"].get */ .Z.get(res, 'body.messages', []);
1437
+ langMessages[locale] = messages;
1438
+ });
1439
+ }
1440
+
1441
+ /***/ }),
1442
+
1346
1443
  /***/ 8733:
1347
1444
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1348
1445
 
@@ -1410,7 +1507,9 @@ __webpack_require__.r(__webpack_exports__);
1410
1507
  /* harmony export */ "detectLang": () => (/* binding */ detectLang),
1411
1508
  /* harmony export */ "getUrlParameter": () => (/* binding */ getUrlParameter),
1412
1509
  /* harmony export */ "sleep": () => (/* binding */ sleep),
1413
- /* harmony export */ "formatCurrency": () => (/* binding */ formatCurrency)
1510
+ /* harmony export */ "formatCurrency": () => (/* binding */ formatCurrency),
1511
+ /* harmony export */ "unicodeToAscii": () => (/* binding */ unicodeToAscii),
1512
+ /* harmony export */ "scrollIntoViewIfNeeded": () => (/* binding */ scrollIntoViewIfNeeded)
1414
1513
  /* harmony export */ });
1415
1514
  var op = __webpack_require__(6877);
1416
1515
 
@@ -2281,7 +2380,7 @@ function getDayName(dayOfWeek) {
2281
2380
  return days[dayOfWeek];
2282
2381
  }
2283
2382
  let loadedFonts = {};
2284
- function preloadWebfonts(fonts) {
2383
+ function preloadWebfonts(fonts, done) {
2285
2384
  for (var i = 0; i < fonts.length; i++) {
2286
2385
  let font = fonts[i];
2287
2386
  if (!font) continue;
@@ -2294,8 +2393,11 @@ function preloadWebfonts(fonts) {
2294
2393
  node.innerHTML = '@!-/#Chào mỪng1';
2295
2394
  node.style.position = 'absolute';
2296
2395
  node.style.display = 'block';
2297
- node.style.fontSize = '1px';
2396
+ node.style.opacity = '0.1';
2397
+ node.style.color = 'transparent';
2398
+ node.style.fontSize = '20px';
2298
2399
  node.style.height = '0px';
2400
+ node.style.top = '0px';
2299
2401
  node.style.width = '0px';
2300
2402
  node.style.fontWeight = weight;
2301
2403
  node.setAttribute('subiz-preload', font + ':' + weight);
@@ -2417,9 +2519,9 @@ function getUrlParameter() {
2417
2519
  }
2418
2520
  var sleep = ms => new Promise(res => setTimeout(res, ms));
2419
2521
  function formatCurrency(val) {
2420
- if (!val) return 0;
2522
+ if (!val) return '0 đ';
2421
2523
  val = Math.round(val);
2422
- return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
2524
+ return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') + ' đ';
2423
2525
  }
2424
2526
 
2425
2527
  function replaceFileUrl(src) {
@@ -2447,6 +2549,36 @@ function replaceFileUrl(src) {
2447
2549
  return src;
2448
2550
  }
2449
2551
 
2552
+ function unicodeToAscii(str) {
2553
+ str = str + '';
2554
+ str = str.replace('đ', 'd').replace('Đ', 'D');
2555
+ return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
2556
+ }
2557
+ function scrollIntoViewIfNeeded($ele) {
2558
+ centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
2559
+ var parent = $ele.parentNode;
2560
+ var parentComputedStyle = window.getComputedStyle(parent, null);
2561
+ var parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'));
2562
+ var parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width'));
2563
+ var overTop = $ele.offsetTop - parent.offsetTop < parent.scrollTop;
2564
+ var overBottom = $ele.offsetTop - parent.offsetTop + $ele.clientHeight - parentBorderTopWidth > parent.scrollTop + parent.clientHeight;
2565
+ var overLeft = $ele.offsetLeft - parent.offsetLeft < parent.scrollLeft;
2566
+ var overRight = $ele.offsetLeft - parent.offsetLeft + $ele.clientWidth - parentBorderLeftWidth > parent.scrollLeft + parent.clientWidth;
2567
+ var alignWithTop = overTop && !overBottom;
2568
+
2569
+ if ((overTop || overBottom) && centerIfNeeded) {
2570
+ parent.scrollTop = $ele.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + $ele.clientHeight / 2;
2571
+ }
2572
+
2573
+ if ((overLeft || overRight) && centerIfNeeded) {
2574
+ parent.scrollLeft = $ele.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + $ele.clientWidth / 2;
2575
+ }
2576
+
2577
+ if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
2578
+ $ele.scrollIntoView(alignWithTop);
2579
+ }
2580
+ }
2581
+
2450
2582
  /***/ }),
2451
2583
 
2452
2584
  /***/ 2302:
@@ -3232,7 +3364,7 @@ var n,l,u,i,t,r,o,f,e={},c=[],s=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[c
3232
3364
  /******/
3233
3365
  /******/ /* webpack/runtime/jsonp chunk loading */
3234
3366
  /******/ (() => {
3235
- /******/ // no baseURI
3367
+ /******/ __webpack_require__.b = document.baseURI || self.location.href;
3236
3368
  /******/
3237
3369
  /******/ // object to store loaded and loading chunks
3238
3370
  /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
@@ -3310,7 +3442,7 @@ var n,l,u,i,t,r,o,f,e={},c=[],s=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[c
3310
3442
  /******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
3311
3443
  /******/ installedChunks[chunkId][0]();
3312
3444
  /******/ }
3313
- /******/ installedChunks[chunkIds[i]] = 0;
3445
+ /******/ installedChunks[chunkId] = 0;
3314
3446
  /******/ }
3315
3447
  /******/
3316
3448
  /******/ }
@@ -3344,8 +3476,6 @@ var lsdb = (__webpack_require__(6929)/* ["default"] */ .Z);
3344
3476
  inmem_localstorage
3345
3477
  });
3346
3478
  ;// CONCATENATED MODULE: ./src/store/api.js
3347
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3348
-
3349
3479
 
3350
3480
 
3351
3481
  const ajax = __webpack_require__(7460);
@@ -3362,92 +3492,6 @@ function jsonifyTextPlain(param, done) {
3362
3492
 
3363
3493
  /* harmony default export */ const api = (class {
3364
3494
  constructor(ApiURL, FileURL) {
3365
- _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get('/conversations'));
3366
-
3367
- _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/conversations/${cid}/messages`));
3368
-
3369
- _defineProperty(this, "ajax", ajax);
3370
-
3371
- _defineProperty(this, "start", extraData => {
3372
- let data = {
3373
- starter_id: this.uid,
3374
- starter_type: 'user',
3375
- integration_id: `${this.accid}.subizv4.subikon`
3376
- };
3377
- util/* default.each */.Z.each(extraData, (v, k) => {
3378
- data[k] = v;
3379
- });
3380
- return this.apireq.post('/conversations', data);
3381
- });
3382
-
3383
- _defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));
3384
-
3385
- _defineProperty(this, "createPostback", (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p));
3386
-
3387
- _defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/receive`));
3388
-
3389
- _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/seen`));
3390
-
3391
- _defineProperty(this, "getConversation", cid => this.apireq.get(`/conversations/${cid}`));
3392
-
3393
- _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
3394
-
3395
- _defineProperty(this, "sendEvent", data => this.apireq.post(`/users/${this.uid}/events`, data));
3396
-
3397
- _defineProperty(this, "sendTyping", cid => this.apireq.post(`/conversations/${cid}/typing`));
3398
-
3399
- _defineProperty(this, "uploadToS3", async file => {
3400
- let {
3401
- body: signed,
3402
- error
3403
- } = await this.apireq.post(`/accounts/${this.accid}/files`, {
3404
- account_id: this.accid,
3405
- description: 'upload\n user-client: web-widget',
3406
- name: file.name.replace(/\s+/g, '_'),
3407
- size: file.size,
3408
- type: file.type
3409
- });
3410
- if (error) return {
3411
- error
3412
- };
3413
- let contentType = file.type || 'application/octet-stream';
3414
- ({
3415
- error
3416
- } = await ajax.setContentType(contentType).put(signed.signed_url, file));
3417
- if (error) return {
3418
- error
3419
- };
3420
- let body;
3421
- ({
3422
- body,
3423
- error
3424
- } = await this.apireq.post(`/accounts/${this.accid}/files/${signed.id}`, {
3425
- account_id: this.accid
3426
- }));
3427
- if (error) return {
3428
- error
3429
- };
3430
- return {
3431
- url: this.FileURL + body.url
3432
- };
3433
- });
3434
-
3435
- _defineProperty(this, "getChallenge", accid => this.apireq.post(`/accounts/${accid}/scrypt-challenges`));
3436
-
3437
- _defineProperty(this, "time", _ => this.apireq.get('/time'));
3438
-
3439
- _defineProperty(this, "updateUser", data => this.apireq.post(`/users/${this.uid}`, data));
3440
-
3441
- _defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
3442
-
3443
- _defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
3444
-
3445
- _defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
3446
-
3447
- _defineProperty(this, "sendImpression", impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression));
3448
-
3449
- _defineProperty(this, "sendConversion", conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion));
3450
-
3451
3495
  this.FileURL = FileURL;
3452
3496
  this.ApiURL = ApiURL;
3453
3497
  this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').beforeHook((param, done) => {
@@ -3466,6 +3510,29 @@ function jsonifyTextPlain(param, done) {
3466
3510
  this.uid = obj.uid;
3467
3511
  }
3468
3512
 
3513
+ listConversations = _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get('/conversations');
3514
+ listMessages = (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/conversations/${cid}/messages`);
3515
+ ajax = ajax;
3516
+ start = extraData => {
3517
+ let data = {
3518
+ starter_id: this.uid,
3519
+ starter_type: 'user',
3520
+ integration_id: `${this.accid}.subizv4.subikon`
3521
+ };
3522
+ util/* default.each */.Z.each(extraData, (v, k) => {
3523
+ data[k] = v;
3524
+ });
3525
+ return this.apireq.post('/conversations', data);
3526
+ };
3527
+ sendConvoEvent = (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev);
3528
+ createPostback = (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p);
3529
+ markAsReceived = (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/receive`);
3530
+ markAsSeen = (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/seen`);
3531
+ getConversation = cid => this.apireq.get(`/conversations/${cid}`);
3532
+ getLocaleContent = locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`);
3533
+ sendEvent = data => this.apireq.post(`/users/${this.uid}/events`, data);
3534
+ sendTyping = cid => this.apireq.post(`/conversations/${cid}/typing`);
3535
+
3469
3536
  sendPresence(device, is_focused) {
3470
3537
  return this.sendEvent({
3471
3538
  by: {
@@ -3499,6 +3566,43 @@ function jsonifyTextPlain(param, done) {
3499
3566
  });
3500
3567
  }
3501
3568
 
3569
+ uploadToS3 = async file => {
3570
+ let {
3571
+ body: signed,
3572
+ error
3573
+ } = await this.apireq.post(`/accounts/${this.accid}/files`, {
3574
+ account_id: this.accid,
3575
+ description: 'upload\n user-client: web-widget',
3576
+ name: file.name.replace(/\s+/g, '_'),
3577
+ size: file.size,
3578
+ type: file.type
3579
+ });
3580
+ if (error) return {
3581
+ error
3582
+ };
3583
+ let contentType = file.type || 'application/octet-stream';
3584
+ ({
3585
+ error
3586
+ } = await ajax.setContentType(contentType).put(signed.signed_url, file));
3587
+ if (error) return {
3588
+ error
3589
+ };
3590
+ let body;
3591
+ ({
3592
+ body,
3593
+ error
3594
+ } = await this.apireq.post(`/accounts/${this.accid}/files/${signed.id}`, {
3595
+ account_id: this.accid
3596
+ }));
3597
+ if (error) return {
3598
+ error
3599
+ };
3600
+ return {
3601
+ url: this.FileURL + body.url
3602
+ };
3603
+ };
3604
+ getChallenge = accid => this.apireq.post(`/accounts/${accid}/scrypt-challenges`);
3605
+
3502
3606
  async createAgentUser(agenttoken) {
3503
3607
  for (var i = 0; i < 10; i++) {
3504
3608
  let {
@@ -3541,10 +3645,26 @@ function jsonifyTextPlain(param, done) {
3541
3645
  }
3542
3646
  }
3543
3647
 
3648
+ time = _ => this.apireq.get('/time');
3649
+ updateUser = data => this.apireq.post(`/users/${this.uid}`, data);
3650
+ getUser = _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`);
3651
+ getAccountSetting = () => this.apireq.get(`/accounts/${this.accid}/settings`);
3652
+ getIsOnline = () => this.apireq.get(`/accounts/${this.accid}/is_online`);
3653
+ sendImpression = impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression);
3654
+ sendConversion = conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion);
3655
+ lookupOrder = key => ajax.setBaseUrl(this.ApiURL).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').addQuery('x-signed-key', key).get(`/orders/123`);
3656
+ getOrder = id => this.apireq.get(`/accounts/${this.accid}/orders/` + id);
3657
+ updateOrder = order => this.apireq.post(`/accounts/${this.accid}/orders/` + order.id, order);
3658
+ fetchShippingAddresses = () => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`);
3659
+ createShippingAddress = addr => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`, addr);
3660
+ list_provinces = () => this.apireq.get(`/accounts/${this.accid}/provinces`);
3661
+ list_districts = p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/districts`);
3662
+ list_wards = p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/wards`);
3663
+ suggest_address = keyword => this.apireq.setQuery({
3664
+ keyword: keyword
3665
+ }).get(`/accounts/${this.accid}/addresses`);
3544
3666
  });
3545
3667
  ;// CONCATENATED MODULE: ./src/store/api_fake.js
3546
- function api_fake_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3547
-
3548
3668
 
3549
3669
 
3550
3670
  const api_fake_ajax = __webpack_require__(7460);
@@ -3564,86 +3684,6 @@ const OK200 = Promise.resolve({
3564
3684
  });
3565
3685
  /* harmony default export */ const api_fake = (class {
3566
3686
  constructor(ApiURL, FileURL) {
3567
- api_fake_defineProperty(this, "listConversations", _ => {
3568
- let convo = makeFakeConvo(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid);
3569
- return Promise.resolve({
3570
- body: {
3571
- anchor: '',
3572
- conversations: [convo]
3573
- },
3574
- code: 200
3575
- });
3576
- });
3577
-
3578
- api_fake_defineProperty(this, "listMessages", (cid, limit, start_id) => {
3579
- let messages = makeFakeMessages(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid);
3580
- return Promise.resolve({
3581
- body: messages,
3582
- code: 200
3583
- });
3584
- });
3585
-
3586
- api_fake_defineProperty(this, "ajax", api_fake_ajax);
3587
-
3588
- api_fake_defineProperty(this, "start", extraData => OK200);
3589
-
3590
- api_fake_defineProperty(this, "sendConvoEvent", (cid, ev) => OK200);
3591
-
3592
- api_fake_defineProperty(this, "createPostback", (cid, p) => OK200);
3593
-
3594
- api_fake_defineProperty(this, "markAsReceived", (cid, messageId) => OK200);
3595
-
3596
- api_fake_defineProperty(this, "markAsSeen", (cid, messageId) => OK200);
3597
-
3598
- api_fake_defineProperty(this, "getConversation", cid => Promise.resolve({
3599
- body: makeFakeConvo(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid),
3600
- code: 200
3601
- }));
3602
-
3603
- api_fake_defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
3604
-
3605
- api_fake_defineProperty(this, "sendEvent", data => OK200);
3606
-
3607
- api_fake_defineProperty(this, "sendTyping", cid => OK200);
3608
-
3609
- api_fake_defineProperty(this, "sendPresence", data => OK200);
3610
-
3611
- api_fake_defineProperty(this, "sendContent", data => OK200);
3612
-
3613
- api_fake_defineProperty(this, "uploadToS3", async file => OK200);
3614
-
3615
- api_fake_defineProperty(this, "getChallenge", accid => OK200);
3616
-
3617
- api_fake_defineProperty(this, "createUser", accid => Promise.resolve({
3618
- account_id: accid,
3619
- id: 'usqzgtgfake',
3620
- mask: 'fakemask'
3621
- }));
3622
-
3623
- api_fake_defineProperty(this, "createAgentUser", agenttoken => Promise.resolve('fakemask'));
3624
-
3625
- api_fake_defineProperty(this, "time", _ => Promise.resolve({
3626
- code: 200,
3627
- body: new util/* default.Date */.Z.Date().toISOString()
3628
- }));
3629
-
3630
- api_fake_defineProperty(this, "updateUser", data => OK200);
3631
-
3632
- api_fake_defineProperty(this, "getUser", _ => Promise.resolve({
3633
- code: 200,
3634
- body: {
3635
- id: '-'
3636
- }
3637
- }));
3638
-
3639
- api_fake_defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
3640
-
3641
- api_fake_defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
3642
-
3643
- api_fake_defineProperty(this, "sendImpression", impression => OK200);
3644
-
3645
- api_fake_defineProperty(this, "sendConversion", conversion => OK200);
3646
-
3647
3687
  this.FileURL = FileURL;
3648
3688
  this.apireq = api_fake_ajax.setBaseUrl(ApiURL).setContentType('text/plain').beforeHook(api_fake_jsonifyTextPlain).setParser('json');
3649
3689
  }
@@ -3658,6 +3698,61 @@ const OK200 = Promise.resolve({
3658
3698
  this.uid = obj.uid;
3659
3699
  }
3660
3700
 
3701
+ listConversations = _ => {
3702
+ let convo = makeFakeConvo(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid);
3703
+ return Promise.resolve({
3704
+ body: {
3705
+ anchor: '',
3706
+ conversations: [convo]
3707
+ },
3708
+ code: 200
3709
+ });
3710
+ };
3711
+ listMessages = (cid, limit, start_id) => {
3712
+ let messages = makeFakeMessages(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid);
3713
+ return Promise.resolve({
3714
+ body: messages,
3715
+ code: 200
3716
+ });
3717
+ };
3718
+ ajax = api_fake_ajax;
3719
+ start = extraData => OK200;
3720
+ sendConvoEvent = (cid, ev) => OK200;
3721
+ createPostback = (cid, p) => OK200;
3722
+ markAsReceived = (cid, messageId) => OK200;
3723
+ markAsSeen = (cid, messageId) => OK200;
3724
+ getConversation = cid => Promise.resolve({
3725
+ body: makeFakeConvo(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid),
3726
+ code: 200
3727
+ });
3728
+ getLocaleContent = locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`);
3729
+ sendEvent = data => OK200;
3730
+ sendTyping = cid => OK200;
3731
+ sendPresence = data => OK200;
3732
+ sendContent = data => OK200;
3733
+ uploadToS3 = async file => OK200;
3734
+ getChallenge = accid => OK200;
3735
+ createUser = accid => Promise.resolve({
3736
+ account_id: accid,
3737
+ id: 'usqzgtgfake',
3738
+ mask: 'fakemask'
3739
+ });
3740
+ createAgentUser = agenttoken => Promise.resolve('fakemask');
3741
+ time = _ => Promise.resolve({
3742
+ code: 200,
3743
+ body: new util/* default.Date */.Z.Date().toISOString()
3744
+ });
3745
+ updateUser = data => OK200;
3746
+ getUser = _ => Promise.resolve({
3747
+ code: 200,
3748
+ body: {
3749
+ id: '-'
3750
+ }
3751
+ });
3752
+ getAccountSetting = () => this.apireq.get(`/accounts/${this.accid}/settings`);
3753
+ getIsOnline = () => this.apireq.get(`/accounts/${this.accid}/is_online`);
3754
+ sendImpression = impression => OK200;
3755
+ sendConversion = conversion => OK200;
3661
3756
  });
3662
3757
 
3663
3758
  function makeFakeConvo(accid, convoid, userid, agentid) {
@@ -4010,8 +4105,6 @@ function makeFakeMessages(accid, convoid, userid, agentid) {
4010
4105
 
4011
4106
  });
4012
4107
  ;// CONCATENATED MODULE: ./src/store/store.js
4013
- function store_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4014
-
4015
4108
 
4016
4109
 
4017
4110
  var flow = __webpack_require__(3165);
@@ -4032,160 +4125,6 @@ const MAX_CONVO = 20;
4032
4125
  const page_loaded = util/* default.Date.now */.Z.Date.now();
4033
4126
  class Store {
4034
4127
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi, agenttoken) {
4035
- store_defineProperty(this, "inmem", false);
4036
-
4037
- store_defineProperty(this, "cookie", cookie);
4038
-
4039
- store_defineProperty(this, "new_visitor", true);
4040
-
4041
- store_defineProperty(this, "matchUser", () => {
4042
- this._touchAcc();
4043
-
4044
- return this.kv.match('user');
4045
- });
4046
-
4047
- store_defineProperty(this, "matchSession", () => this.kv.match('session') || {});
4048
-
4049
- store_defineProperty(this, "matchAccount", () => this.cache.match('account'));
4050
-
4051
- store_defineProperty(this, "matchUnread", () => {
4052
- let user = this.matchUser();
4053
- let allconvos = this.matchConvo('*');
4054
- let unreadcount = 0;
4055
- util/* default.map */.Z.map(allconvos, convo => {
4056
- if (!util/* default.isConvoSeen */.Z.isConvoSeen(convo, user.id)) unreadcount++;
4057
- });
4058
- return unreadcount;
4059
- });
4060
-
4061
- store_defineProperty(this, "matchPlugin", () => {
4062
- if (util/* default.size */.Z.size(this.forcePlugins) > 0) return util/* default.cloneDeep */.Z.cloneDeep(this.forcePlugins);
4063
- return util/* default.cloneDeep */.Z.cloneDeep(this.cache.match('plugin')) || {};
4064
- });
4065
-
4066
- store_defineProperty(this, "device", {});
4067
-
4068
- store_defineProperty(this, "browserVisibility", 'visible');
4069
-
4070
- store_defineProperty(this, "matchAgent", id => {
4071
- let agentM = this.cache.match('agent') || {};
4072
- if (id === '*') return agentM;
4073
- return agentM[id];
4074
- });
4075
-
4076
- store_defineProperty(this, "matchConvo", id => {
4077
- if (!id) return;
4078
-
4079
- if (id === '*') {
4080
- this._touchAcc();
4081
-
4082
- return util/* default.filter */.Z.filter(this.cache.all(), (value, k) => k.startsWith('convo_'));
4083
- }
4084
-
4085
- if (!this.isInsync(id)) this.fetchConvo(id);
4086
- return this.cache.match('convo_' + id);
4087
- });
4088
-
4089
- store_defineProperty(this, "fetchConvo", async cid => {
4090
- await this.readyGate.entry();
4091
- await this.reconnectGate.entry(undefined, true);
4092
- if (this.isInsync(cid)) return this.reconnectGate.open();
4093
- this.markSync(cid);
4094
- let {
4095
- body: convo,
4096
- error
4097
- } = await this.api.getConversation(cid);
4098
- if (convo && !error) this._setConvo(convo);
4099
- return this.reconnectGate.open();
4100
- });
4101
-
4102
- store_defineProperty(this, "listEvents", id => {
4103
- if (!id || id === '*' || typeof id !== 'string') return;
4104
-
4105
- if (!this.isInsync('events' + id)) {
4106
- setTimeout(async () => {
4107
- await this.readyGate.entry();
4108
- await this.reconnectGate.entry(undefined, true);
4109
- if (this.isInsync('events' + id)) return this.reconnectGate.open();
4110
- this.markSync('events' + id);
4111
- await this.chain.reload(id, (type, anchor, limit) => this.listmessageapi(type, anchor, limit));
4112
- this.pubsub.publish('account');
4113
- return this.reconnectGate.open();
4114
- }, 10);
4115
- }
4116
-
4117
- return this.chain.listM(id);
4118
- });
4119
-
4120
- store_defineProperty(this, "fetchMoreEvents", async convoid => {
4121
- let {
4122
- error
4123
- } = await this.chain.fetchMore(convoid, 50, (type, anchor, limit) => this.listmessageapi(type, anchor, limit));
4124
- this.pubsub.publish('account');
4125
- return {
4126
- error
4127
- };
4128
- });
4129
-
4130
- store_defineProperty(this, "matchBot", () => this.cache.match('bot') || {});
4131
-
4132
- store_defineProperty(this, "readyGate", new util/* default.Gate */.Z.Gate());
4133
-
4134
- store_defineProperty(this, "convoGate", new util/* default.Gate */.Z.Gate(true));
4135
-
4136
- store_defineProperty(this, "reconnectGate", new util/* default.Gate */.Z.Gate(true));
4137
-
4138
- store_defineProperty(this, "matchLastview", () => this.kv.match('lastview') || {});
4139
-
4140
- store_defineProperty(this, "matchIsOpen", () => !!this.kv.match('isopen'));
4141
-
4142
- store_defineProperty(this, "matchHasManuallyClosed", () => !!this.kv.match('hasManuallyClosed'));
4143
-
4144
- store_defineProperty(this, "matchClosePreviewAt", () => this.kv.match('close_preview_at') || 0);
4145
-
4146
- store_defineProperty(this, "sendPresence", util/* default.throttle */.Z.throttle(async () => {
4147
- await this.readyGate.entry();
4148
- if (!util/* default.get */.Z.get(this.kv.match('user'), 'id')) return;
4149
- if (util/* default.isUserBanned */.Z.isUserBanned(this.kv.match('user'))) return;
4150
- return this.api.sendPresence(this.device, this.browserVisibility === 'visible' && document.hasFocus());
4151
- }, 1000));
4152
-
4153
- store_defineProperty(this, "now", () => util/* default.Date.now */.Z.Date.now() + this.timeDiff);
4154
-
4155
- store_defineProperty(this, "seenQueue", []);
4156
-
4157
- store_defineProperty(this, "_typing", util/* default.throttle */.Z.throttle(convoid => this.api.sendTyping(convoid), 3000));
4158
-
4159
- store_defineProperty(this, "onConvoEvent", (o, cb) => this.pubsub.on2(o, 'events', cb));
4160
-
4161
- store_defineProperty(this, "seenConvo", id => {
4162
- if (!id || id === 'create') return;
4163
- this.seenQueue.push(id);
4164
- });
4165
-
4166
- store_defineProperty(this, "onUpdate", (o, cb) => this.pubsub.on2(o, 'account', cb));
4167
-
4168
- store_defineProperty(this, "onResetCSS", (o, cb) => this.pubsub.on2(o, 'resetCSS', cb));
4169
-
4170
- store_defineProperty(this, "onHighlight", (o, cb) => this.pubsub.on2(o, 'highlight', cb));
4171
-
4172
- store_defineProperty(this, "setHasManuallyClosed", () => this.kv.put('hasManuallyClosed', true));
4173
-
4174
- store_defineProperty(this, "setIsOpen", isopen => {
4175
- let lastisopen = this.kv.match('isopen');
4176
- this.kv.put('isopen', isopen);
4177
- if (!lastisopen && isopen) sendEventToThirdParty('SUBIZ Chat', 'Opened', 'Subiz Windows');
4178
- });
4179
-
4180
- store_defineProperty(this, "closePreview", () => this.kv.put('close_preview_at', new util/* default.Date */.Z.Date().getTime()));
4181
-
4182
- store_defineProperty(this, "setLastview", (view, opts) => this.kv.put('lastview', {
4183
- view,
4184
- opts
4185
- }));
4186
-
4187
- store_defineProperty(this, "timeDiff", 0);
4188
-
4189
4128
  this.agent_token = agenttoken;
4190
4129
  this.g_sync = {};
4191
4130
  this.forceDevice = null;
@@ -4239,10 +4178,31 @@ class Store {
4239
4178
  }, 2000);
4240
4179
  }
4241
4180
 
4181
+ inmem = false;
4182
+ cookie = cookie;
4183
+
4242
4184
  isInsync(key) {
4243
4185
  return util/* default.Date.now */.Z.Date.now() - (this.g_sync[key] || 0) < 300000;
4244
4186
  }
4245
4187
 
4188
+ async fetchShippingAddresses() {
4189
+ let out = await this.api.fetchShippingAddresses();
4190
+ if (out.error) return null;
4191
+ this.cache.put('shipping_address', out.body.shipping_addresses);
4192
+ }
4193
+
4194
+ matchShippingAddresses() {
4195
+ return this.cache.match('shipping_address');
4196
+ }
4197
+
4198
+ updateOrder(order) {
4199
+ return this.api.updateOrder(order);
4200
+ }
4201
+
4202
+ createShippingAddress(addr) {
4203
+ return this.api.createShippingAddress(addr);
4204
+ }
4205
+
4246
4206
  async overrideAcc(acc) {
4247
4207
  this.forceAcc = util/* default.cloneDeep */.Z.cloneDeep(acc);
4248
4208
  await this.readyGate.entry();
@@ -4319,12 +4279,113 @@ class Store {
4319
4279
  this.g_sync[key] = util/* default.Date.now */.Z.Date.now();
4320
4280
  }
4321
4281
 
4282
+ new_visitor = true;
4283
+
4322
4284
  async _touchAcc() {
4323
4285
  if (this.isInsync('account')) return;
4324
4286
  await this.readyGate.entry();
4325
4287
  if (!this.isInsync('account')) this.reconnect();
4326
4288
  }
4327
4289
 
4290
+ matchUser = () => {
4291
+ this._touchAcc();
4292
+
4293
+ return this.kv.match('user');
4294
+ };
4295
+ suggest_addresses = keyword => this.api.suggest_address(keyword);
4296
+ matchSession = () => this.kv.match('session') || {};
4297
+ matchAccount = () => this.cache.match('account');
4298
+ matchPaymentMethods = () => this.cache.match('payment_methods');
4299
+ matchUnread = () => {
4300
+ let user = this.matchUser();
4301
+ let allconvos = this.matchConvo('*');
4302
+ let unreadcount = 0;
4303
+ util/* default.map */.Z.map(allconvos, convo => {
4304
+ if (!util/* default.isConvoSeen */.Z.isConvoSeen(convo, user.id)) unreadcount++;
4305
+ });
4306
+ return unreadcount;
4307
+ };
4308
+ matchPlugin = () => {
4309
+ if (util/* default.size */.Z.size(this.forcePlugins) > 0) return util/* default.cloneDeep */.Z.cloneDeep(this.forcePlugins);
4310
+ return util/* default.cloneDeep */.Z.cloneDeep(this.cache.match('plugin')) || {};
4311
+ };
4312
+ device = {};
4313
+ browserVisibility = 'visible';
4314
+ matchAgent = id => {
4315
+ let agentM = this.cache.match('agent') || {};
4316
+ if (id === '*') return agentM;
4317
+ return agentM[id];
4318
+ };
4319
+ matchConvo = id => {
4320
+ if (!id) return;
4321
+
4322
+ if (id === '*') {
4323
+ this._touchAcc();
4324
+
4325
+ return util/* default.filter */.Z.filter(this.cache.all(), (value, k) => k.startsWith('convo_'));
4326
+ }
4327
+
4328
+ if (!this.isInsync(id)) this.fetchConvo(id);
4329
+ return this.cache.match('convo_' + id);
4330
+ };
4331
+ fetchConvo = async cid => {
4332
+ await this.readyGate.entry();
4333
+ await this.reconnectGate.entry(undefined, true);
4334
+ if (this.isInsync(cid)) return this.reconnectGate.open();
4335
+ this.markSync(cid);
4336
+ let {
4337
+ body: convo,
4338
+ error
4339
+ } = await this.api.getConversation(cid);
4340
+ if (convo && !error) this._setConvo(convo);
4341
+ return this.reconnectGate.open();
4342
+ };
4343
+ list_provinces = () => this.api.list_provinces();
4344
+ list_districts = p => this.api.list_districts(p);
4345
+ list_wards = p => this.api.list_wards(p);
4346
+ list_provices;
4347
+ listEvents = id => {
4348
+ if (!id || id === '*' || typeof id !== 'string') return;
4349
+
4350
+ if (!this.isInsync('events' + id)) {
4351
+ setTimeout(async () => {
4352
+ await this.readyGate.entry();
4353
+ await this.reconnectGate.entry(undefined, true);
4354
+ if (this.isInsync('events' + id)) return this.reconnectGate.open();
4355
+ this.markSync('events' + id);
4356
+ await this.chain.reload(id, (type, anchor, limit) => this.listmessageapi(type, anchor, limit));
4357
+ this.pubsub.publish('account');
4358
+ return this.reconnectGate.open();
4359
+ }, 10);
4360
+ }
4361
+
4362
+ return this.chain.listM(id);
4363
+ };
4364
+ fetchMoreEvents = async convoid => {
4365
+ let {
4366
+ error
4367
+ } = await this.chain.fetchMore(convoid, 50, (type, anchor, limit) => this.listmessageapi(type, anchor, limit));
4368
+ this.pubsub.publish('account');
4369
+ return {
4370
+ error
4371
+ };
4372
+ };
4373
+ matchBot = () => this.cache.match('bot') || {};
4374
+ readyGate = new util/* default.Gate */.Z.Gate();
4375
+ convoGate = new util/* default.Gate */.Z.Gate(true);
4376
+ reconnectGate = new util/* default.Gate */.Z.Gate(true);
4377
+ matchLastview = () => this.kv.match('lastview') || {};
4378
+ matchIsOpen = () => !!this.kv.match('isopen');
4379
+ matchHasManuallyClosed = () => !!this.kv.match('hasManuallyClosed');
4380
+ matchClosePreviewAt = () => this.kv.match('close_preview_at') || 0;
4381
+ sendPresence = util/* default.throttle */.Z.throttle(async () => {
4382
+ await this.readyGate.entry();
4383
+ if (!util/* default.get */.Z.get(this.kv.match('user'), 'id')) return;
4384
+ if (util/* default.isUserBanned */.Z.isUserBanned(this.kv.match('user'))) return;
4385
+ return this.api.sendPresence(this.device, this.browserVisibility === 'visible' && document.hasFocus());
4386
+ }, 1000);
4387
+ now = () => util/* default.Date.now */.Z.Date.now() + this.timeDiff;
4388
+
4328
4389
  async init(accid, mask) {
4329
4390
  this.readyGate.close();
4330
4391
  accid = (accid || '').trim();
@@ -4383,6 +4444,8 @@ class Store {
4383
4444
  return mask;
4384
4445
  }
4385
4446
 
4447
+ seenQueue = [];
4448
+
4386
4449
  seenLoop() {
4387
4450
  this.seenQueue = [];
4388
4451
  clearInterval(this._seenInterval);
@@ -4456,6 +4519,7 @@ class Store {
4456
4519
  }
4457
4520
 
4458
4521
  _setUser(user) {
4522
+ user = util/* default.cloneDeep */.Z.cloneDeep(user);
4459
4523
  let olduser = this.kv.match('user') || {};
4460
4524
  var accid = olduser.account_id || user.account_id;
4461
4525
  var id = olduser.id || user.id;
@@ -4547,6 +4611,8 @@ class Store {
4547
4611
  this.cache.put('agent', agentM);
4548
4612
  }
4549
4613
 
4614
+ let pms = util/* default.get */.Z.get(setting, 'payment_methods', []);
4615
+ this.cache.put('payment_methods', pms);
4550
4616
  this.pubsub.publish('account');
4551
4617
  }
4552
4618
 
@@ -4725,6 +4791,8 @@ class Store {
4725
4791
  this._typing(cid);
4726
4792
  }
4727
4793
 
4794
+ _typing = util/* default.throttle */.Z.throttle(convoid => this.api.sendTyping(convoid), 3000);
4795
+
4728
4796
  async startConvo(req) {
4729
4797
  await this.readyGate.entry();
4730
4798
  this.convoGate.close();
@@ -4745,6 +4813,14 @@ class Store {
4745
4813
  };
4746
4814
  }
4747
4815
 
4816
+ fetchOrder(id) {
4817
+ return this.api.getOrder(id);
4818
+ }
4819
+
4820
+ lookupOrder(key) {
4821
+ return this.api.lookupOrder(key);
4822
+ }
4823
+
4748
4824
  createPostback(cid, postback) {
4749
4825
  return this.api.createPostback(cid, postback);
4750
4826
  }
@@ -4809,6 +4885,12 @@ class Store {
4809
4885
  sendEventToThirdParty('SUBIZ Chat', 'Sent', 'User');
4810
4886
  }
4811
4887
 
4888
+ onConvoEvent = (o, cb) => this.pubsub.on2(o, 'events', cb);
4889
+ seenConvo = id => {
4890
+ if (!id || id === 'create') return;
4891
+ this.seenQueue.push(id);
4892
+ };
4893
+
4812
4894
  _setConvo(convo) {
4813
4895
  let count = 0;
4814
4896
  let user = this.kv.match('user');
@@ -4836,6 +4918,21 @@ class Store {
4836
4918
  this.cache.put('convo_' + convo.id, convo);
4837
4919
  }
4838
4920
 
4921
+ onUpdate = (o, cb) => this.pubsub.on2(o, 'account', cb);
4922
+ onResetCSS = (o, cb) => this.pubsub.on2(o, 'resetCSS', cb);
4923
+ onHighlight = (o, cb) => this.pubsub.on2(o, 'highlight', cb);
4924
+ setHasManuallyClosed = () => this.kv.put('hasManuallyClosed', true);
4925
+ setIsOpen = isopen => {
4926
+ let lastisopen = this.kv.match('isopen');
4927
+ this.kv.put('isopen', isopen);
4928
+ if (!lastisopen && isopen) sendEventToThirdParty('SUBIZ Chat', 'Opened', 'Subiz Windows');
4929
+ };
4930
+ closePreview = () => this.kv.put('close_preview_at', new util/* default.Date */.Z.Date().getTime());
4931
+ setLastview = (view, opts) => this.kv.put('lastview', {
4932
+ view,
4933
+ opts
4934
+ });
4935
+
4839
4936
  matchLastPluginRun(pluginid) {
4840
4937
  let log = this.kv.match('plugin_run_logs') || {};
4841
4938
  return log[pluginid];
@@ -4938,6 +5035,8 @@ class Store {
4938
5035
  return [events, anchor];
4939
5036
  }
4940
5037
 
5038
+ timeDiff = 0;
5039
+
4941
5040
  async loopTime() {
4942
5041
  let startms = util/* default.Date.now */.Z.Date.now();
4943
5042
  if (!util/* default.get */.Z.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 30000);
@@ -5112,30 +5211,30 @@ let mobileCheck = function (a) {
5112
5211
  }(navigator.userAgent || navigator.vendor || window.opera);
5113
5212
 
5114
5213
  let tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(navigator.userAgent);
5214
+ // EXTERNAL MODULE: ./src/common.js
5215
+ var common = __webpack_require__(2493);
5115
5216
  // EXTERNAL MODULE: ./node_modules/preact/dist/preact.module.js
5116
5217
  var preact_module = __webpack_require__(6400);
5117
5218
  ;// CONCATENATED MODULE: ./src/plugin.js
5118
5219
 
5119
5220
 
5120
5221
 
5121
- const LoadChatbox = () => __webpack_require__.e(/* import() */ 74).then(__webpack_require__.bind(__webpack_require__, 1074));
5122
5222
 
5123
- const LoadContact = () => __webpack_require__.e(/* import() */ 619).then(__webpack_require__.bind(__webpack_require__, 9619));
5223
+ const LoadChatbox = () => __webpack_require__.e(/* import() */ 132).then(__webpack_require__.bind(__webpack_require__, 8132));
5224
+
5225
+ const LoadContact = () => __webpack_require__.e(/* import() */ 335).then(__webpack_require__.bind(__webpack_require__, 2335));
5124
5226
 
5125
5227
  const LoadPopup = () => __webpack_require__.e(/* import() */ 213).then(__webpack_require__.bind(__webpack_require__, 8213));
5126
5228
 
5127
5229
  const LoadNotif = () => __webpack_require__.e(/* import() */ 605).then(__webpack_require__.bind(__webpack_require__, 9605));
5128
5230
 
5129
- let langMessages = {};
5130
- let downloadLock = false;
5131
-
5132
5231
  function Plugin(plugin, store, $container, lib) {
5133
5232
  if (!$container) throw '$div must is a valid html node';
5134
5233
  var $div = document.createElement('div');
5135
5234
  $div.id = plugin.id;
5136
5235
  $container.appendChild($div);
5137
5236
 
5138
- let _locale = getLocale(plugin, util/* default.detectLang */.Z.detectLang());
5237
+ let _locale = common/* getLocale */.Kd(plugin, util/* default.detectLang */.Z.detectLang());
5139
5238
 
5140
5239
  var domGate = new util/* default.Gate */.Z.Gate();
5141
5240
  var pageIndex = 0;
@@ -5265,7 +5364,7 @@ function Plugin(plugin, store, $container, lib) {
5265
5364
 
5266
5365
  let t = key => {
5267
5366
  if (_locale === 'debug') return `{{${key}}}`;
5268
- let messages = util/* default.get */.Z.get(langMessages, _locale, []);
5367
+ let messages = util/* default.get */.Z.get(common/* langMessages */.Rs, _locale, []);
5269
5368
  let message = util/* default.find */.Z.find(messages, message => message.key === key);
5270
5369
  return util/* default.get */.Z.get(message, 'message', key);
5271
5370
  };
@@ -5285,7 +5384,7 @@ function Plugin(plugin, store, $container, lib) {
5285
5384
  t.locale = () => _locale;
5286
5385
 
5287
5386
  this.forceDownloadLanguage = async () => {
5288
- await downloadLanguage(store, _locale, true);
5387
+ await common/* downloadLanguage */.WW(store, _locale, true);
5289
5388
  this.update(plugin);
5290
5389
  };
5291
5390
 
@@ -5295,8 +5394,8 @@ function Plugin(plugin, store, $container, lib) {
5295
5394
 
5296
5395
  _render();
5297
5396
 
5298
- _locale = getLocale(plugin, locale);
5299
- await downloadLanguage(store, _locale);
5397
+ _locale = common/* getLocale */.Kd(plugin, locale);
5398
+ await common/* downloadLanguage */.WW(store, _locale);
5300
5399
  this.t = t;
5301
5400
 
5302
5401
  _render();
@@ -5332,7 +5431,7 @@ function Plugin(plugin, store, $container, lib) {
5332
5431
  }
5333
5432
 
5334
5433
  this.update(plugin);
5335
- downloadLanguage(store, _locale).then(() => {
5434
+ common/* downloadLanguage */.WW(store, _locale).then(() => {
5336
5435
  this.t = t;
5337
5436
  this.update(plugin);
5338
5437
  });
@@ -5476,39 +5575,7 @@ class PluginMgr {
5476
5575
  }
5477
5576
 
5478
5577
  }
5479
-
5480
- function downloadLanguage(store, locale, force) {
5481
- if (downloadLock) return new Promise(resolve => setTimeout(() => downloadLanguage(store, locale, force).then(resolve), 100));
5482
- downloadLock = true;
5483
- let messages;
5484
-
5485
- if (locale === 'debug' || langMessages[locale] && !force) {
5486
- downloadLock = false;
5487
- return Promise.resolve();
5488
- }
5489
-
5490
- return store.getLocaleContent(locale).then(res => {
5491
- downloadLock = false;
5492
- messages = util/* default.get */.Z.get(res, 'body.messages', []);
5493
- langMessages[locale] = messages;
5494
- });
5495
- }
5496
-
5497
- const getLocale = (plugin, loc) => {
5498
- if (!loc) loc = '';
5499
- let found = util/* default.find */.Z.find(plugin.locales, l => l.toLowerCase().trim() === loc.toLowerCase().trim());
5500
- if (found) return found;
5501
- found = util/* default.find */.Z.find(plugin.locales, l => {
5502
- l = l.replace('-', '_').split('_')[0].trim().toLowerCase();
5503
- let compareloc = loc.replace('-', '_').split('_')[0].trim().toLowerCase();
5504
- return l == compareloc;
5505
- });
5506
- if (found) return found;
5507
- return plugin.locale || 'en-US';
5508
- };
5509
5578
  ;// CONCATENATED MODULE: ./src/lib.js
5510
- function lib_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5511
-
5512
5579
 
5513
5580
 
5514
5581
 
@@ -5520,18 +5587,6 @@ util/* default.preloadWebfonts */.Z.preloadWebfonts(['Roboto'], [400, 500]);
5520
5587
 
5521
5588
  class Widget {
5522
5589
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fake, agenttoken) {
5523
- lib_defineProperty(this, "version", () => '4.4');
5524
-
5525
- lib_defineProperty(this, "setSetting", setting => this.store.setSetting({
5526
- account_setting: setting
5527
- }));
5528
-
5529
- lib_defineProperty(this, "getSetting", _ => ({
5530
- account_setting: util/* default.cloneDeep */.Z.cloneDeep(this.store.matchAccountSetting())
5531
- }));
5532
-
5533
- lib_defineProperty(this, "getUser", () => util/* default.parseJSON */.Z.parseJSON(util/* default.stringify */.Z.stringify(this.store.matchUser())));
5534
-
5535
5590
  this.domGate = new util/* default.Gate */.Z.Gate();
5536
5591
  this.store = new Store(ApiURL, FileURL, RealtimeURL, inmem, fake, agenttoken);
5537
5592
  window.sbz_store = this.store;
@@ -5567,7 +5622,6 @@ class Widget {
5567
5622
  this.pluginMgr.destroy();
5568
5623
  clearInterval(clean);
5569
5624
  }, 1000);
5570
- console.log('OUT33', outmask);
5571
5625
  this.domGate.open();
5572
5626
  cb && cb(outmask);
5573
5627
  return outmask;
@@ -5637,6 +5691,15 @@ class Widget {
5637
5691
  this.pluginMgr.hideCurrentChatbox();
5638
5692
  }
5639
5693
 
5694
+ version = () => '4.4';
5695
+ setSetting = setting => this.store.setSetting({
5696
+ account_setting: setting
5697
+ });
5698
+ getSetting = _ => ({
5699
+ account_setting: util/* default.cloneDeep */.Z.cloneDeep(this.store.matchAccountSetting())
5700
+ });
5701
+ getUser = () => util/* default.parseJSON */.Z.parseJSON(util/* default.stringify */.Z.stringify(this.store.matchUser()));
5702
+
5640
5703
  async setLocale(locale) {
5641
5704
  await this.domGate.entry();
5642
5705
  return this.pluginMgr.setCurrentChatboxLocale(locale);