@subiz/widget-v4 4.0.51 → 4.0.56

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 (56) hide show
  1. package/compiled_src/chatbox/OrderAttachments.js +4 -8
  2. package/compiled_src/chatbox/ProductAttachments.js +4 -4
  3. package/compiled_src/notif/notif.js +7 -3
  4. package/compiled_src/plugin.js +1 -1
  5. package/compiled_src/store/api.js +1 -0
  6. package/compiled_src/store/store.js +0 -150
  7. package/compiled_src/util/campaign.js +6 -1
  8. package/dist/{17d02a15859.178.js → 17d7f3360b5.178.js} +1 -1
  9. package/dist/{17d02a15859.213.js → 17d7f3360b5.213.js} +0 -0
  10. package/dist/{17d02a15859.362.js → 17d7f3360b5.362.js} +1 -1
  11. package/dist/17d7f3360b5.441.js +1 -0
  12. package/dist/17d7f3360b5.605.js +1 -0
  13. package/dist/{17d02a15859.619.js → 17d7f3360b5.619.js} +1 -1
  14. package/dist/{17d02a15859.678.js → 17d7f3360b5.678.js} +0 -0
  15. package/dist/17d7f3360b5.74.js +1 -0
  16. package/dist/{17d02a15859.782.js → 17d7f3360b5.782.js} +1 -1
  17. package/dist/17d7f3360b5.app.js +1 -0
  18. package/dist/{17d02a15859.index.html → 17d7f3360b5.index.html} +1 -1
  19. package/dist/{17d02a15859.library.html → 17d7f3360b5.library.html} +1 -1
  20. package/dist/17d7f3360b5.library.js +1 -0
  21. package/dist/{17d02a15859.preview.html → 17d7f3360b5.preview.html} +1 -1
  22. package/dist/17d7f3360b5.preview.js +1 -0
  23. package/dist/17d7f3360b5.screenshoot.js +1 -0
  24. package/dist/17d7f338b23.178.js +406 -0
  25. package/dist/17d7f338b23.213.js +3223 -0
  26. package/dist/17d7f338b23.362.js +107 -0
  27. package/dist/17d7f338b23.441.js +2706 -0
  28. package/dist/17d7f338b23.605.js +391 -0
  29. package/dist/17d7f338b23.619.js +777 -0
  30. package/dist/17d7f338b23.678.js +107 -0
  31. package/dist/17d7f338b23.74.js +4732 -0
  32. package/dist/17d7f338b23.782.js +107 -0
  33. package/dist/17d7f338b23.screenshoot.js +5747 -0
  34. package/dist/HASH +1 -1
  35. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  36. package/dist/screenshoot.html +7 -0
  37. package/package.json +11 -11
  38. package/screenshoot.html +15 -0
  39. package/screenshoot.js +59 -0
  40. package/src/chatbox/OrderAttachments.js +4 -9
  41. package/src/chatbox/ProductAttachments.js +4 -4
  42. package/src/notif/notif.js +37 -28
  43. package/src/plugin.js +12 -5
  44. package/src/store/api.js +2 -5
  45. package/src/store/store.js +0 -137
  46. package/src/util/campaign.js +14 -11
  47. package/take.js +36 -0
  48. package/webpack.dev.js +7 -0
  49. package/webpack.prod.js +12 -2
  50. package/webpack.screenshoot.js +28 -0
  51. package/dist/17d02a15859.441.js +0 -1
  52. package/dist/17d02a15859.605.js +0 -1
  53. package/dist/17d02a15859.712.js +0 -1
  54. package/dist/17d02a15859.app.js +0 -1
  55. package/dist/17d02a15859.library.js +0 -1
  56. package/dist/17d02a15859.preview.js +0 -1
package/dist/HASH CHANGED
@@ -1 +1 @@
1
- 17d02a15859
1
+ 17d7f338b23
@@ -0,0 +1,7 @@
1
+ <html><head><meta name="viewport" content="width=device-width,intial-scale=1"/><style>/* make the environment look like widget environment */
2
+ #sbz-pop * {
3
+ all: unset;
4
+ }
5
+ body {
6
+ background: #ddd;
7
+ }</style></head><body><script defer="defer" src="./17d7f338b23.screenshoot.js"></script></body></html>
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.0.51",
3
+ "version": "4.0.56",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
7
- "build": "npx webpack --config webpack.prod.js",
7
+ "build": "rm -rf dist && npx webpack --config webpack.prod.js && npx webpack --config webpack.screenshoot.js",
8
8
  "report": "npx webpack --config webpack.report.js",
9
9
  "lib": "rm -rf compiled_src && npx babel --out-dir=compiled_src src"
10
10
  },
11
11
  "dependencies": {
12
- "@babel/core": "^7.16.0",
13
- "@googlemaps/js-api-loader": "^1.11.4",
12
+ "@googlemaps/js-api-loader": "^1.12.11",
14
13
  "@subiz/ajax": "^3.0.12",
15
14
  "@subiz/flow": "^1.0.9",
16
15
  "@subiz/storage": "0.0.8",
17
16
  "@subiz/wsclient": "^3.1.7",
18
- "babel-loader": "^8.2.3",
19
17
  "cookie_js": "1.4.2",
20
- "core-js": "^3.19.1",
18
+ "core-js": "^3.19.2",
21
19
  "css-loader": "^5.2.6",
22
20
  "file-loader": "^6.2.0",
23
21
  "less": "^4.1.2",
24
22
  "less-loader": "^10.2.0",
25
- "marked": "^4.0.4",
26
- "preact": "^10.6.0"
23
+ "marked": "^4.0.6",
24
+ "preact": "^10.6.2"
27
25
  },
28
26
  "devDependencies": {
27
+ "babel-loader": "^8.2.3",
28
+ "@babel/core": "^7.16.0",
29
29
  "@babel/cli": "^7.16.0",
30
30
  "@babel/plugin-proposal-class-properties": "^7.16.0",
31
31
  "@babel/plugin-transform-react-jsx": "^7.16.0",
32
32
  "@babel/preset-env": "^7.16.4",
33
33
  "babel-plugin-syntax-jsx": "^6.18.0",
34
34
  "html-webpack-plugin": "^5.5.0",
35
- "prettier": "^2.4.1",
36
- "webpack": "^5.64.3",
35
+ "puppeteer": "^12.0.1",
36
+ "webpack": "^5.64.4",
37
37
  "webpack-bundle-analyzer": "^4.5.0",
38
38
  "webpack-cli": "^4.9.1",
39
- "webpack-dev-server": "^4.5.0"
39
+ "webpack-dev-server": "^4.6.0"
40
40
  }
41
41
  }
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <head>
3
+ <meta name="viewport" content="width=device-width, intial-scale=1.0" />
4
+ <style>
5
+ /* make the environment look like widget environment */
6
+ #sbz-pop * {
7
+ all: unset;
8
+ }
9
+ body {
10
+ background: #ddd;
11
+ }
12
+ </style>
13
+ </head>
14
+ <body></body>
15
+ </html>
package/screenshoot.js ADDED
@@ -0,0 +1,59 @@
1
+ import Widget from './src/lib.js'
2
+
3
+ let accid = 'acqsulrowbxiugvginhw'
4
+ let widget = new Widget(
5
+ 'https://api.subiz.com.vn/4.0/',
6
+ 'https://file-subiz.com/',
7
+ 'https://rt-0.subiz.com.vn/',
8
+ true,
9
+ true,
10
+ )
11
+
12
+ function main() {
13
+ var $div = document.createElement('div')
14
+ document.body.appendChild($div)
15
+ let hash = document.location.hash.substr(1)
16
+
17
+ let plugin = JSON.parse(decodeURIComponent(atob(hash)))
18
+ plugin.triggers = [{type: 'after_pageview', after_pageview_sec: 0, enabled: true}]
19
+ if (plugin.popup) plugin.popup.overlay = false
20
+ plugin._dont_close = true
21
+ plugin._page_index = 0
22
+ plugin.conditions = []
23
+
24
+ if (plugin.type === 'notification') {
25
+ if (!plugin.notification) return console.log('EMPTY PLUGIN')
26
+
27
+ if (!plugin.notification.profiles || plugin.notification.profiles.length == 0) {
28
+ plugin.notification.profiles = [
29
+ {
30
+ address: 'Hàng Da, Hoàn Kiếm, Hà Nội',
31
+ age: 26,
32
+ avatar_url: 'https://vcdn.subiz-cdn.com/file/firegedmbhqftirxacho-avatar3.jpeg',
33
+ country: 'VN',
34
+ email: 'linhxx@gmail.com',
35
+ gender: 'Female',
36
+ fullname: 'Nguyễn Linh',
37
+ phone: '0823588xxx',
38
+ },
39
+ {
40
+ address: 'Lũng Cú, Đồng Văn, Hà Giang',
41
+ age: 23,
42
+ avatar_url: 'https://vcdn.subiz-cdn.com/file/fiqvzdstytzxlbsguaci-ellipse_2319.png',
43
+ country: 'VN',
44
+ email: 'lannhoanggxx@gmail.com',
45
+ gender: 'Female',
46
+ name: 'Nguyễn Hoàng Lan',
47
+ phone: '0326789xxx',
48
+ },
49
+ ]
50
+ }
51
+ }
52
+
53
+ plugin.account_id = accid
54
+ widget._overridePlugin([plugin])
55
+ // widget._overrideDeviceType('mobile')
56
+ widget.setAccount(accid, $div)
57
+ }
58
+
59
+ main()
@@ -33,7 +33,6 @@ export default class ProductAttachments extends Com {
33
33
  {sb.map(order.items, (item) => {
34
34
  let product = item.product || {}
35
35
 
36
- let price = this.props.store.getPrice(product, 'price', order.currency)
37
36
  return (
38
37
  <div class='order_attachment__product'>
39
38
  <img
@@ -41,12 +40,10 @@ export default class ProductAttachments extends Com {
41
40
  src={(sb.get(product, 'images.0'), require('../../assets/img/default.jpg'))}
42
41
  />
43
42
  <div style='overflow: hidden !important;'>
44
- <div class='order_attachment__product_name'>{this.props.t.i18n(product.name)}</div>
43
+ <div class='order_attachment__product_name'>{product.name}</div>
44
+ <div class='order_attachment__product_desc'>{product.description || product.long_description}</div>
45
45
  <div class='order_attachment__product_desc'>
46
- {this.props.t.i18n(product.short_description) || this.props.t.i18n(product.description)}
47
- </div>
48
- <div class='order_attachment__product_desc'>
49
- {this.props.t('qty')} {item.quantity}&nbsp;·&nbsp;{sb.formatCurrency(price)}
46
+ {this.props.t('qty')} {item.quantity}&nbsp;·&nbsp;{sb.formatCurrency(product.price)}
50
47
  </div>
51
48
  </div>
52
49
  </div>
@@ -56,13 +53,11 @@ export default class ProductAttachments extends Com {
56
53
  )
57
54
  }
58
55
 
59
- let {total} = this.props.store.getOrderTotal(order)
60
-
61
56
  let $total = (
62
57
  <div class='order_attachment__footer'>
63
58
  <div>{this.props.t('total')}</div>{' '}
64
59
  <div>
65
- <b>{sb.formatCurrency(total)}</b>
60
+ <b>{sb.formatCurrency(order.total)}</b>
66
61
  </div>
67
62
  </div>
68
63
  )
@@ -35,11 +35,11 @@ export default class ProductAttachments extends Com {
35
35
 
36
36
  let $title = (
37
37
  <a href={url} class='product_attachment__title' target='_blank'>
38
- {this.props.t.i18n(product.name)}
38
+ {product.name}
39
39
  </a>
40
40
  )
41
41
  let $subtitle = null
42
- let desc = this.props.t.i18n(product.short_description) || this.props.t.i18n(product.description)
42
+ let desc = product.description || product.long_description
43
43
  if (desc) $subtitle = <div class='product_attachment__subtitle'>{desc}</div>
44
44
 
45
45
  let $price = null
@@ -53,8 +53,8 @@ export default class ProductAttachments extends Com {
53
53
  return (
54
54
  <div class={'product_attachment product_attachment__' + byType}>
55
55
  <div>
56
- <a href={this.props.store.replaceFileUrl(product.images[0])} target='_blank'>
57
- <img class='product_attachment__img' src={this.props.store.replaceFileUrl(product.images[0])} />
56
+ <a href={this.props.store.replaceFileUrl(product.image)} target='_blank'>
57
+ <img class='product_attachment__img' src={this.props.store.replaceFileUrl(product.image)} />
58
58
  </a>
59
59
  </div>
60
60
  {$title}
@@ -68,17 +68,17 @@ export default class Notif extends Com {
68
68
 
69
69
  renderCloseButton() {
70
70
  return (
71
- <div class="btn_close" onClick={e => this.onCloseButtonClick(e)}>
71
+ <div class='btn_close' onClick={(e) => this.onCloseButtonClick(e)}>
72
72
  <svg
73
- class="btn_close__icon"
74
- xmlns="http://www.w3.org/2000/svg"
75
- width="24"
76
- height="24"
77
- viewBox="0 0 24 24"
78
- stroke-linecap="round"
79
- stroke-linejoin="round">
80
- <line x1="18" y1="6" x2="6" y2="18" style="stroke-width: 3 !important;"></line>
81
- <line x1="6" y1="6" x2="18" y2="18" style="stroke-width: 3 !important;"></line>
73
+ class='btn_close__icon'
74
+ xmlns='http://www.w3.org/2000/svg'
75
+ width='24'
76
+ height='24'
77
+ viewBox='0 0 24 24'
78
+ stroke-linecap='round'
79
+ stroke-linejoin='round'>
80
+ <line x1='18' y1='6' x2='6' y2='18' style='stroke-width: 3 !important;'></line>
81
+ <line x1='6' y1='6' x2='18' y2='18' style='stroke-width: 3 !important;'></line>
82
82
  </svg>
83
83
  </div>
84
84
  )
@@ -100,13 +100,13 @@ export default class Notif extends Com {
100
100
  this.setState({closeAnimation: false})
101
101
  let timestamp = this.randomTimestampt()
102
102
  let profiles = sb.get(this.props, 'plugin.notification.profiles', [])
103
- let user = profiles[Math.floor(Math.random() * sb.size(profiles))]
103
+ let user = profiles[Math.floor(Math.random() * sb.size(profiles))] || {}
104
104
  // make sure image loaded
105
105
  if (user.avatar_url && user.avatar_url.startsWith('http')) {
106
106
  await sb.preloadImg(user.avatar_url)
107
107
  }
108
108
 
109
- sb.map(sb.get(this.props.plugin, 'notification.custom_avatar_urls'), url => {
109
+ sb.map(sb.get(this.props.plugin, 'notification.custom_avatar_urls'), (url) => {
110
110
  profiles.push({
111
111
  type: 'person',
112
112
  fullname: randomName(),
@@ -119,7 +119,12 @@ export default class Notif extends Com {
119
119
  })
120
120
 
121
121
  let i18n_messages = sb.get(this.props, 'plugin.notification.i18n_message_quill_deltas', [])
122
+
122
123
  let i18n_message = i18n_messages[Math.floor(Math.random() * sb.size(i18n_messages))]
124
+
125
+ let fallbackmsgs = sb.get(this.props, 'plugin.notification.message_quill_deltas', [])
126
+ let fallbackmessage = fallbackmsgs[Math.floor(Math.random() * sb.size(fallbackmsgs))]
127
+
123
128
  let i18n_title = sb.get(this.props, 'plugin.notification.i18n_title_quill_delta')
124
129
 
125
130
  return this.setState({
@@ -127,8 +132,8 @@ export default class Notif extends Com {
127
132
  last_show: sb.Date.now(),
128
133
  timestamp: timestamp,
129
134
  user: user,
130
- title: this.props.t.i18n(i18n_title),
131
- message: this.props.t.i18n(i18n_message),
135
+ title: this.props.t.i18n(i18n_title) || sb.get(this.props, 'plugin.notification.title_quill_delta'),
136
+ message: this.props.t.i18n(i18n_message) || fallbackmessage,
132
137
  })
133
138
  }
134
139
  this.setState({closeAnimation: true})
@@ -140,7 +145,7 @@ export default class Notif extends Com {
140
145
  async refreshCSS() {
141
146
  // make sure you are still alive
142
147
  let plugins = this.props.store.matchPlugin()
143
- let found = sb.find(plugins, plugin => plugin.id === this.props.plugin.id)
148
+ let found = sb.find(plugins, (plugin) => plugin.id === this.props.plugin.id)
144
149
  if (!found) return
145
150
  let css = (await notifCSS).default.default.toString()
146
151
  // var outcss = sb.replaceCssVariablePlugin(css, this.props.plugin.popup)
@@ -191,7 +196,7 @@ export default class Notif extends Com {
191
196
  renderTextFromQuillDelta(quilldelta, profile) {
192
197
  let qd = sb.parseJSON(quilldelta)
193
198
  if (!qd || !qd.ops) return null
194
- return sb.map(qd.ops, op => {
199
+ return sb.map(qd.ops, (op) => {
195
200
  let out = null
196
201
  if (!op.insert) return null
197
202
 
@@ -215,7 +220,6 @@ export default class Notif extends Com {
215
220
  if (!this.state.imageReady) return null
216
221
  if (this.state.close) return null
217
222
  if (!this.state.message) return null
218
-
219
223
  let notif = sb.get(this.props.plugin, 'notification', {})
220
224
  if (!notif) return null
221
225
  let animation = ''
@@ -244,24 +248,29 @@ export default class Notif extends Com {
244
248
  return (
245
249
  <div
246
250
  class={animation + ' notif' + ' notif__' + pos}
247
- onClick={e => this.onClick(e)}
248
- onmouseover={e => this.setOver(true)}
251
+ onClick={(e) => this.onClick(e)}
252
+ onmouseover={(e) => this.setOver(true)}
249
253
  style={st}
250
- onmouseleave={e => this.setOver(false)}>
251
- <div style="position: relative !important; display: flex !important; align-items: center !important;">
252
- <img alt="notification background" class="notif_bg" src={notif.background_url} style={sb.js2css(notif.background_style)} />
254
+ onmouseleave={(e) => this.setOver(false)}>
255
+ <div style='position: relative !important; display: flex !important; align-items: center !important;'>
256
+ <img
257
+ alt='notification background'
258
+ class='notif_bg'
259
+ src={notif.background_url}
260
+ style={sb.js2css(notif.background_style)}
261
+ />
253
262
  {this.renderCloseButton()}
254
- <div class="notif_avatar" style={sb.js2css(notif.avatar_style)}>
255
- <img alt="notification avatar" class="notif_avatar__img" src={user.avatar_url} />
263
+ <div class='notif_avatar' style={sb.js2css(notif.avatar_style)}>
264
+ <img alt='notification avatar' class='notif_avatar__img' src={user.avatar_url} />
256
265
  </div>
257
- <div class="notif_body">
258
- <div class="notif_title" style={sb.js2css(notif.title_style)}>
266
+ <div class='notif_body'>
267
+ <div class='notif_title' style={sb.js2css(notif.title_style)}>
259
268
  {this.renderTextFromQuillDelta(this.state.title, user)}
260
269
  </div>
261
- <div class="notif_message" style={sb.js2css(notif.message_style)}>
270
+ <div class='notif_message' style={sb.js2css(notif.message_style)}>
262
271
  {this.renderTextFromQuillDelta(this.state.message, user)}
263
272
  </div>
264
- <div class="notif_time" style={sb.js2css(notif.subtext_style)}>
273
+ <div class='notif_time' style={sb.js2css(notif.subtext_style)}>
265
274
  {this.state.timestamp}
266
275
  </div>
267
276
  </div>
package/src/plugin.js CHANGED
@@ -29,10 +29,9 @@ function Plugin(plugin, store, $container, lib) {
29
29
 
30
30
  this.getState = () => state
31
31
 
32
- var run = async function () {
32
+ var run = async function() {
33
33
  if (_destroy) return
34
34
  if (state !== 'hold') return
35
-
36
35
  // dont run converted plugin twice
37
36
  if (plugin.type === 'popup' && store.isConverted(plugin.id)) return
38
37
 
@@ -372,11 +371,19 @@ function downloadLanguage(store, locale, force) {
372
371
  const getLocale = (plugin, loc) => {
373
372
  if (!loc) loc = ''
374
373
  let found = sb.find(plugin.locales, (l) => l.toLowerCase().trim() === loc.toLowerCase().trim())
375
- if (found) return loc
374
+ if (found) return found
376
375
 
377
376
  found = sb.find(plugin.locales, (l) => {
378
- l = l.replace('-', '_').split('_')[0].trim().toLowerCase()
379
- let compareloc = loc.replace('-', '_').split('_')[0].trim().toLowerCase()
377
+ l = l
378
+ .replace('-', '_')
379
+ .split('_')[0]
380
+ .trim()
381
+ .toLowerCase()
382
+ let compareloc = loc
383
+ .replace('-', '_')
384
+ .split('_')[0]
385
+ .trim()
386
+ .toLowerCase()
380
387
  return l == compareloc
381
388
  })
382
389
  if (found) return found
package/src/store/api.js CHANGED
@@ -47,10 +47,7 @@ export default class {
47
47
  .get('/conversations')
48
48
 
49
49
  listMessages = (cid, limit, start_id) =>
50
- this.apireq
51
- .addQuery('limit', limit)
52
- .addQuery('start_id', start_id)
53
- .get(`/conversations/${cid}/messages`)
50
+ this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/conversations/${cid}/messages`)
54
51
 
55
52
  ajax = ajax
56
53
 
@@ -85,7 +82,7 @@ export default class {
85
82
  return this.sendEvent({
86
83
  by: {id: this.uid, device: device},
87
84
  type: 'content_viewed',
88
- data: {product: {url: pageUrl, title: pageTitle}},
85
+ data: {product: {url: pageUrl, name: pageTitle, title: pageTitle}},
89
86
  })
90
87
  }
91
88
 
@@ -930,143 +930,6 @@ export default class Store {
930
930
  setTimeout(() => this.loopTime(), 60000)
931
931
  }
932
932
 
933
- getPrice(obj, field, currency) {
934
- if (!obj) return 0
935
- if (!currency) return obj[field] || 0
936
- let defcur = sb.get(this.matchAccount(), 'currency')
937
- if (currency != defcur) return sb.get(obj, [field + '_locale', currency], 0)
938
- return obj[field] || 0
939
- }
940
-
941
- getOrderTotal(order) {
942
- let subtotal = 0
943
- sb.map(order.items, (item) => {
944
- if (!item.product) return 0
945
- let price = this.getPrice(item.product, 'price', order.currency) * item.quantity
946
-
947
- if (item.discount_type) {
948
- if (item.discount_type == 'percentage') {
949
- if (item.discount_before_tax && item.discount_percentage > 0) {
950
- price = price * (1 - item.discount_percentage / 10000)
951
- }
952
- } else if (item.discount_type == 'amount') {
953
- let computed_discount = this.getPrice(item, 'discount', order.currency)
954
- if (item.discount_before_tax && computed_discount > 0) {
955
- price = price - computed_discount
956
- if (price <= 0) price = 0
957
- }
958
- }
959
- }
960
- subtotal += price
961
- })
962
-
963
- let computed_discount = 0
964
- // add specific item discount after tax to computed_discount
965
- sb.map(order.items, (item) => {
966
- if (!item.discount_type) return
967
- if (!item.product) return 0
968
- let price = this.getPrice(item.product, 'price', order.currency) * item.quantity
969
-
970
- let tax = item.product.tax
971
- let taxprice = 0
972
- if (tax && tax.id) taxprice = (price * tax.percentage) / 10000
973
-
974
- if (item.discount_type == 'percentage' && !item.discount_before_tax && item.discount_percentage > 0) {
975
- computed_discount += ((price + taxprice) * item.discount_percentage) / 10000
976
- } else if (item.discount_type == 'amount') {
977
- let itemdiscount = this.getPrice(item, 'discount', order.currency)
978
- if (!item.discount_before_tax && itemdiscount > 0) {
979
- // CAUTION: easy to miss condition
980
- if (itemdiscount > price + taxprice) itemdiscount = price + taxprice
981
- computed_discount += itemdiscount
982
- }
983
- }
984
- })
985
-
986
- // TAX
987
- let totaltax = 0
988
- let taxM = {}
989
- sb.map(order.items, (item, i) => {
990
- if (!item.product) return
991
- let tax = item.product.tax
992
- if (!tax) return
993
- if (!tax.id) return
994
- let price = this.getPrice(item.product, 'price', order.currency) * item.quantity
995
-
996
- if (item.discount_type) {
997
- if (item.discount_type == 'percentage') {
998
- if (item.discount_before_tax && item.discount_percentage > 0) {
999
- price = price * (1 - item.discount_percentage / 10000)
1000
- }
1001
- } else if (item.discount_type == 'amount') {
1002
- let computed_discount = this.getPrice(item, 'discount', order.currency)
1003
- if (item.discount_before_tax && computed_discount > 0) {
1004
- price = price - computed_discount
1005
- if (price <= 0) price = 0
1006
- }
1007
- }
1008
- }
1009
- let taxprice = (price * tax.percentage) / 10000
1010
-
1011
- taxM[i] = {
1012
- tax: tax,
1013
- taxprice: taxprice,
1014
- }
1015
- })
1016
-
1017
- // have discount before tax
1018
- if (order.discount_before_tax) {
1019
- // decrease tax by discount percentage
1020
- if (order.discount_type == 'percentage' && order.discount_percentage > 0) {
1021
- sb.map(taxM, (t) => {
1022
- t.taxprice = t.taxprice * (1 - order.discount_percentage / 10000)
1023
- })
1024
- computed_discount += (subtotal * order.discount_percentage) / 10000
1025
- } else if (order.discount_type == 'amount') {
1026
- let discount = this.getPrice(order, 'discount', order.currency)
1027
- if (subtotal > 0) {
1028
- sb.map(taxM, (t) => {
1029
- // CAUTION: easy to miss
1030
- if (discount > subtotal) discount = subtotal
1031
-
1032
- t.taxprice = t.taxprice * (1 - discount / subtotal)
1033
- })
1034
- }
1035
- computed_discount += discount
1036
- }
1037
- } else {
1038
- if (order.discount_type == 'percentage' && order.discount_percentage > 0) {
1039
- let taxprice = 0
1040
- sb.map(taxM, (t) => (taxprice += t.taxprice))
1041
- computed_discount += ((subtotal + taxprice) * order.discount_percentage) / 10000
1042
- } else if (order.discount_type == 'amount') {
1043
- let discount = this.getPrice(order, 'discount', order.currency)
1044
- computed_discount += discount
1045
- }
1046
- }
1047
-
1048
- // SHIP
1049
- let shippingfee = this.getPrice(order.shipping, 'fee', order.currency)
1050
- if (shippingfee > 0) {
1051
- if (sb.get(order, 'shipping.tax.id')) {
1052
- let tax = order.shipping.tax
1053
- let taxprice = (shippingfee * tax.percentage) / 10000
1054
- taxM['ship'] = {tax: tax, taxprice: taxprice}
1055
- }
1056
- }
1057
-
1058
- let taxprice = 0
1059
- sb.map(taxM, (t) => (taxprice += t.taxprice))
1060
- let total = subtotal + taxprice - computed_discount + shippingfee
1061
-
1062
- // add adjustment
1063
- let adj = this.getPrice(order, 'adjustment', order.currency)
1064
- total += adj
1065
-
1066
- if (total < 0) total = 0
1067
- return {subtotal, computed_discount, taxM, total}
1068
- }
1069
-
1070
933
  replaceFileUrl(src) {
1071
934
  if (!src) return ''
1072
935
 
@@ -1,8 +1,8 @@
1
1
  var common = require('./common.js')
2
2
 
3
3
  // callback when user is about to leave site
4
- export function trackExitIntent (cb) {
5
- let handler = e => {
4
+ export function trackExitIntent(cb) {
5
+ let handler = (e) => {
6
6
  if (e.clientY > 10) return // not move to top
7
7
  if (cb) cb()
8
8
  document.removeEventListener('mouseout', handler)
@@ -11,8 +11,8 @@ export function trackExitIntent (cb) {
11
11
  }
12
12
 
13
13
  // callback after user has scrolled X% down on the current page
14
- export function trackScrollingPercentage (percent, cb) {
15
- let handleScroll = e => {
14
+ export function trackScrollingPercentage(percent, cb) {
15
+ let handleScroll = (e) => {
16
16
  let scrollTop = e.srcElement.scrollingElement ? e.srcElement.scrollingElement.scrollTop : e.srcElement.scrollTop
17
17
  let scrollHeight = e.srcElement.scrollingElement
18
18
  ? e.srcElement.scrollingElement.scrollHeight
@@ -28,14 +28,17 @@ export function trackScrollingPercentage (percent, cb) {
28
28
  }
29
29
 
30
30
  // callback when user clicks on a specific part of page
31
- export function trackAreaClicked (selector, cb) {
31
+ export function trackAreaClicked(selector, cb) {
32
32
  if (!selector) return
33
33
  selector = selector || ''
34
- common.map(selector.split('\n'), selector => {
34
+ common.map(selector.split('\n'), (selector) => {
35
35
  selector = common.trim(selector)
36
36
  if (!selector) return
37
- let doms = document.querySelectorAll(selector)
38
- common.map(doms, dom => {
37
+ let doms = []
38
+ try {
39
+ doms = document.querySelectorAll(selector)
40
+ } catch (e) {}
41
+ common.map(doms, (dom) => {
39
42
  if (!dom) return
40
43
  dom.addEventListener('click', cb, false)
41
44
  })
@@ -43,7 +46,7 @@ export function trackAreaClicked (selector, cb) {
43
46
  }
44
47
 
45
48
  // callback when user has stopped all activity (clicking, scrolling, ...)
46
- export function trackInactivity (seconds, cb) {
49
+ export function trackInactivity(seconds, cb) {
47
50
  let events = [
48
51
  'scroll',
49
52
  'keyup',
@@ -80,9 +83,9 @@ let timeOnPage = 0 // seconds
80
83
  setInterval(() => timeOnPage++, 1000)
81
84
 
82
85
  // when user has been on the page for at least X seconds
83
- export function trackTimeOnPage (seconds, cb) {
86
+ export function trackTimeOnPage(seconds, cb) {
84
87
  if (seconds < 1) {
85
- return setTimeout(function () {
88
+ return setTimeout(function() {
86
89
  cb(seconds)
87
90
  }, 100)
88
91
  }
package/take.js ADDED
@@ -0,0 +1,36 @@
1
+ const puppeteer = require('puppeteer')
2
+
3
+ async function take() {
4
+ const browser = await puppeteer.launch({args: ['--no-sandbox']})
5
+ const page = await browser.newPage()
6
+ let templateBase64 = Buffer.from(encodeURIComponent(process.argv[2])).toString('base64')
7
+
8
+ await page.setViewport({width: 940, height: 700})
9
+ await page.goto('file://' + __dirname + '/dist/screenshoot.html#' + templateBase64, {
10
+ waitUntil: 'networkidle2',
11
+ })
12
+ await timeout(3000)
13
+ let out = makeid(20) + '.jpg'
14
+ await page.screenshot({path: out})
15
+ console.log(out)
16
+ browser.close()
17
+ }
18
+
19
+ function timeout(ms) {
20
+ return new Promise((resolve) => setTimeout(resolve, ms))
21
+ }
22
+
23
+ function makeid(length) {
24
+ var result = []
25
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
26
+ var charactersLength = characters.length
27
+ for (var i = 0; i < length; i++) {
28
+ result.push(characters.charAt(Math.floor(Math.random() * charactersLength)))
29
+ }
30
+ return result.join('')
31
+ }
32
+
33
+ take()
34
+
35
+ // try (remember to run 'npm run build' before running following command)
36
+ // node take.js '{"account_id":"acpxkgumifuoofoosble","id":"cpqzpnooosdhodmkjlixs","name":"Đặt hàng trước","type":"notification","created":1620813049308,"created_by":"agqmwfyuehpuzpehmv","updated":1620816899738,"updated_by":"agqmwfyuehpuzpehmv","triggers":[{"type":"after_pageview"}],"initiative_frequency":{"once_per_session":true},"notification":{"profile_tags":["nam thanh niên","nữ thanh niên"],"profiles":[{"avatar_url":"https://public-gcs.subiz-cdn.com/widget_assets/profile_images/VNM02.png","fullname":"Đoàn Hải Nam","country":"vn","gender":"Male","age":26,"tags":["nam thanh niên","vui tươi"],"email":"hainamxx@gmail.com","phone":"0823588xxx","address":"Hàng Da, Hoàn Kiếm, Hà Nội"},{"avatar_url":"https://public-gcs.subiz-cdn.com/widget_assets/profile_images/VNF03.png","fullname":"Nguyễn Hoàng Lan","country":"vn","gender":"Female","age":36,"tags":["nữ trung niên","lịch sự","vui tươi"],"email":"lannhoanggxx@gmail.com","phone":"0326789xxx","address":"Lũng Cú, Đồng Văn, Hà Giang"},{"avatar_url":"https://public-gcs.subiz-cdn.com/widget_assets/profile_images/VNM04.png","fullname":"Nguyễn Quý Tiến","country":"vn","gender":"Male","age":40,"tags":["nam trung niên","lịch sự"],"email":"tiendzxxx@gmail.com","phone":"056189xxxx","address":"Thụy Khuê, Tây Hồ, Hà Nội"},{"avatar_url":"https://public-gcs.subiz-cdn.com/widget_assets/profile_images/VNF05.png","fullname":"Phạm Hồng Thắm","country":"vn","gender":"Female","age":36,"tags":["nữ trung niên","lịch sự"],"email":"thampham1506xxx@gmail.com","phone":"033820xxxx","address":"Ngọc Đào, Hà Quang, Cao Bằng"},{"avatar_url":"https://public-gcs.subiz-cdn.com/widget_assets/profile_images/VNF06.png","fullname":"Ngô Thị Như Hòa","country":"vn","gender":"Female","age":29,"tags":["nữ thanh niên","lịch sự"],"email":"alice29xxx@gmail.com","phone":"058104xxxx","address":"Xuân Đỉnh, Bắc Từ Liêm, Hà Nội"}],"title_quill_delta":"{\"ops\":[{\"insert\":{\"dynamicField\":{\"id\":\"hesivydbbhoybwyk\",\"value\":\"Họ tên\",\"key\":\"user.fullname\"}}},{\"insert\":\" Ba \\n\"}]}","title_style":{"color":"rgba(255,255,255,1)"},"message_quill_deltas":["{\"ops\":[{\"insert\":\"Đặt trước Note 20 thành công\\n\"}]}"],"message_style":{"color":"rgba(216,207,207,1)"},"url":"https://subiz.com.vn","new_tab":true,"background_url":"https://public-gcs.subiz-cdn.com/widget_assets/notification_background/Frame%20129.png","subtext_style":{},"avatar_style":{"border_radius":"50%"},"position":"bottom-left","interval_sec":60000},"conversion_notification":{"all_agents":true},"template_title":"Đặt hàng trước","thumbnail_url":"https://file-subiz.com/fiqzpohaoyckhgxylulxcpqzpnooosdhodmkjlixs.jpg"}'