@subiz/widget-v4 4.1.125 → 4.1.129
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.
- package/assets/less/avatar.less +7 -3
- package/assets/less/chatbox.less +25 -2
- package/assets/less/form.less +77 -2
- package/assets/less/message.less +4 -0
- package/assets/less/widget.less +20 -0
- package/assets/less/widget_header.less +27 -7
- package/compiled_src/chatbox/ChatButton.js +22 -7
- package/compiled_src/chatbox/ConnectionStatus.js +58 -0
- package/compiled_src/chatbox/Event.js +10 -8
- package/compiled_src/chatbox/FormAttachment2.js +80 -0
- package/compiled_src/chatbox/Header.js +12 -1
- package/compiled_src/chatbox/Widget.js +5 -0
- package/compiled_src/form/Form.js +274 -0
- package/compiled_src/form/FormPage.js +131 -0
- package/compiled_src/form/index.js +72 -0
- package/compiled_src/store/api.js +3 -0
- package/compiled_src/store/realtime_fake.js +4 -0
- package/compiled_src/store/store.js +25 -0
- package/compiled_src/util/campaign.js +3 -5
- package/compiled_src/util/common.js +15 -0
- package/dist/127.js +273 -0
- package/dist/132.js +2575 -6434
- package/dist/185.js +1885 -0
- package/dist/1967c022bc1.127.js +1 -0
- package/dist/1967c022bc1.132.js +1 -0
- package/dist/1967c022bc1.185.js +1 -0
- package/dist/1967c022bc1.27.js +1 -0
- package/dist/1967c022bc1.278.js +1 -0
- package/dist/1967c022bc1.459.js +1 -0
- package/dist/1967c022bc1.490.js +1 -0
- package/dist/1967c022bc1.74.js +1 -0
- package/dist/1967c022bc1.997.js +1 -0
- package/dist/1967c022bc1.app.js +1 -0
- package/dist/1967c022bc1.form.html +1 -0
- package/dist/1967c022bc1.form.js +1 -0
- package/dist/{18a02a9c54e.index.html → 1967c022bc1.index.html} +28 -4
- package/dist/{18a02a9c54e.library.html → 1967c022bc1.library.html} +28 -4
- package/dist/1967c022bc1.library.js +1 -0
- package/dist/{18a02a9c54e.preview.html → 1967c022bc1.preview.html} +1 -1
- package/dist/1967c022bc1.preview.js +1 -0
- package/dist/1967c022bc1.webview.js +1 -0
- package/dist/27.js +107 -0
- package/dist/278.js +406 -0
- package/dist/459.js +107 -0
- package/dist/{605.js → 490.js} +82 -82
- package/dist/{335.js → 74.js} +35 -35
- package/dist/{678.js → 997.js} +6 -6
- package/dist/HASH +1 -1
- package/dist/assets/img/{subiz-mono.877e9f5.svg → subiz-mono.8fbc067.svg} +1 -1
- package/dist/malicious-app.js +6 -4
- package/dist/screenshoot.html +1 -1
- package/dist/screenshoot.js +10133 -5182
- package/form.html +10 -0
- package/package.json +5 -4
- package/src/chatbox/ChatButton.js +22 -9
- package/src/chatbox/ConnectionStatus.js +42 -0
- package/src/chatbox/Event.js +10 -10
- package/src/chatbox/FormAttachment2.js +58 -0
- package/src/chatbox/Header.js +15 -0
- package/src/chatbox/Widget.js +2 -0
- package/src/form/Form.js +293 -0
- package/src/form/FormPage.js +95 -0
- package/src/form/index.js +79 -0
- package/src/store/api.js +8 -0
- package/src/store/realtime_fake.js +8 -4
- package/src/store/store.js +29 -0
- package/src/util/campaign.js +3 -5
- package/src/util/common.js +16 -0
- package/webpack.dev.js +2 -0
- package/webpack.prod.js +7 -0
- package/dist/178.js +0 -406
- package/dist/18a02a9c54e.132.js +0 -1
- package/dist/18a02a9c54e.178.js +0 -1
- package/dist/18a02a9c54e.213.js +0 -1
- package/dist/18a02a9c54e.335.js +0 -1
- package/dist/18a02a9c54e.362.js +0 -1
- package/dist/18a02a9c54e.441.js +0 -1
- package/dist/18a02a9c54e.605.js +0 -1
- package/dist/18a02a9c54e.678.js +0 -1
- package/dist/18a02a9c54e.782.js +0 -1
- package/dist/18a02a9c54e.app.js +0 -1
- package/dist/18a02a9c54e.library.js +0 -1
- package/dist/18a02a9c54e.preview.js +0 -1
- package/dist/18a02a9c54e.screenshoot.js +0 -1
- package/dist/18a02a9c54e.webview.js +0 -1
- package/dist/213.js +0 -2780
- package/dist/362.js +0 -107
- package/dist/441.js +0 -2855
- package/dist/782.js +0 -107
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import Store from '../store/store.js'
|
|
2
|
+
import * as common from '../common.js'
|
|
3
|
+
import sb from '../util/index.js'
|
|
4
|
+
import {h, render} from 'preact'
|
|
5
|
+
import FormPage from './FormPage.js'
|
|
6
|
+
// find the body
|
|
7
|
+
let promiseMainCSS = (() => import(/*webpackChunkName: "main-css" */ '../chatbox/css.js'))()
|
|
8
|
+
const config = require('../../config.js')
|
|
9
|
+
|
|
10
|
+
function findChatbox(store) {
|
|
11
|
+
let pluginM = store.matchPlugin()
|
|
12
|
+
let chatboxs = sb.filter(pluginM, (plugin) => plugin.type === 'chatbox')
|
|
13
|
+
if (sb.size(chatboxs) === 0) {
|
|
14
|
+
console.error('no chatbox found.')
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
return chatboxs[0]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getUrlParameter(name) {
|
|
21
|
+
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]')
|
|
22
|
+
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)')
|
|
23
|
+
var results = regex.exec(location.search)
|
|
24
|
+
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var $link = document.createElement('link')
|
|
28
|
+
$link.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap'
|
|
29
|
+
$link.rel = 'stylesheet'
|
|
30
|
+
document.head.append($link)
|
|
31
|
+
|
|
32
|
+
sb.preloadWebfonts(['Inter'], [400, 500])
|
|
33
|
+
|
|
34
|
+
async function load() {
|
|
35
|
+
let store = new Store(config.ApiURL, config.FileURL, config.RealtimeURL, true)
|
|
36
|
+
window.store = store
|
|
37
|
+
let accid =
|
|
38
|
+
getUrlParameter('id') || getUrlParameter('acc_id') || getUrlParameter('account_id') || 'acqsulrowbxiugvginhw'
|
|
39
|
+
let mask = accid + '@' + 'abcd'
|
|
40
|
+
let token = getUrlParameter('token')
|
|
41
|
+
await store.init(accid, mask)
|
|
42
|
+
|
|
43
|
+
let acc = store.matchAccount() || {}
|
|
44
|
+
let plugin = findChatbox(store) || {}
|
|
45
|
+
|
|
46
|
+
// make sure you are still alive
|
|
47
|
+
let css = (await promiseMainCSS).default.default.toString()
|
|
48
|
+
var outcss = sb.replaceCssVariable(css, plugin.chatbox)
|
|
49
|
+
|
|
50
|
+
let $cssStyleDiv = document.createElement('style')
|
|
51
|
+
document.head.appendChild($cssStyleDiv)
|
|
52
|
+
$cssStyleDiv.type = 'text/css'
|
|
53
|
+
$cssStyleDiv.id = 'subiz-style-for-order'
|
|
54
|
+
|
|
55
|
+
sb.setCss('form', $cssStyleDiv, outcss)
|
|
56
|
+
|
|
57
|
+
let t = (key) => {
|
|
58
|
+
if (_locale === 'debug') return `{{${key}}}`
|
|
59
|
+
|
|
60
|
+
let messages = sb.get(common.langMessages, _locale, [])
|
|
61
|
+
let message = sb.find(messages, (message) => message.key === key)
|
|
62
|
+
return sb.get(message, 'message', key)
|
|
63
|
+
}
|
|
64
|
+
let _locale = plugin.locale || acc.locale || 'vi-VN'
|
|
65
|
+
t.i18n = (i18nText) => {
|
|
66
|
+
if (!i18nText) return ''
|
|
67
|
+
let fallbackLocale = plugin.locale || acc.locale || 'vi-VN'
|
|
68
|
+
fallbackLocale = fallbackLocale.replace('-', '_')
|
|
69
|
+
let locale = _locale.replace('-', '_')
|
|
70
|
+
|
|
71
|
+
return i18nText[locale] || i18nText[fallbackLocale]
|
|
72
|
+
}
|
|
73
|
+
t.locale = () => _locale
|
|
74
|
+
common.downloadLanguage(store, _locale).then(() => {
|
|
75
|
+
render(<FormPage store={store} t={t} token={token}/>, document.getElementById('form'))
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
load()
|
package/src/store/api.js
CHANGED
|
@@ -14,6 +14,12 @@ export default class {
|
|
|
14
14
|
|
|
15
15
|
this.FileURL = FileURL
|
|
16
16
|
this.ApiURL = ApiURL
|
|
17
|
+
this.api41 = ajax
|
|
18
|
+
.setBaseUrl('https://api5.subiz.com.vn/4.1')
|
|
19
|
+
.withCredentials(true)
|
|
20
|
+
.setContentType('text/plain')
|
|
21
|
+
.beforeHook(jsonifyTextPlain)
|
|
22
|
+
.setParser('json')
|
|
17
23
|
this.apireq = ajax
|
|
18
24
|
.setBaseUrl(ApiURL)
|
|
19
25
|
.withCredentials(true)
|
|
@@ -316,6 +322,8 @@ export default class {
|
|
|
316
322
|
list_districts = (p) => this.apireq.setQuery(p).get(`/accounts/${this.accid}/districts`)
|
|
317
323
|
list_wards = (p) => this.apireq.setQuery(p).get(`/accounts/${this.accid}/wards`)
|
|
318
324
|
|
|
325
|
+
checkFormToken = (token) => this.api41.get(`/submissions/${token}`)
|
|
326
|
+
submitForm2 = (token, data) => this.api41.post(`/submissions/${token}`, data)
|
|
319
327
|
suggest_address = (keyword) => this.apireq.setQuery({keyword: keyword}).get(`/accounts/${this.accid}/addresses`)
|
|
320
328
|
create_ticket = (ticket) => this.apireq.post(`/accounts/${this.accid}/tickets`, ticket)
|
|
321
329
|
}
|
package/src/store/store.js
CHANGED
|
@@ -21,6 +21,9 @@ export default class Store {
|
|
|
21
21
|
cookie = cookie
|
|
22
22
|
|
|
23
23
|
constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi) {
|
|
24
|
+
this.connectionStatus = 'active' // active, dead: Internet coneection issue or rt server error, connecting: Subscribe rt too long
|
|
25
|
+
this.CONNECTION_CHECK_INTERVAL = 3000
|
|
26
|
+
this.reconnectTimestamp = 0
|
|
24
27
|
this.g_sync = {}
|
|
25
28
|
this._die = false
|
|
26
29
|
this.forceDevice = null
|
|
@@ -123,6 +126,28 @@ export default class Store {
|
|
|
123
126
|
}, 2000)
|
|
124
127
|
}
|
|
125
128
|
|
|
129
|
+
async loopCheckConnectionStatus() {
|
|
130
|
+
while (true) {
|
|
131
|
+
if (this._die) break
|
|
132
|
+
await sb.sleep(this.CONNECTION_CHECK_INTERVAL)
|
|
133
|
+
if (!this.realtime) continue
|
|
134
|
+
if (!this.realtime.getStatus || !this.realtime.reconnect) continue
|
|
135
|
+
|
|
136
|
+
if (this.connectionStatus === 'dead') {
|
|
137
|
+
await this.realtime.reconnect()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let currentStatus = this.connectionStatus
|
|
141
|
+
this.connectionStatus = this.realtime.getStatus()
|
|
142
|
+
if (currentStatus !== this.connectionStatus) {
|
|
143
|
+
console.log('publish connectionStatus', this.connectionStatus)
|
|
144
|
+
this.pubsub.publish('connection')
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getConnectionStatus = () => this.connectionStatus
|
|
150
|
+
|
|
126
151
|
// inmem
|
|
127
152
|
_currentViewingProduct = {}
|
|
128
153
|
linkProduct(p) {
|
|
@@ -409,6 +434,8 @@ export default class Store {
|
|
|
409
434
|
matchHasManuallyClosed = () => !!this.kv.match('hasManuallyClosed') // true if user has ever closed the widget
|
|
410
435
|
matchClosePreviewAt = () => this.kv.match('close_preview_at') || 0
|
|
411
436
|
|
|
437
|
+
checkFormToken = (token) => this.api.checkFormToken(token)
|
|
438
|
+
submitForm2 = (token, data) => this.api.submitForm2(token, data)
|
|
412
439
|
sendPresence = sb.throttle(
|
|
413
440
|
async () => {
|
|
414
441
|
if (this._die) return dieErr
|
|
@@ -501,6 +528,7 @@ export default class Store {
|
|
|
501
528
|
await this.reconnect({user: user}) // already fetched
|
|
502
529
|
this.readyGate.open()
|
|
503
530
|
this.reconnectWs(accid, user.id)
|
|
531
|
+
this.loopCheckConnectionStatus()
|
|
504
532
|
return user
|
|
505
533
|
}
|
|
506
534
|
|
|
@@ -1063,6 +1091,7 @@ export default class Store {
|
|
|
1063
1091
|
}
|
|
1064
1092
|
|
|
1065
1093
|
onUpdate = (o, cb) => this.pubsub.on2(o, 'account', cb)
|
|
1094
|
+
onConnection = (o, cb) => this.pubsub.on2(o, 'connection', cb)
|
|
1066
1095
|
onResetCSS = (o, cb) => this.pubsub.on2(o, 'resetCSS', cb)
|
|
1067
1096
|
onHighlight = (o, cb) => this.pubsub.on2(o, 'highlight', cb)
|
|
1068
1097
|
|
package/src/util/campaign.js
CHANGED
|
@@ -81,10 +81,7 @@ export function trackInactivity(seconds = 0, cb) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
let
|
|
85
|
-
common.setInterval(() => {
|
|
86
|
-
timeOnPage += 5
|
|
87
|
-
}, 5000)
|
|
84
|
+
let _pageLoaded = common.Date.now()
|
|
88
85
|
|
|
89
86
|
// when user has been on the page for at least X seconds
|
|
90
87
|
export function trackTimeOnPage(seconds = 0, cb) {
|
|
@@ -95,10 +92,11 @@ export function trackTimeOnPage(seconds = 0, cb) {
|
|
|
95
92
|
}
|
|
96
93
|
|
|
97
94
|
let timer = common.setInterval(() => {
|
|
95
|
+
let timeOnPage = (common.Date.now() - _pageLoaded) / 1000
|
|
98
96
|
if (timeOnPage < seconds) return
|
|
99
97
|
if (cb) cb(timeOnPage)
|
|
100
98
|
common.clearInterval(timer)
|
|
101
|
-
},
|
|
99
|
+
}, 200)
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
function on(eventName, selector, fn) {
|
package/src/util/common.js
CHANGED
|
@@ -1411,6 +1411,22 @@ export function blockToText(block) {
|
|
|
1411
1411
|
return _blockToText(block).trim()
|
|
1412
1412
|
}
|
|
1413
1413
|
|
|
1414
|
+
export function isBlockEmpty(block) {
|
|
1415
|
+
return _isBlockEmpty(block)
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function _isBlockEmpty(block = {}) {
|
|
1419
|
+
if (!size(block.content)) {
|
|
1420
|
+
if ((block.text || '').trim()) return false
|
|
1421
|
+
return true
|
|
1422
|
+
}
|
|
1423
|
+
let result = true
|
|
1424
|
+
map(block.content, (content) => {
|
|
1425
|
+
result = result && _isBlockEmpty(content)
|
|
1426
|
+
})
|
|
1427
|
+
return result
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1414
1430
|
function _blockToText(block) {
|
|
1415
1431
|
if (!block || !block.type) return ''
|
|
1416
1432
|
let out = ''
|
package/webpack.dev.js
CHANGED
|
@@ -6,6 +6,7 @@ module.exports = {
|
|
|
6
6
|
webview: './webview.js',
|
|
7
7
|
app: './app.js',
|
|
8
8
|
inject: './inject.js',
|
|
9
|
+
form: './src/form/index.js',
|
|
9
10
|
preview: './preview.js',
|
|
10
11
|
library: './library.js',
|
|
11
12
|
order: './src/order/index.js',
|
|
@@ -20,6 +21,7 @@ module.exports = {
|
|
|
20
21
|
new HtmlWebpackPlugin({filename: './preview.html', template: './preview.html', chunks: ['preview']}),
|
|
21
22
|
new HtmlWebpackPlugin({filename: './inject.html', template: './inject.html', inject: 'body', chunks: ['inject']}),
|
|
22
23
|
new HtmlWebpackPlugin({filename: './library.html', template: './index.html', inject: 'body', chunks: ['library']}),
|
|
24
|
+
new HtmlWebpackPlugin({filename: './form.html', template: './form.html', inject: 'body', chunks: ['form']}),
|
|
23
25
|
new HtmlWebpackPlugin({
|
|
24
26
|
filename: './screenshoot.html',
|
|
25
27
|
template: './screenshoot.html',
|
package/webpack.prod.js
CHANGED
|
@@ -9,6 +9,7 @@ webpackconfig.entry = {
|
|
|
9
9
|
webview: './webview.js',
|
|
10
10
|
app: './app.js',
|
|
11
11
|
preview: './preview.js',
|
|
12
|
+
form: './src/form/index.js',
|
|
12
13
|
library: './library.js',
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -39,6 +40,12 @@ webpackconfig.plugins = [
|
|
|
39
40
|
inject: 'body',
|
|
40
41
|
chunks: ['preview'],
|
|
41
42
|
}),
|
|
43
|
+
new HtmlWebpackPlugin({
|
|
44
|
+
filename: HASH + '.form.html',
|
|
45
|
+
template: './form.html',
|
|
46
|
+
inject: 'body',
|
|
47
|
+
chunks: ['form'],
|
|
48
|
+
}),
|
|
42
49
|
new HtmlWebpackPlugin({
|
|
43
50
|
filename: HASH + '.library.html',
|
|
44
51
|
template: './index.html',
|