@subiz/widget-v4 4.0.91 → 4.0.93

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 (194) hide show
  1. package/compiled_src/bot.js +0 -11
  2. package/compiled_src/call/call.js +0 -61
  3. package/compiled_src/call/css.js +0 -2
  4. package/compiled_src/chatbox/AgentsAvatar.js +0 -16
  5. package/compiled_src/chatbox/AudioAttachments.js +0 -14
  6. package/compiled_src/chatbox/ButtonAttachments.js +1 -14
  7. package/compiled_src/chatbox/Buttons.js +0 -13
  8. package/compiled_src/chatbox/ChatButton.js +1 -78
  9. package/compiled_src/chatbox/DropdownSelect.js +3 -44
  10. package/compiled_src/chatbox/Emoji.js +0 -7
  11. package/compiled_src/chatbox/Event.js +0 -59
  12. package/compiled_src/chatbox/Events.js +4 -44
  13. package/compiled_src/chatbox/FileAttachments.js +0 -14
  14. package/compiled_src/chatbox/FormAttachment.js +1 -52
  15. package/compiled_src/chatbox/FormAttachments.js +0 -14
  16. package/compiled_src/chatbox/FormSubmitAttachments.js +0 -11
  17. package/compiled_src/chatbox/GenericTemplateAttachments.js +1 -20
  18. package/compiled_src/chatbox/Header.js +1 -46
  19. package/compiled_src/chatbox/ImageAttachments.js +0 -16
  20. package/compiled_src/chatbox/InfoMessage.js +0 -13
  21. package/compiled_src/chatbox/ListField.js +0 -16
  22. package/compiled_src/chatbox/MessageInput.js +1 -47
  23. package/compiled_src/chatbox/Order.js +0 -35
  24. package/compiled_src/chatbox/OrderAttachments.js +1 -23
  25. package/compiled_src/chatbox/PoweredBy.js +0 -7
  26. package/compiled_src/chatbox/ProductAttachments.js +0 -19
  27. package/compiled_src/chatbox/QuickReplies.js +0 -18
  28. package/compiled_src/chatbox/Rating.js +0 -37
  29. package/compiled_src/chatbox/ShadowDomRoot.js +0 -9
  30. package/compiled_src/chatbox/TextMessage.js +0 -64
  31. package/compiled_src/chatbox/Typing.js +0 -15
  32. package/compiled_src/chatbox/VideoAttachments.js +0 -14
  33. package/compiled_src/chatbox/Widget.js +6 -167
  34. package/compiled_src/chatbox/css.js +0 -2
  35. package/compiled_src/chatbox/dragscroll.js +1 -5
  36. package/compiled_src/chatbox/main.js +3 -43
  37. package/compiled_src/chatbox/releaseAnimation.js +0 -11
  38. package/compiled_src/chatbox/spinner.js +0 -10
  39. package/compiled_src/chatbox/time.js +0 -22
  40. package/compiled_src/chatbox/touchscroll.js +0 -7
  41. package/compiled_src/common.js +0 -22
  42. package/compiled_src/contact/contact.js +2 -52
  43. package/compiled_src/contact/css.js +0 -2
  44. package/compiled_src/lib.js +19 -46
  45. package/compiled_src/notif/css.js +0 -2
  46. package/compiled_src/notif/notif.js +0 -63
  47. package/compiled_src/order/address_picker.js +4 -38
  48. package/compiled_src/order/icon.js +0 -16
  49. package/compiled_src/order/index.js +1 -34
  50. package/compiled_src/order/order.js +2 -156
  51. package/compiled_src/plugin.js +1 -77
  52. package/compiled_src/popup/countdown.js +2 -33
  53. package/compiled_src/popup/css.js +0 -2
  54. package/compiled_src/popup/popup.js +2 -165
  55. package/compiled_src/popup/tick.core.commonjs.js +72 -222
  56. package/compiled_src/popup/tick.view.flip.commonjs.js +23 -31
  57. package/compiled_src/store/api.js +103 -66
  58. package/compiled_src/store/api_fake.js +3 -39
  59. package/compiled_src/store/realtime_fake.js +0 -6
  60. package/compiled_src/store/store.js +46 -257
  61. package/compiled_src/util/campaign.js +0 -13
  62. package/compiled_src/util/common.js +15 -190
  63. package/compiled_src/util/common.test.js +0 -4
  64. package/compiled_src/util/extractor.js +1 -21
  65. package/compiled_src/util/extractor.test.js +0 -3
  66. package/compiled_src/util/gate.js +0 -7
  67. package/compiled_src/util/gate.test.js +1 -2
  68. package/compiled_src/util/index.js +1 -7
  69. package/compiled_src/util/mutex.js +31 -0
  70. package/compiled_src/util/op.js +1 -14
  71. package/compiled_src/util/pubsub.js +0 -6
  72. package/compiled_src/util/pubsub.test.js +0 -2
  73. package/package.json +12 -12
  74. package/src/chatbox/main.js +3 -3
  75. package/src/lib.js +24 -2
  76. package/src/store/api.js +111 -22
  77. package/src/store/api_fake.js +5 -6
  78. package/src/store/store.js +38 -14
  79. package/src/util/common.js +0 -4
  80. package/src/util/index.js +1 -0
  81. package/src/util/mutex.js +27 -0
  82. package/dist/0b82fa7e5c3b07b40a44.png +0 -1
  83. package/dist/0f4af006e38ee8b93633.png +0 -1
  84. package/dist/132.js +0 -6777
  85. package/dist/178.js +0 -573
  86. package/dist/17f00e48d38.132.js +0 -1
  87. package/dist/17f00e48d38.178.js +0 -1
  88. package/dist/17f00e48d38.213.js +0 -1
  89. package/dist/17f00e48d38.335.js +0 -1
  90. package/dist/17f00e48d38.362.js +0 -1
  91. package/dist/17f00e48d38.441.js +0 -1
  92. package/dist/17f00e48d38.605.js +0 -1
  93. package/dist/17f00e48d38.678.js +0 -1
  94. package/dist/17f00e48d38.782.js +0 -1
  95. package/dist/17f00e48d38.app.js +0 -1
  96. package/dist/17f00e48d38.index.html +0 -22
  97. package/dist/17f00e48d38.library.html +0 -22
  98. package/dist/17f00e48d38.library.js +0 -1
  99. package/dist/17f00e48d38.preview.html +0 -759
  100. package/dist/17f00e48d38.preview.js +0 -1
  101. package/dist/17f00e48d38.screenshoot.js +0 -1
  102. package/dist/1ea1c6cd21d25176810c.png +0 -1
  103. package/dist/213.js +0 -3188
  104. package/dist/292d42404e1b03398f61.png +0 -1
  105. package/dist/312d376370831b7bea83.png +0 -1
  106. package/dist/313d1bfc1cf776d1aefe.png +0 -1
  107. package/dist/335.js +0 -411
  108. package/dist/362.js +0 -157
  109. package/dist/441.js +0 -2732
  110. package/dist/4aa58bb7a66bb44975aa.png +0 -1
  111. package/dist/56ce063bc6c81adb7322.png +0 -1
  112. package/dist/605.js +0 -328
  113. package/dist/678.js +0 -157
  114. package/dist/6a411166ef5cc79e0714.png +0 -1
  115. package/dist/6faf403782fefacc1649.png +0 -1
  116. package/dist/782.js +0 -204
  117. package/dist/79dca33c68fab79c067f.png +0 -1
  118. package/dist/82da1578fa84f9debaeb.png +0 -1
  119. package/dist/8b8e0f0824743974b282.png +0 -1
  120. package/dist/8d551390d81e39130a3c.png +0 -1
  121. package/dist/9fc61b9479877ebdb6c7.png +0 -1
  122. package/dist/HASH +0 -1
  123. package/dist/a165d31dcb3dc90f1057.png +0 -1
  124. package/dist/a98d4a5698812c4426b3.png +0 -1
  125. package/dist/assets/img/Facebook.64607ec.png +0 -0
  126. package/dist/assets/img/Zalo.6845707.png +0 -0
  127. package/dist/assets/img/award1a.1a58e10.png +0 -0
  128. package/dist/assets/img/award3a.3b74423.png +0 -0
  129. package/dist/assets/img/award4a.ed6ccd4.png +0 -0
  130. package/dist/assets/img/award5.39eb7ae.png +0 -0
  131. package/dist/assets/img/bubble_default.7d5e4ab.svg +0 -20
  132. package/dist/assets/img/caret.998eb8f.svg +0 -1
  133. package/dist/assets/img/convos_empty.2353007.svg +0 -72
  134. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  135. package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
  136. package/dist/assets/img/done_gray.d7e8203.svg +0 -4
  137. package/dist/assets/img/done_green.b817fd4.svg +0 -4
  138. package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
  139. package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
  140. package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
  141. package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
  142. package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
  143. package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
  144. package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
  145. package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
  146. package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
  147. package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
  148. package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
  149. package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
  150. package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
  151. package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
  152. package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
  153. package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
  154. package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
  155. package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
  156. package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
  157. package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
  158. package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
  159. package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
  160. package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
  161. package/dist/assets/img/empty.29bed2d.svg +0 -23
  162. package/dist/assets/img/empty_1.0b98af0.svg +0 -11
  163. package/dist/assets/img/examplte_logo.f86535f.svg +0 -1
  164. package/dist/assets/img/external-link.90577cc.svg +0 -1
  165. package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
  166. package/dist/assets/img/ghn.070f8e3.svg +0 -17
  167. package/dist/assets/img/ghtk.326eac1.svg +0 -18
  168. package/dist/assets/img/image_default.be0698b.png +0 -0
  169. package/dist/assets/img/info.ebce7ea.svg +0 -1
  170. package/dist/assets/img/loader.37000a7.svg +0 -1
  171. package/dist/assets/img/loading_static.8f403ae.svg +0 -10
  172. package/dist/assets/img/main-service1.d536cc2.png +0 -0
  173. package/dist/assets/img/main-service2.9b99549.png +0 -0
  174. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  175. package/dist/assets/img/package.8d37d0f.svg +0 -5
  176. package/dist/assets/img/package_fade.763c001.svg +0 -1
  177. package/dist/assets/img/rating--average.1ea492c.svg +0 -12
  178. package/dist/assets/img/rating--great.e3d712e.svg +0 -16
  179. package/dist/assets/img/rating--poor.2938a25.svg +0 -12
  180. package/dist/assets/img/search.f9705ff.svg +0 -1
  181. package/dist/assets/img/send.6db52a9.svg +0 -3
  182. package/dist/assets/img/shop.f7dc7d8.svg +0 -1
  183. package/dist/assets/img/shop_faded.df7845a.svg +0 -1
  184. package/dist/assets/img/subiz-mono.877e9f5.svg +0 -3
  185. package/dist/assets/img/x.26fdfa3.svg +0 -5
  186. package/dist/c41606bf9d1b604e46d5.png +0 -1
  187. package/dist/ce1f7450ce6c1aacd330.png +0 -1
  188. package/dist/cf8c01e88f4770a6e3e5.png +0 -1
  189. package/dist/dfbcfeab1d5622a737e2.png +0 -1
  190. package/dist/e4893ed8c2f7b8329919.png +0 -1
  191. package/dist/ec2ab4eb4ef73d186186.png +0 -1
  192. package/dist/malicious-app.js +0 -13
  193. package/dist/screenshoot.html +0 -7
  194. package/dist/screenshoot.js +0 -5919
@@ -4,16 +4,13 @@ module.exports = function () {
4
4
  if (!module) {
5
5
  var module = {};
6
6
  }
7
-
8
7
  ;
9
8
  'use strict';
10
-
11
9
  var classCallCheck = function (instance, Constructor) {
12
10
  if (!(instance instanceof Constructor)) {
13
11
  throw new TypeError('Cannot call a class as a function');
14
12
  }
15
13
  };
16
-
17
14
  var createClass = function () {
18
15
  function defineProperties(target, props) {
19
16
  for (var i = 0; i < props.length; i++) {
@@ -24,37 +21,37 @@ module.exports = function () {
24
21
  Object.defineProperty(target, descriptor.key, descriptor);
25
22
  }
26
23
  }
27
-
28
24
  return function (Constructor, protoProps, staticProps) {
29
25
  if (protoProps) defineProperties(Constructor.prototype, protoProps);
30
26
  if (staticProps) defineProperties(Constructor, staticProps);
31
27
  return Constructor;
32
28
  };
33
29
  }();
34
-
35
30
  var index = function (_ref) {
36
31
  var DOM = _ref.DOM,
37
- animate = _ref.Animation.animate,
38
- Extension = _ref.Extension,
39
- performance = _ref.Date.performance,
40
- _ref$View = _ref.View,
41
- rooter = _ref$View.rooter,
42
- destroyer = _ref$View.destroyer,
43
- drawer = _ref$View.drawer,
44
- updater = _ref$View.updater,
45
- styler = _ref$View.styler;
32
+ animate = _ref.Animation.animate,
33
+ Extension = _ref.Extension,
34
+ performance = _ref.Date.performance,
35
+ _ref$View = _ref.View,
36
+ rooter = _ref$View.rooter,
37
+ destroyer = _ref$View.destroyer,
38
+ drawer = _ref$View.drawer,
39
+ updater = _ref$View.updater,
40
+ styler = _ref$View.styler;
46
41
  var easeOutCubic = Extension.getExtension(Extension.Type.EASING_FUNCTION, 'ease-out-cubic');
47
42
  var easeOutSine = Extension.getExtension(Extension.Type.EASING_FUNCTION, 'ease-out-sine');
48
-
49
43
  var draw = function draw(state) {
50
44
  if (state.isInitialValue()) {
51
45
  state.root.textContent = '';
46
+
52
47
  state.spacer = DOM.create('span', 'tick-flip-spacer');
53
48
  state.root.appendChild(state.spacer);
49
+
54
50
  var shadowTop = DOM.create('span', 'tick-flip-shadow-top tick-flip-shadow tick-flip-front');
55
51
  var shadowBottom = DOM.create('span', 'tick-flip-shadow-bottom tick-flip-shadow tick-flip-back');
56
52
  state.root.appendChild(shadowTop);
57
53
  state.root.appendChild(shadowBottom);
54
+
58
55
  state.shadowCard = DOM.create('span', 'tick-flip-card-shadow');
59
56
  state.root.appendChild(state.shadowCard);
60
57
  }
@@ -70,7 +67,6 @@ module.exports = function () {
70
67
  }
71
68
 
72
69
  var turningCard = state.cards[state.cards.length - 1];
73
-
74
70
  if (turningCard) {
75
71
  turningCard.waiting = false;
76
72
  turningCard.offset = performance();
@@ -93,18 +89,16 @@ module.exports = function () {
93
89
  topCard.waiting = true;
94
90
  topCard.front = state.value;
95
91
  topCard.rotate(0);
92
+
96
93
  state.root.insertBefore(topCard.root, state.root.firstChild);
97
94
  state.cards.push(topCard);
98
-
99
95
  if (!state.animating) {
100
96
  state.animating = true;
101
97
  var ease = Extension.getExtension(Extension.Type.EASING_FUNCTION, state.style.flipEasing);
102
-
103
98
  var tick = function tick() {
104
99
  var cardsToAnimate = state.cards.filter(function (card) {
105
100
  return !card.done && !card.waiting;
106
101
  });
107
-
108
102
  if (cardsToAnimate.length === 0) {
109
103
  state.animating = false;
110
104
  return;
@@ -114,50 +108,49 @@ module.exports = function () {
114
108
  if (card.offset !== null) {
115
109
  card.progress = (performance() - card.offset) / state.style.flipDuration;
116
110
  }
117
-
118
111
  if (card.progress >= 1) {
119
112
  card.progress = 1;
120
113
  card.done = true;
121
114
  }
122
-
123
115
  card.visual_progress = ease(card.progress);
124
116
  });
117
+
125
118
  var cardDistance = 0.01;
126
119
  cardsToAnimate.reverse().forEach(function (card, index) {
127
120
  var previousCard = cardsToAnimate[index - 1];
128
-
129
121
  if (previousCard && card.visual_progress <= previousCard.visual_progress) {
130
122
  card.visual_progress = previousCard.visual_progress + cardDistance;
131
123
  }
132
124
  });
133
125
  cardsToAnimate.reverse();
126
+
134
127
  state.cards.forEach(function (card, index) {
135
128
  var shadowFrontProgress = 1 - Math.abs(card.visual_progress - 0.5) * 2;
136
129
  var highlightBackProgress = 1 - (card.visual_progress - 0.5) / 0.5;
137
130
  card.shadowFront = shadowFrontProgress;
138
131
  card.highlightBack = highlightBackProgress;
132
+
139
133
  var cardAbove = state.cards[index + 1];
140
134
 
141
135
  if (cardAbove && card.visual_progress > 0.5 && card.visual_progress > 0) {
142
136
  card.shadowBack = easeOutCubic(cardAbove.visual_progress);
143
137
  }
144
138
  });
139
+
145
140
  cardsToAnimate.forEach(function (card, index) {
146
141
  var p = card.visual_progress;
147
-
148
142
  if (p > 0.5 && !card.done) {
149
143
  card.root.style.setProperty('z-index', 10 + index, 'important');
150
144
  } else {
151
145
  card.root.style.removeProperty('z-index');
152
146
  }
153
-
154
147
  card.rotate(p * -180);
155
148
  });
149
+
156
150
  var shadowProgress = 0;
157
151
  var dist = 1;
158
152
  cardsToAnimate.forEach(function (card) {
159
153
  var d = Math.abs(card.visual_progress - 0.5);
160
-
161
154
  if (d < dist) {
162
155
  dist = d;
163
156
  shadowProgress = card.visual_progress;
@@ -166,9 +159,11 @@ module.exports = function () {
166
159
  var s = shadowProgress < 0.5 ? easeOutSine(shadowProgress / 0.5) : easeOutSine((1 - shadowProgress) / 0.5);
167
160
  state.shadowCard.style.setProperty('opacity', s, 'important');
168
161
  DOM.transform(state.shadowCard, 'scaleY', s);
162
+
169
163
  state.cards.filter(function (card) {
170
164
  return card.done;
171
165
  }).slice(0, -1).forEach(function (card) {
166
+
172
167
  state.cards = state.cards.filter(function (c) {
173
168
  return c !== card;
174
169
  });
@@ -179,15 +174,14 @@ module.exports = function () {
179
174
  });
180
175
  requestAnimationFrame(tick);
181
176
  };
182
-
183
177
  tick();
184
178
  }
185
179
  };
186
-
187
180
  var FlipCard = function () {
188
181
  function FlipCard() {
189
182
  classCallCheck(this, FlipCard);
190
183
  this._root = DOM.create('span', 'tick-flip-card');
184
+
191
185
  var front = DOM.create('span', 'tick-flip-panel-front tick-flip-front tick-flip-panel');
192
186
  var textFront = DOM.create('span', 'tick-flip-panel-front-text');
193
187
  var textFrontWrapper = DOM.create('span', 'tick-flip-panel-text-wrapper');
@@ -206,7 +200,6 @@ module.exports = function () {
206
200
  back.appendChild(shadowBack);
207
201
 
208
202
  this._root.appendChild(front);
209
-
210
203
  this._root.appendChild(back);
211
204
 
212
205
  this._front = front;
@@ -214,17 +207,17 @@ module.exports = function () {
214
207
  this._shadowFront = shadowFront;
215
208
  this._shadowBack = shadowBack;
216
209
  this._highlightBack = highlightBack;
210
+
217
211
  this._textBack = textBackWrapper;
218
212
  this._textFront = textFrontWrapper;
213
+
219
214
  this._frontValue = null;
220
215
  this._backValue = null;
221
216
  }
222
-
223
217
  createClass(FlipCard, [{
224
218
  key: 'rotate',
225
219
  value: function rotate(degrees) {
226
220
  this._front.style.setProperty('transform', 'rotateX(' + degrees + 'deg)', 'important');
227
-
228
221
  this._back.style.setProperty('transform', 'rotateX(' + (-180 + degrees) + 'deg)', 'important');
229
222
  }
230
223
  }, {
@@ -288,7 +281,6 @@ module.exports = function () {
288
281
  }), drawer(state, draw), destroyer(state));
289
282
  };
290
283
  };
291
-
292
284
  module.exports = index;
293
285
  module.exports.identifier = {
294
286
  name: 'flip',
@@ -4,63 +4,44 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _index = _interopRequireDefault(require("../util/index.js"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  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; }
13
-
14
10
  const ajax = require('@subiz/ajax/src/ajax.js');
15
-
16
11
  ajax.env.XMLHttpRequest = window.XMLHttpRequest;
17
-
18
12
  const findAnswer = challenge => challenge.answer;
19
-
20
13
  function jsonifyTextPlain(param, done) {
21
14
  let req = param.request;
22
15
  if (req.content_type === 'text/plain' && req.body !== undefined) req.body = _index.default.stringify(req.body);
23
16
  done(true);
24
17
  }
25
-
26
18
  class _default {
27
19
  constructor(ApiURL, FileURL) {
28
20
  _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get('/conversations'));
29
-
30
21
  _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/conversations/${cid}/messages`));
31
-
32
22
  _defineProperty(this, "ajax", ajax);
33
-
34
23
  _defineProperty(this, "start", extraData => {
35
24
  let data = {
36
25
  starter_id: this.uid,
37
26
  starter_type: 'user',
38
- integration_id: `${this.accid}.subizv4.subikon`
27
+ touchpoint: {
28
+ channel: 'subiz',
29
+ source: 'web'
30
+ }
39
31
  };
40
-
41
32
  _index.default.each(extraData, (v, k) => {
42
33
  data[k] = v;
43
34
  });
44
-
45
35
  return this.apireq.post('/conversations', data);
46
36
  });
47
-
48
37
  _defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));
49
-
50
38
  _defineProperty(this, "createPostback", (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p));
51
-
52
39
  _defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/receive`));
53
-
54
40
  _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/seen`));
55
-
56
41
  _defineProperty(this, "getConversation", cid => this.apireq.get(`/conversations/${cid}`));
57
-
58
42
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
59
-
60
43
  _defineProperty(this, "sendEvent", data => this.apireq.post(`/users/${this.uid}/events`, data));
61
-
62
44
  _defineProperty(this, "sendTyping", cid => this.apireq.post(`/conversations/${cid}/typing`));
63
-
64
45
  _defineProperty(this, "sendPresence", (device, is_focused, productid, source_id, sku) => this.sendEvent({
65
46
  by: {
66
47
  id: this.uid,
@@ -77,7 +58,6 @@ class _default {
77
58
  }
78
59
  }
79
60
  }));
80
-
81
61
  _defineProperty(this, "uploadToS3", async file => {
82
62
  let {
83
63
  body: signed,
@@ -99,6 +79,7 @@ class _default {
99
79
  if (error) return {
100
80
  error
101
81
  };
82
+
102
83
  let body;
103
84
  ({
104
85
  body,
@@ -113,46 +94,41 @@ class _default {
113
94
  url: this.FileURL + body.url
114
95
  };
115
96
  });
116
-
117
97
  _defineProperty(this, "getChallenge", accid => this.apireq.post(`/accounts/${accid}/scrypt-challenges`));
118
-
119
98
  _defineProperty(this, "time", _ => this.apireq.get('/time'));
120
-
121
99
  _defineProperty(this, "updateUser", data => this.apireq.post(`/users/${this.uid}`, data));
122
-
123
100
  _defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
124
-
125
101
  _defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
126
-
127
102
  _defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
128
-
129
103
  _defineProperty(this, "sendImpression", impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression));
130
-
131
104
  _defineProperty(this, "sendConversion", conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion));
132
-
133
105
  _defineProperty(this, "lookupOrder", key => ajax.setBaseUrl(this.ApiURL).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').addQuery('x-signed-key', key).get(`/orders/123`));
134
-
135
106
  _defineProperty(this, "getOrder", id => this.apireq.get(`/accounts/${this.accid}/orders/` + id));
136
-
137
107
  _defineProperty(this, "updateOrder", order => this.apireq.post(`/accounts/${this.accid}/orders/` + order.id, order));
138
-
139
108
  _defineProperty(this, "fetchShippingAddresses", () => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`));
140
-
141
109
  _defineProperty(this, "createShippingAddress", addr => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`, addr));
142
-
143
110
  _defineProperty(this, "list_provinces", () => this.apireq.get(`/accounts/${this.accid}/provinces`));
144
-
145
111
  _defineProperty(this, "list_districts", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/districts`));
146
-
147
112
  _defineProperty(this, "list_wards", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/wards`));
148
-
149
113
  _defineProperty(this, "suggest_address", keyword => this.apireq.setQuery({
150
114
  keyword: keyword
151
115
  }).get(`/accounts/${this.accid}/addresses`));
152
-
116
+ this.refreshLock = new _index.default.Mutex();
153
117
  this.FileURL = FileURL;
154
118
  this.ApiURL = ApiURL;
155
119
  this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').beforeHook((param, done) => {
120
+ if (this.token_generator) {
121
+ let user_id = this.profile_id;
122
+ this.token_generator().then(token => {
123
+ if (user_id != this.profile_id) return done(true);
124
+
125
+ if (!token) return done(false);
126
+ if (token == 'error') return done(false);
127
+ param.request = param.request.addQuery('x-access-token', token);
128
+ return done(true);
129
+ });
130
+ return;
131
+ }
156
132
  if (this.mask) param.request = param.request.addQuery('x-user-mask', this.mask);
157
133
  return done(true);
158
134
  });
@@ -161,13 +137,97 @@ class _default {
161
137
  setAgentId(agid) {
162
138
  this.agentid = agid;
163
139
  }
164
-
165
140
  setAuth(obj) {
166
141
  this.accid = obj.accid;
167
142
  this.mask = obj.mask;
168
143
  this.uid = obj.uid;
169
144
  }
145
+ async setTokenGenerator(accid, uid, tokenGenerator) {
146
+ this.tokensession = this.tokensession || 0;
147
+ this.tokensession++;
148
+ let tokensession = this.tokensession;
149
+ if (!accid || !_index.default.startsWith(accid, 'ac')) return {
150
+ error: 'invalid_account_id'
151
+ };
152
+ if (!uid) return {
153
+ error: 'invalid_user_id'
154
+ };
155
+ if (typeof tokenGenerator !== 'function') return {
156
+ error: 'invalid_token_generator'
157
+ };
158
+ this.accid = accid;
159
+ this.profile_id = uid;
160
+ this.token_generator = async force => {
161
+ await this.refreshLock.lock();
162
+ if (tokensession != this.tokensession) {
163
+ this.refreshLock.unlock();
164
+ return;
165
+ }
166
+
167
+ let age = (_index.default.Date.now() - (this.last_token_at || 0)) / 1000;
170
168
 
169
+ if (!force && this.last_token && age < 1800) {
170
+ this.refreshLock.unlock();
171
+ return this.last_token;
172
+ }
173
+ if (!force && this.last_token && age < 3000) {
174
+ if (this.token_generator) setTimeout(async () => {
175
+ let token, err;
176
+ try {
177
+ token = await tokenGenerator(uid);
178
+ } catch (e) {
179
+ err = e;
180
+ }
181
+ if (tokensession != this.tokensession) {
182
+ this.refreshLock.unlock();
183
+ return;
184
+ }
185
+
186
+ if (err) this.last_token = 'error';else this.last_token = token;
187
+ this.last_token_at = _index.default.Date.now();
188
+ this.refreshLock.unlock();
189
+ });
190
+ return this.last_token;
191
+ }
192
+
193
+ let token;
194
+ let err;
195
+ try {
196
+ token = await tokenGenerator(uid);
197
+ } catch (e) {
198
+ err = e;
199
+ }
200
+ if (tokensession != this.tokensession) {
201
+ this.refreshLock.unlock();
202
+ return;
203
+ }
204
+
205
+ if (err) this.last_token = 'error';else this.last_token = token;
206
+ this.last_token_at = _index.default.Date.now();
207
+ this.refreshLock.unlock();
208
+ return this.last_token;
209
+ };
210
+ let outuser;
211
+ for (let i = 0; true; i++) {
212
+ await this.token_generator(true);
213
+ if (tokensession != this.tokensession) break;
214
+ outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-access-token', this.last_token).setParser('json').get(`/accounts/${accid}/users/${uid}`);
215
+ if (!_index.default.get(outuser, 'body.id')) {
216
+ let sleeptime = Math.min(2000 + i * 100, 120000);
217
+ await _index.default.sleep(sleeptime);
218
+ continue;
219
+ }
220
+ break;
221
+ }
222
+ if (outuser.error) {
223
+ if (_index.default.get(outuser.body.code)) return {
224
+ error: outuser.body.code
225
+ };
226
+ return outuser;
227
+ }
228
+ this.uid = outuser.body.id;
229
+ return outuser.body;
230
+ }
171
231
  sendContentView(device, pageUrl, pageTitle, id, source_id, sku) {
172
232
  if (!id) id = undefined;
173
233
  if (!source_id) source_id = undefined;
@@ -189,25 +249,6 @@ class _default {
189
249
  }
190
250
  });
191
251
  }
192
-
193
- async createAgentUser(agenttoken) {
194
- for (var i = 0; i < 10; i++) {
195
- let {
196
- body,
197
- error
198
- } = await ajax.setBaseUrl(this.ApiURL).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').addQuery('x-access-token', agenttoken).post(`/agent-users`);
199
-
200
- if (error) {
201
- await _index.default.sleep(1000);
202
- continue;
203
- }
204
-
205
- let userid = body ? body.id || '' : '';
206
- if (!userid) return '';
207
- return body.account_id + '@' + userid;
208
- }
209
- }
210
-
211
252
  async createUser(accid) {
212
253
  for (var i = 0; i < 10; i++) {
213
254
  const {
@@ -222,16 +263,12 @@ class _default {
222
263
  body: user,
223
264
  error
224
265
  } = await this.apireq.post(`/accounts/${accid}/scrypt-challenges/users`, data);
225
-
226
266
  if (error) {
227
267
  await _index.default.sleep(1000);
228
268
  continue;
229
269
  }
230
-
231
270
  return user;
232
271
  }
233
272
  }
234
-
235
273
  }
236
-
237
274
  exports.default = _default;
@@ -4,29 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _index = _interopRequireDefault(require("../util/index.js"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  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; }
13
-
14
10
  const ajax = require('@subiz/ajax/src/ajax.js');
15
-
16
11
  ajax.env.XMLHttpRequest = window.XMLHttpRequest;
17
-
18
12
  const findAnswer = challenge => challenge.answer;
19
-
20
13
  function jsonifyTextPlain(param, done) {
21
14
  let req = param.request;
22
15
  if (req.content_type === 'text/plain' && req.body !== undefined) req.body = _index.default.stringify(req.body);
23
16
  done(true);
24
17
  }
25
-
26
18
  const OK200 = Promise.resolve({
27
19
  code: 200
28
20
  });
29
-
30
21
  class _default {
31
22
  constructor(ApiURL, FileURL) {
32
23
  _defineProperty(this, "listConversations", _ => {
@@ -39,7 +30,6 @@ class _default {
39
30
  code: 200
40
31
  });
41
32
  });
42
-
43
33
  _defineProperty(this, "listMessages", (cid, limit, start_id) => {
44
34
  let messages = makeFakeMessages(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid);
45
35
  return Promise.resolve({
@@ -47,68 +37,43 @@ class _default {
47
37
  code: 200
48
38
  });
49
39
  });
50
-
51
40
  _defineProperty(this, "ajax", ajax);
52
-
53
41
  _defineProperty(this, "start", extraData => OK200);
54
-
55
42
  _defineProperty(this, "sendConvoEvent", (cid, ev) => OK200);
56
-
57
43
  _defineProperty(this, "createPostback", (cid, p) => OK200);
58
-
59
44
  _defineProperty(this, "markAsReceived", (cid, messageId) => OK200);
60
-
61
45
  _defineProperty(this, "markAsSeen", (cid, messageId) => OK200);
62
-
63
46
  _defineProperty(this, "getConversation", cid => Promise.resolve({
64
47
  body: makeFakeConvo(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid),
65
48
  code: 200
66
49
  }));
67
-
68
50
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
69
-
70
51
  _defineProperty(this, "sendEvent", data => OK200);
71
-
72
52
  _defineProperty(this, "sendTyping", cid => OK200);
73
-
74
53
  _defineProperty(this, "sendPresence", data => OK200);
75
-
76
54
  _defineProperty(this, "sendContent", data => OK200);
77
-
78
55
  _defineProperty(this, "uploadToS3", async file => OK200);
79
-
80
56
  _defineProperty(this, "getChallenge", accid => OK200);
81
-
82
57
  _defineProperty(this, "createUser", accid => Promise.resolve({
83
58
  account_id: accid,
84
59
  id: 'usqzgtgfake',
85
60
  mask: 'fakemask'
86
61
  }));
87
-
88
- _defineProperty(this, "createAgentUser", agenttoken => Promise.resolve('fakemask'));
89
-
90
62
  _defineProperty(this, "time", _ => Promise.resolve({
91
63
  code: 200,
92
64
  body: new _index.default.Date().toISOString()
93
65
  }));
94
-
95
66
  _defineProperty(this, "updateUser", data => OK200);
96
-
97
67
  _defineProperty(this, "getUser", _ => Promise.resolve({
98
68
  code: 200,
99
69
  body: {
100
70
  id: '-'
101
71
  }
102
72
  }));
103
-
104
73
  _defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
105
-
106
74
  _defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
107
-
108
75
  _defineProperty(this, "sendImpression", impression => OK200);
109
-
110
76
  _defineProperty(this, "sendConversion", conversion => OK200);
111
-
112
77
  this.FileURL = FileURL;
113
78
  this.apireq = ajax.setBaseUrl(ApiURL).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json');
114
79
  }
@@ -116,17 +81,17 @@ class _default {
116
81
  setAgentId(agid) {
117
82
  this.agentid = agid;
118
83
  }
119
-
84
+ setTokenGenerator(accid, uid, tokenGenerator) {
85
+ this.accid = accid;
86
+ }
120
87
  setAuth(obj) {
121
88
  this.accid = obj.accid;
122
89
  this.mask = obj.mask;
123
90
  this.uid = obj.uid;
124
91
  }
125
-
126
92
  }
127
93
 
128
94
  exports.default = _default;
129
-
130
95
  function makeFakeConvo(accid, convoid, userid, agentid) {
131
96
  let inteid = accid + '.subizv4.subikon';
132
97
  return {
@@ -192,7 +157,6 @@ function makeFakeConvo(accid, convoid, userid, agentid) {
192
157
  source: 'https://subiz.com.vn/'
193
158
  };
194
159
  }
195
-
196
160
  function makeFakeMessages(accid, convoid, userid, agentid) {
197
161
  let inteid = accid + '.subizv4.subikon';
198
162
  return [{
@@ -4,16 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  class _default {
9
8
  onEvent() {}
10
-
11
9
  onInterrupted() {}
12
-
13
10
  subscribe() {}
14
-
15
11
  stop() {}
16
-
17
12
  }
18
-
19
13
  exports.default = _default;