@subiz/widget-v4 4.0.61 → 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 (154) 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 +33 -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/spinner.js +1 -1
  35. package/compiled_src/chatbox/time.js +3 -1
  36. package/compiled_src/common.js +40 -1
  37. package/compiled_src/contact/contact.js +7 -12
  38. package/compiled_src/lib.js +9 -14
  39. package/compiled_src/notif/notif.js +12 -15
  40. package/compiled_src/order/address_picker.js +241 -0
  41. package/compiled_src/order/icon.js +62 -0
  42. package/compiled_src/order/index.js +113 -0
  43. package/compiled_src/order/order.js +1220 -0
  44. package/compiled_src/plugin.js +9 -42
  45. package/compiled_src/popup/countdown.js +4 -7
  46. package/compiled_src/popup/popup.js +9 -12
  47. package/compiled_src/store/api.js +80 -90
  48. package/compiled_src/store/api_fake.js +55 -82
  49. package/compiled_src/store/store.js +163 -158
  50. package/compiled_src/util/common.js +36 -2
  51. package/dist/0b82fa7e5c3b07b40a44.png +1 -0
  52. package/dist/0f4af006e38ee8b93633.png +1 -0
  53. package/dist/{74.js → 132.js} +2232 -235
  54. package/dist/178.js +341 -174
  55. package/dist/17e757ccadd.132.js +1 -0
  56. package/dist/17e757ccadd.178.js +1 -0
  57. package/dist/17e757ccadd.213.js +1 -0
  58. package/dist/17e757ccadd.335.js +1 -0
  59. package/dist/17e757ccadd.362.js +1 -0
  60. package/dist/17e757ccadd.441.js +1 -0
  61. package/dist/17e757ccadd.605.js +1 -0
  62. package/dist/17e757ccadd.678.js +1 -0
  63. package/dist/17e757ccadd.782.js +1 -0
  64. package/dist/17e757ccadd.app.js +1 -0
  65. package/dist/{17db8166252.index.html → 17e757ccadd.index.html} +1 -1
  66. package/dist/{17db8166252.library.html → 17e757ccadd.library.html} +1 -1
  67. package/dist/17e757ccadd.library.js +1 -0
  68. package/dist/{17db8166252.preview.html → 17e757ccadd.preview.html} +1 -1
  69. package/dist/17e757ccadd.preview.js +1 -0
  70. package/dist/17e757ccadd.screenshoot.js +1 -0
  71. package/dist/1ea1c6cd21d25176810c.png +1 -0
  72. package/dist/213.js +18 -88
  73. package/dist/292d42404e1b03398f61.png +1 -0
  74. package/dist/312d376370831b7bea83.png +1 -0
  75. package/dist/313d1bfc1cf776d1aefe.png +1 -0
  76. package/dist/335.js +408 -0
  77. package/dist/362.js +71 -21
  78. package/dist/441.js +69 -43
  79. package/dist/4aa58bb7a66bb44975aa.png +1 -0
  80. package/dist/56ce063bc6c81adb7322.png +1 -0
  81. package/dist/605.js +13 -79
  82. package/dist/678.js +70 -20
  83. package/dist/6a411166ef5cc79e0714.png +1 -0
  84. package/dist/6faf403782fefacc1649.png +1 -0
  85. package/dist/782.js +118 -21
  86. package/dist/79dca33c68fab79c067f.png +1 -0
  87. package/dist/82da1578fa84f9debaeb.png +1 -0
  88. package/dist/8b8e0f0824743974b282.png +1 -0
  89. package/dist/8d551390d81e39130a3c.png +1 -0
  90. package/dist/9fc61b9479877ebdb6c7.png +1 -0
  91. package/dist/HASH +1 -1
  92. package/dist/a165d31dcb3dc90f1057.png +1 -0
  93. package/dist/a98d4a5698812c4426b3.png +1 -0
  94. package/dist/assets/img/caret.998eb8f.svg +1 -0
  95. package/dist/assets/img/done_green.b817fd4.svg +4 -0
  96. package/dist/assets/img/empty_1.0b98af0.svg +11 -0
  97. package/dist/assets/img/ghn.070f8e3.svg +17 -0
  98. package/dist/assets/img/ghtk.326eac1.svg +18 -0
  99. package/dist/assets/img/info.ebce7ea.svg +1 -0
  100. package/dist/assets/img/loader.37000a7.svg +1 -0
  101. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  102. package/dist/assets/img/package.8d37d0f.svg +5 -0
  103. package/dist/assets/img/package_fade.763c001.svg +1 -0
  104. package/dist/assets/img/search.f9705ff.svg +1 -0
  105. package/dist/assets/img/shop.f7dc7d8.svg +1 -0
  106. package/dist/assets/img/shop_faded.df7845a.svg +1 -0
  107. package/dist/assets/img/x.26fdfa3.svg +5 -0
  108. package/dist/c41606bf9d1b604e46d5.png +1 -0
  109. package/dist/ce1f7450ce6c1aacd330.png +1 -0
  110. package/dist/cf8c01e88f4770a6e3e5.png +1 -0
  111. package/dist/dfbcfeab1d5622a737e2.png +1 -0
  112. package/dist/e4893ed8c2f7b8329919.png +1 -0
  113. package/dist/ec2ab4eb4ef73d186186.png +1 -0
  114. package/dist/screenshoot.html +1 -1
  115. package/dist/screenshoot.js +448 -386
  116. package/order.html +19 -771
  117. package/package.json +12 -13
  118. package/src/chatbox/DropdownSelect.js +229 -0
  119. package/src/chatbox/Event.js +2 -2
  120. package/src/chatbox/Events.js +43 -42
  121. package/src/chatbox/Order.js +232 -0
  122. package/src/chatbox/OrderAttachments.js +2 -1
  123. package/src/chatbox/TextMessage.js +21 -12
  124. package/src/chatbox/Widget.js +34 -4
  125. package/src/chatbox/spinner.js +1 -1
  126. package/src/chatbox/time.js +1 -1
  127. package/src/common.js +52 -8
  128. package/src/contact/contact.js +1 -1
  129. package/src/order/address_picker.js +235 -0
  130. package/src/order/icon.js +32 -0
  131. package/src/order/index.js +86 -0
  132. package/src/order/order.js +1157 -0
  133. package/src/order/scratch +211 -0
  134. package/src/plugin.js +7 -52
  135. package/src/store/api.js +26 -1
  136. package/src/store/store.js +46 -9
  137. package/src/util/common.js +48 -2
  138. package/webpack.dev.js +2 -0
  139. package/dist/17db8166252.178.js +0 -1
  140. package/dist/17db8166252.213.js +0 -1
  141. package/dist/17db8166252.362.js +0 -1
  142. package/dist/17db8166252.441.js +0 -1
  143. package/dist/17db8166252.605.js +0 -1
  144. package/dist/17db8166252.619.js +0 -1
  145. package/dist/17db8166252.678.js +0 -1
  146. package/dist/17db8166252.74.js +0 -1
  147. package/dist/17db8166252.782.js +0 -1
  148. package/dist/17db8166252.app.js +0 -1
  149. package/dist/17db8166252.library.js +0 -1
  150. package/dist/17db8166252.preview.js +0 -1
  151. package/dist/17db8166252.screenshoot.js +0 -1
  152. package/dist/619.js +0 -777
  153. package/order.js +0 -0
  154. package/test.js +0 -1
@@ -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
 
@@ -2298,6 +2397,7 @@ function preloadWebfonts(fonts, done) {
2298
2397
  node.style.color = 'transparent';
2299
2398
  node.style.fontSize = '20px';
2300
2399
  node.style.height = '0px';
2400
+ node.style.top = '0px';
2301
2401
  node.style.width = '0px';
2302
2402
  node.style.fontWeight = weight;
2303
2403
  node.setAttribute('subiz-preload', font + ':' + weight);
@@ -2419,9 +2519,9 @@ function getUrlParameter() {
2419
2519
  }
2420
2520
  var sleep = ms => new Promise(res => setTimeout(res, ms));
2421
2521
  function formatCurrency(val) {
2422
- if (!val) return 0;
2522
+ if (!val) return '0 đ';
2423
2523
  val = Math.round(val);
2424
- return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
2524
+ return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') + ' đ';
2425
2525
  }
2426
2526
 
2427
2527
  function replaceFileUrl(src) {
@@ -2449,6 +2549,36 @@ function replaceFileUrl(src) {
2449
2549
  return src;
2450
2550
  }
2451
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
+
2452
2582
  /***/ }),
2453
2583
 
2454
2584
  /***/ 2302:
@@ -3234,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
3234
3364
  /******/
3235
3365
  /******/ /* webpack/runtime/jsonp chunk loading */
3236
3366
  /******/ (() => {
3237
- /******/ // no baseURI
3367
+ /******/ __webpack_require__.b = document.baseURI || self.location.href;
3238
3368
  /******/
3239
3369
  /******/ // object to store loaded and loading chunks
3240
3370
  /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
@@ -3312,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
3312
3442
  /******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
3313
3443
  /******/ installedChunks[chunkId][0]();
3314
3444
  /******/ }
3315
- /******/ installedChunks[chunkIds[i]] = 0;
3445
+ /******/ installedChunks[chunkId] = 0;
3316
3446
  /******/ }
3317
3447
  /******/
3318
3448
  /******/ }
@@ -3346,8 +3476,6 @@ var lsdb = (__webpack_require__(6929)/* ["default"] */ .Z);
3346
3476
  inmem_localstorage
3347
3477
  });
3348
3478
  ;// CONCATENATED MODULE: ./src/store/api.js
3349
- 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; }
3350
-
3351
3479
 
3352
3480
 
3353
3481
  const ajax = __webpack_require__(7460);
@@ -3364,92 +3492,6 @@ function jsonifyTextPlain(param, done) {
3364
3492
 
3365
3493
  /* harmony default export */ const api = (class {
3366
3494
  constructor(ApiURL, FileURL) {
3367
- _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get('/conversations'));
3368
-
3369
- _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/conversations/${cid}/messages`));
3370
-
3371
- _defineProperty(this, "ajax", ajax);
3372
-
3373
- _defineProperty(this, "start", extraData => {
3374
- let data = {
3375
- starter_id: this.uid,
3376
- starter_type: 'user',
3377
- integration_id: `${this.accid}.subizv4.subikon`
3378
- };
3379
- util/* default.each */.Z.each(extraData, (v, k) => {
3380
- data[k] = v;
3381
- });
3382
- return this.apireq.post('/conversations', data);
3383
- });
3384
-
3385
- _defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));
3386
-
3387
- _defineProperty(this, "createPostback", (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p));
3388
-
3389
- _defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/receive`));
3390
-
3391
- _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/seen`));
3392
-
3393
- _defineProperty(this, "getConversation", cid => this.apireq.get(`/conversations/${cid}`));
3394
-
3395
- _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
3396
-
3397
- _defineProperty(this, "sendEvent", data => this.apireq.post(`/users/${this.uid}/events`, data));
3398
-
3399
- _defineProperty(this, "sendTyping", cid => this.apireq.post(`/conversations/${cid}/typing`));
3400
-
3401
- _defineProperty(this, "uploadToS3", async file => {
3402
- let {
3403
- body: signed,
3404
- error
3405
- } = await this.apireq.post(`/accounts/${this.accid}/files`, {
3406
- account_id: this.accid,
3407
- description: 'upload\n user-client: web-widget',
3408
- name: file.name.replace(/\s+/g, '_'),
3409
- size: file.size,
3410
- type: file.type
3411
- });
3412
- if (error) return {
3413
- error
3414
- };
3415
- let contentType = file.type || 'application/octet-stream';
3416
- ({
3417
- error
3418
- } = await ajax.setContentType(contentType).put(signed.signed_url, file));
3419
- if (error) return {
3420
- error
3421
- };
3422
- let body;
3423
- ({
3424
- body,
3425
- error
3426
- } = await this.apireq.post(`/accounts/${this.accid}/files/${signed.id}`, {
3427
- account_id: this.accid
3428
- }));
3429
- if (error) return {
3430
- error
3431
- };
3432
- return {
3433
- url: this.FileURL + body.url
3434
- };
3435
- });
3436
-
3437
- _defineProperty(this, "getChallenge", accid => this.apireq.post(`/accounts/${accid}/scrypt-challenges`));
3438
-
3439
- _defineProperty(this, "time", _ => this.apireq.get('/time'));
3440
-
3441
- _defineProperty(this, "updateUser", data => this.apireq.post(`/users/${this.uid}`, data));
3442
-
3443
- _defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
3444
-
3445
- _defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
3446
-
3447
- _defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
3448
-
3449
- _defineProperty(this, "sendImpression", impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression));
3450
-
3451
- _defineProperty(this, "sendConversion", conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion));
3452
-
3453
3495
  this.FileURL = FileURL;
3454
3496
  this.ApiURL = ApiURL;
3455
3497
  this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').beforeHook((param, done) => {
@@ -3468,6 +3510,29 @@ function jsonifyTextPlain(param, done) {
3468
3510
  this.uid = obj.uid;
3469
3511
  }
3470
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
+
3471
3536
  sendPresence(device, is_focused) {
3472
3537
  return this.sendEvent({
3473
3538
  by: {
@@ -3501,6 +3566,43 @@ function jsonifyTextPlain(param, done) {
3501
3566
  });
3502
3567
  }
3503
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
+
3504
3606
  async createAgentUser(agenttoken) {
3505
3607
  for (var i = 0; i < 10; i++) {
3506
3608
  let {
@@ -3543,10 +3645,26 @@ function jsonifyTextPlain(param, done) {
3543
3645
  }
3544
3646
  }
3545
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`);
3546
3666
  });
3547
3667
  ;// CONCATENATED MODULE: ./src/store/api_fake.js
3548
- 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; }
3549
-
3550
3668
 
3551
3669
 
3552
3670
  const api_fake_ajax = __webpack_require__(7460);
@@ -3566,86 +3684,6 @@ const OK200 = Promise.resolve({
3566
3684
  });
3567
3685
  /* harmony default export */ const api_fake = (class {
3568
3686
  constructor(ApiURL, FileURL) {
3569
- api_fake_defineProperty(this, "listConversations", _ => {
3570
- let convo = makeFakeConvo(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid);
3571
- return Promise.resolve({
3572
- body: {
3573
- anchor: '',
3574
- conversations: [convo]
3575
- },
3576
- code: 200
3577
- });
3578
- });
3579
-
3580
- api_fake_defineProperty(this, "listMessages", (cid, limit, start_id) => {
3581
- let messages = makeFakeMessages(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid);
3582
- return Promise.resolve({
3583
- body: messages,
3584
- code: 200
3585
- });
3586
- });
3587
-
3588
- api_fake_defineProperty(this, "ajax", api_fake_ajax);
3589
-
3590
- api_fake_defineProperty(this, "start", extraData => OK200);
3591
-
3592
- api_fake_defineProperty(this, "sendConvoEvent", (cid, ev) => OK200);
3593
-
3594
- api_fake_defineProperty(this, "createPostback", (cid, p) => OK200);
3595
-
3596
- api_fake_defineProperty(this, "markAsReceived", (cid, messageId) => OK200);
3597
-
3598
- api_fake_defineProperty(this, "markAsSeen", (cid, messageId) => OK200);
3599
-
3600
- api_fake_defineProperty(this, "getConversation", cid => Promise.resolve({
3601
- body: makeFakeConvo(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid),
3602
- code: 200
3603
- }));
3604
-
3605
- api_fake_defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
3606
-
3607
- api_fake_defineProperty(this, "sendEvent", data => OK200);
3608
-
3609
- api_fake_defineProperty(this, "sendTyping", cid => OK200);
3610
-
3611
- api_fake_defineProperty(this, "sendPresence", data => OK200);
3612
-
3613
- api_fake_defineProperty(this, "sendContent", data => OK200);
3614
-
3615
- api_fake_defineProperty(this, "uploadToS3", async file => OK200);
3616
-
3617
- api_fake_defineProperty(this, "getChallenge", accid => OK200);
3618
-
3619
- api_fake_defineProperty(this, "createUser", accid => Promise.resolve({
3620
- account_id: accid,
3621
- id: 'usqzgtgfake',
3622
- mask: 'fakemask'
3623
- }));
3624
-
3625
- api_fake_defineProperty(this, "createAgentUser", agenttoken => Promise.resolve('fakemask'));
3626
-
3627
- api_fake_defineProperty(this, "time", _ => Promise.resolve({
3628
- code: 200,
3629
- body: new util/* default.Date */.Z.Date().toISOString()
3630
- }));
3631
-
3632
- api_fake_defineProperty(this, "updateUser", data => OK200);
3633
-
3634
- api_fake_defineProperty(this, "getUser", _ => Promise.resolve({
3635
- code: 200,
3636
- body: {
3637
- id: '-'
3638
- }
3639
- }));
3640
-
3641
- api_fake_defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
3642
-
3643
- api_fake_defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
3644
-
3645
- api_fake_defineProperty(this, "sendImpression", impression => OK200);
3646
-
3647
- api_fake_defineProperty(this, "sendConversion", conversion => OK200);
3648
-
3649
3687
  this.FileURL = FileURL;
3650
3688
  this.apireq = api_fake_ajax.setBaseUrl(ApiURL).setContentType('text/plain').beforeHook(api_fake_jsonifyTextPlain).setParser('json');
3651
3689
  }
@@ -3660,6 +3698,61 @@ const OK200 = Promise.resolve({
3660
3698
  this.uid = obj.uid;
3661
3699
  }
3662
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;
3663
3756
  });
3664
3757
 
3665
3758
  function makeFakeConvo(accid, convoid, userid, agentid) {
@@ -4012,8 +4105,6 @@ function makeFakeMessages(accid, convoid, userid, agentid) {
4012
4105
 
4013
4106
  });
4014
4107
  ;// CONCATENATED MODULE: ./src/store/store.js
4015
- 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; }
4016
-
4017
4108
 
4018
4109
 
4019
4110
  var flow = __webpack_require__(3165);
@@ -4034,160 +4125,6 @@ const MAX_CONVO = 20;
4034
4125
  const page_loaded = util/* default.Date.now */.Z.Date.now();
4035
4126
  class Store {
4036
4127
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi, agenttoken) {
4037
- store_defineProperty(this, "inmem", false);
4038
-
4039
- store_defineProperty(this, "cookie", cookie);
4040
-
4041
- store_defineProperty(this, "new_visitor", true);
4042
-
4043
- store_defineProperty(this, "matchUser", () => {
4044
- this._touchAcc();
4045
-
4046
- return this.kv.match('user');
4047
- });
4048
-
4049
- store_defineProperty(this, "matchSession", () => this.kv.match('session') || {});
4050
-
4051
- store_defineProperty(this, "matchAccount", () => this.cache.match('account'));
4052
-
4053
- store_defineProperty(this, "matchUnread", () => {
4054
- let user = this.matchUser();
4055
- let allconvos = this.matchConvo('*');
4056
- let unreadcount = 0;
4057
- util/* default.map */.Z.map(allconvos, convo => {
4058
- if (!util/* default.isConvoSeen */.Z.isConvoSeen(convo, user.id)) unreadcount++;
4059
- });
4060
- return unreadcount;
4061
- });
4062
-
4063
- store_defineProperty(this, "matchPlugin", () => {
4064
- if (util/* default.size */.Z.size(this.forcePlugins) > 0) return util/* default.cloneDeep */.Z.cloneDeep(this.forcePlugins);
4065
- return util/* default.cloneDeep */.Z.cloneDeep(this.cache.match('plugin')) || {};
4066
- });
4067
-
4068
- store_defineProperty(this, "device", {});
4069
-
4070
- store_defineProperty(this, "browserVisibility", 'visible');
4071
-
4072
- store_defineProperty(this, "matchAgent", id => {
4073
- let agentM = this.cache.match('agent') || {};
4074
- if (id === '*') return agentM;
4075
- return agentM[id];
4076
- });
4077
-
4078
- store_defineProperty(this, "matchConvo", id => {
4079
- if (!id) return;
4080
-
4081
- if (id === '*') {
4082
- this._touchAcc();
4083
-
4084
- return util/* default.filter */.Z.filter(this.cache.all(), (value, k) => k.startsWith('convo_'));
4085
- }
4086
-
4087
- if (!this.isInsync(id)) this.fetchConvo(id);
4088
- return this.cache.match('convo_' + id);
4089
- });
4090
-
4091
- store_defineProperty(this, "fetchConvo", async cid => {
4092
- await this.readyGate.entry();
4093
- await this.reconnectGate.entry(undefined, true);
4094
- if (this.isInsync(cid)) return this.reconnectGate.open();
4095
- this.markSync(cid);
4096
- let {
4097
- body: convo,
4098
- error
4099
- } = await this.api.getConversation(cid);
4100
- if (convo && !error) this._setConvo(convo);
4101
- return this.reconnectGate.open();
4102
- });
4103
-
4104
- store_defineProperty(this, "listEvents", id => {
4105
- if (!id || id === '*' || typeof id !== 'string') return;
4106
-
4107
- if (!this.isInsync('events' + id)) {
4108
- setTimeout(async () => {
4109
- await this.readyGate.entry();
4110
- await this.reconnectGate.entry(undefined, true);
4111
- if (this.isInsync('events' + id)) return this.reconnectGate.open();
4112
- this.markSync('events' + id);
4113
- await this.chain.reload(id, (type, anchor, limit) => this.listmessageapi(type, anchor, limit));
4114
- this.pubsub.publish('account');
4115
- return this.reconnectGate.open();
4116
- }, 10);
4117
- }
4118
-
4119
- return this.chain.listM(id);
4120
- });
4121
-
4122
- store_defineProperty(this, "fetchMoreEvents", async convoid => {
4123
- let {
4124
- error
4125
- } = await this.chain.fetchMore(convoid, 50, (type, anchor, limit) => this.listmessageapi(type, anchor, limit));
4126
- this.pubsub.publish('account');
4127
- return {
4128
- error
4129
- };
4130
- });
4131
-
4132
- store_defineProperty(this, "matchBot", () => this.cache.match('bot') || {});
4133
-
4134
- store_defineProperty(this, "readyGate", new util/* default.Gate */.Z.Gate());
4135
-
4136
- store_defineProperty(this, "convoGate", new util/* default.Gate */.Z.Gate(true));
4137
-
4138
- store_defineProperty(this, "reconnectGate", new util/* default.Gate */.Z.Gate(true));
4139
-
4140
- store_defineProperty(this, "matchLastview", () => this.kv.match('lastview') || {});
4141
-
4142
- store_defineProperty(this, "matchIsOpen", () => !!this.kv.match('isopen'));
4143
-
4144
- store_defineProperty(this, "matchHasManuallyClosed", () => !!this.kv.match('hasManuallyClosed'));
4145
-
4146
- store_defineProperty(this, "matchClosePreviewAt", () => this.kv.match('close_preview_at') || 0);
4147
-
4148
- store_defineProperty(this, "sendPresence", util/* default.throttle */.Z.throttle(async () => {
4149
- await this.readyGate.entry();
4150
- if (!util/* default.get */.Z.get(this.kv.match('user'), 'id')) return;
4151
- if (util/* default.isUserBanned */.Z.isUserBanned(this.kv.match('user'))) return;
4152
- return this.api.sendPresence(this.device, this.browserVisibility === 'visible' && document.hasFocus());
4153
- }, 1000));
4154
-
4155
- store_defineProperty(this, "now", () => util/* default.Date.now */.Z.Date.now() + this.timeDiff);
4156
-
4157
- store_defineProperty(this, "seenQueue", []);
4158
-
4159
- store_defineProperty(this, "_typing", util/* default.throttle */.Z.throttle(convoid => this.api.sendTyping(convoid), 3000));
4160
-
4161
- store_defineProperty(this, "onConvoEvent", (o, cb) => this.pubsub.on2(o, 'events', cb));
4162
-
4163
- store_defineProperty(this, "seenConvo", id => {
4164
- if (!id || id === 'create') return;
4165
- this.seenQueue.push(id);
4166
- });
4167
-
4168
- store_defineProperty(this, "onUpdate", (o, cb) => this.pubsub.on2(o, 'account', cb));
4169
-
4170
- store_defineProperty(this, "onResetCSS", (o, cb) => this.pubsub.on2(o, 'resetCSS', cb));
4171
-
4172
- store_defineProperty(this, "onHighlight", (o, cb) => this.pubsub.on2(o, 'highlight', cb));
4173
-
4174
- store_defineProperty(this, "setHasManuallyClosed", () => this.kv.put('hasManuallyClosed', true));
4175
-
4176
- store_defineProperty(this, "setIsOpen", isopen => {
4177
- let lastisopen = this.kv.match('isopen');
4178
- this.kv.put('isopen', isopen);
4179
- if (!lastisopen && isopen) sendEventToThirdParty('SUBIZ Chat', 'Opened', 'Subiz Windows');
4180
- });
4181
-
4182
- store_defineProperty(this, "closePreview", () => this.kv.put('close_preview_at', new util/* default.Date */.Z.Date().getTime()));
4183
-
4184
- store_defineProperty(this, "setLastview", (view, opts) => this.kv.put('lastview', {
4185
- view,
4186
- opts
4187
- }));
4188
-
4189
- store_defineProperty(this, "timeDiff", 0);
4190
-
4191
4128
  this.agent_token = agenttoken;
4192
4129
  this.g_sync = {};
4193
4130
  this.forceDevice = null;
@@ -4241,10 +4178,31 @@ class Store {
4241
4178
  }, 2000);
4242
4179
  }
4243
4180
 
4181
+ inmem = false;
4182
+ cookie = cookie;
4183
+
4244
4184
  isInsync(key) {
4245
4185
  return util/* default.Date.now */.Z.Date.now() - (this.g_sync[key] || 0) < 300000;
4246
4186
  }
4247
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
+
4248
4206
  async overrideAcc(acc) {
4249
4207
  this.forceAcc = util/* default.cloneDeep */.Z.cloneDeep(acc);
4250
4208
  await this.readyGate.entry();
@@ -4321,12 +4279,113 @@ class Store {
4321
4279
  this.g_sync[key] = util/* default.Date.now */.Z.Date.now();
4322
4280
  }
4323
4281
 
4282
+ new_visitor = true;
4283
+
4324
4284
  async _touchAcc() {
4325
4285
  if (this.isInsync('account')) return;
4326
4286
  await this.readyGate.entry();
4327
4287
  if (!this.isInsync('account')) this.reconnect();
4328
4288
  }
4329
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
+
4330
4389
  async init(accid, mask) {
4331
4390
  this.readyGate.close();
4332
4391
  accid = (accid || '').trim();
@@ -4385,6 +4444,8 @@ class Store {
4385
4444
  return mask;
4386
4445
  }
4387
4446
 
4447
+ seenQueue = [];
4448
+
4388
4449
  seenLoop() {
4389
4450
  this.seenQueue = [];
4390
4451
  clearInterval(this._seenInterval);
@@ -4458,6 +4519,7 @@ class Store {
4458
4519
  }
4459
4520
 
4460
4521
  _setUser(user) {
4522
+ user = util/* default.cloneDeep */.Z.cloneDeep(user);
4461
4523
  let olduser = this.kv.match('user') || {};
4462
4524
  var accid = olduser.account_id || user.account_id;
4463
4525
  var id = olduser.id || user.id;
@@ -4549,6 +4611,8 @@ class Store {
4549
4611
  this.cache.put('agent', agentM);
4550
4612
  }
4551
4613
 
4614
+ let pms = util/* default.get */.Z.get(setting, 'payment_methods', []);
4615
+ this.cache.put('payment_methods', pms);
4552
4616
  this.pubsub.publish('account');
4553
4617
  }
4554
4618
 
@@ -4727,6 +4791,8 @@ class Store {
4727
4791
  this._typing(cid);
4728
4792
  }
4729
4793
 
4794
+ _typing = util/* default.throttle */.Z.throttle(convoid => this.api.sendTyping(convoid), 3000);
4795
+
4730
4796
  async startConvo(req) {
4731
4797
  await this.readyGate.entry();
4732
4798
  this.convoGate.close();
@@ -4747,6 +4813,14 @@ class Store {
4747
4813
  };
4748
4814
  }
4749
4815
 
4816
+ fetchOrder(id) {
4817
+ return this.api.getOrder(id);
4818
+ }
4819
+
4820
+ lookupOrder(key) {
4821
+ return this.api.lookupOrder(key);
4822
+ }
4823
+
4750
4824
  createPostback(cid, postback) {
4751
4825
  return this.api.createPostback(cid, postback);
4752
4826
  }
@@ -4811,6 +4885,12 @@ class Store {
4811
4885
  sendEventToThirdParty('SUBIZ Chat', 'Sent', 'User');
4812
4886
  }
4813
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
+
4814
4894
  _setConvo(convo) {
4815
4895
  let count = 0;
4816
4896
  let user = this.kv.match('user');
@@ -4838,6 +4918,21 @@ class Store {
4838
4918
  this.cache.put('convo_' + convo.id, convo);
4839
4919
  }
4840
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
+
4841
4936
  matchLastPluginRun(pluginid) {
4842
4937
  let log = this.kv.match('plugin_run_logs') || {};
4843
4938
  return log[pluginid];
@@ -4940,6 +5035,8 @@ class Store {
4940
5035
  return [events, anchor];
4941
5036
  }
4942
5037
 
5038
+ timeDiff = 0;
5039
+
4943
5040
  async loopTime() {
4944
5041
  let startms = util/* default.Date.now */.Z.Date.now();
4945
5042
  if (!util/* default.get */.Z.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 30000);
@@ -5114,30 +5211,30 @@ let mobileCheck = function (a) {
5114
5211
  }(navigator.userAgent || navigator.vendor || window.opera);
5115
5212
 
5116
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);
5117
5216
  // EXTERNAL MODULE: ./node_modules/preact/dist/preact.module.js
5118
5217
  var preact_module = __webpack_require__(6400);
5119
5218
  ;// CONCATENATED MODULE: ./src/plugin.js
5120
5219
 
5121
5220
 
5122
5221
 
5123
- const LoadChatbox = () => __webpack_require__.e(/* import() */ 74).then(__webpack_require__.bind(__webpack_require__, 1074));
5124
5222
 
5125
- 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));
5126
5226
 
5127
5227
  const LoadPopup = () => __webpack_require__.e(/* import() */ 213).then(__webpack_require__.bind(__webpack_require__, 8213));
5128
5228
 
5129
5229
  const LoadNotif = () => __webpack_require__.e(/* import() */ 605).then(__webpack_require__.bind(__webpack_require__, 9605));
5130
5230
 
5131
- let langMessages = {};
5132
- let downloadLock = false;
5133
-
5134
5231
  function Plugin(plugin, store, $container, lib) {
5135
5232
  if (!$container) throw '$div must is a valid html node';
5136
5233
  var $div = document.createElement('div');
5137
5234
  $div.id = plugin.id;
5138
5235
  $container.appendChild($div);
5139
5236
 
5140
- let _locale = getLocale(plugin, util/* default.detectLang */.Z.detectLang());
5237
+ let _locale = common/* getLocale */.Kd(plugin, util/* default.detectLang */.Z.detectLang());
5141
5238
 
5142
5239
  var domGate = new util/* default.Gate */.Z.Gate();
5143
5240
  var pageIndex = 0;
@@ -5267,7 +5364,7 @@ function Plugin(plugin, store, $container, lib) {
5267
5364
 
5268
5365
  let t = key => {
5269
5366
  if (_locale === 'debug') return `{{${key}}}`;
5270
- let messages = util/* default.get */.Z.get(langMessages, _locale, []);
5367
+ let messages = util/* default.get */.Z.get(common/* langMessages */.Rs, _locale, []);
5271
5368
  let message = util/* default.find */.Z.find(messages, message => message.key === key);
5272
5369
  return util/* default.get */.Z.get(message, 'message', key);
5273
5370
  };
@@ -5287,7 +5384,7 @@ function Plugin(plugin, store, $container, lib) {
5287
5384
  t.locale = () => _locale;
5288
5385
 
5289
5386
  this.forceDownloadLanguage = async () => {
5290
- await downloadLanguage(store, _locale, true);
5387
+ await common/* downloadLanguage */.WW(store, _locale, true);
5291
5388
  this.update(plugin);
5292
5389
  };
5293
5390
 
@@ -5297,8 +5394,8 @@ function Plugin(plugin, store, $container, lib) {
5297
5394
 
5298
5395
  _render();
5299
5396
 
5300
- _locale = getLocale(plugin, locale);
5301
- await downloadLanguage(store, _locale);
5397
+ _locale = common/* getLocale */.Kd(plugin, locale);
5398
+ await common/* downloadLanguage */.WW(store, _locale);
5302
5399
  this.t = t;
5303
5400
 
5304
5401
  _render();
@@ -5334,7 +5431,7 @@ function Plugin(plugin, store, $container, lib) {
5334
5431
  }
5335
5432
 
5336
5433
  this.update(plugin);
5337
- downloadLanguage(store, _locale).then(() => {
5434
+ common/* downloadLanguage */.WW(store, _locale).then(() => {
5338
5435
  this.t = t;
5339
5436
  this.update(plugin);
5340
5437
  });
@@ -5478,39 +5575,7 @@ class PluginMgr {
5478
5575
  }
5479
5576
 
5480
5577
  }
5481
-
5482
- function downloadLanguage(store, locale, force) {
5483
- if (downloadLock) return new Promise(resolve => setTimeout(() => downloadLanguage(store, locale, force).then(resolve), 100));
5484
- downloadLock = true;
5485
- let messages;
5486
-
5487
- if (locale === 'debug' || langMessages[locale] && !force) {
5488
- downloadLock = false;
5489
- return Promise.resolve();
5490
- }
5491
-
5492
- return store.getLocaleContent(locale).then(res => {
5493
- downloadLock = false;
5494
- messages = util/* default.get */.Z.get(res, 'body.messages', []);
5495
- langMessages[locale] = messages;
5496
- });
5497
- }
5498
-
5499
- const getLocale = (plugin, loc) => {
5500
- if (!loc) loc = '';
5501
- let found = util/* default.find */.Z.find(plugin.locales, l => l.toLowerCase().trim() === loc.toLowerCase().trim());
5502
- if (found) return found;
5503
- found = util/* default.find */.Z.find(plugin.locales, l => {
5504
- l = l.replace('-', '_').split('_')[0].trim().toLowerCase();
5505
- let compareloc = loc.replace('-', '_').split('_')[0].trim().toLowerCase();
5506
- return l == compareloc;
5507
- });
5508
- if (found) return found;
5509
- return plugin.locale || 'en-US';
5510
- };
5511
5578
  ;// CONCATENATED MODULE: ./src/lib.js
5512
- 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; }
5513
-
5514
5579
 
5515
5580
 
5516
5581
 
@@ -5522,18 +5587,6 @@ util/* default.preloadWebfonts */.Z.preloadWebfonts(['Roboto'], [400, 500]);
5522
5587
 
5523
5588
  class Widget {
5524
5589
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fake, agenttoken) {
5525
- lib_defineProperty(this, "version", () => '4.4');
5526
-
5527
- lib_defineProperty(this, "setSetting", setting => this.store.setSetting({
5528
- account_setting: setting
5529
- }));
5530
-
5531
- lib_defineProperty(this, "getSetting", _ => ({
5532
- account_setting: util/* default.cloneDeep */.Z.cloneDeep(this.store.matchAccountSetting())
5533
- }));
5534
-
5535
- lib_defineProperty(this, "getUser", () => util/* default.parseJSON */.Z.parseJSON(util/* default.stringify */.Z.stringify(this.store.matchUser())));
5536
-
5537
5590
  this.domGate = new util/* default.Gate */.Z.Gate();
5538
5591
  this.store = new Store(ApiURL, FileURL, RealtimeURL, inmem, fake, agenttoken);
5539
5592
  window.sbz_store = this.store;
@@ -5638,6 +5691,15 @@ class Widget {
5638
5691
  this.pluginMgr.hideCurrentChatbox();
5639
5692
  }
5640
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
+
5641
5703
  async setLocale(locale) {
5642
5704
  await this.domGate.entry();
5643
5705
  return this.pluginMgr.setCurrentChatboxLocale(locale);