@subiz/widget-v4 4.1.166 → 4.1.168
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/app.js +2 -0
- package/compiled_src/lib.js +2 -0
- package/compiled_src/plugin.js +1 -0
- package/compiled_src/store/api.js +4 -1
- package/dist/198a731cfbb.app.js +1 -0
- package/dist/{198a3614cdc.chat.html → 198a731cfbb.chat.html} +1 -1
- package/dist/198a731cfbb.chat.js +1 -0
- package/dist/{198a3614cdc.form.html → 198a731cfbb.form.html} +1 -1
- package/dist/198a731cfbb.form.js +1 -0
- package/dist/{198a3614cdc.index.html → 198a731cfbb.index.html} +1 -1
- package/dist/{198a3614cdc.library.html → 198a731cfbb.library.html} +1 -1
- package/dist/198a731cfbb.library.js +1 -0
- package/dist/{198a3614cdc.preview.html → 198a731cfbb.preview.html} +1 -1
- package/dist/198a731cfbb.preview.js +1 -0
- package/dist/198a731cfbb.webview.js +1 -0
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +26 -33
- package/index.html +1 -0
- package/package.json +1 -1
- package/src/lib.js +4 -0
- package/src/plugin.js +1 -0
- package/src/store/api.js +4 -1
- package/tracking.js +114 -36
- package/dist/198a3614cdc.app.js +0 -1
- package/dist/198a3614cdc.chat.js +0 -1
- package/dist/198a3614cdc.form.js +0 -1
- package/dist/198a3614cdc.library.js +0 -1
- package/dist/198a3614cdc.preview.js +0 -1
- package/dist/198a3614cdc.webview.js +0 -1
- /package/dist/{198a3614cdc.127.js → 198a731cfbb.127.js} +0 -0
- /package/dist/{198a3614cdc.132.js → 198a731cfbb.132.js} +0 -0
- /package/dist/{198a3614cdc.185.js → 198a731cfbb.185.js} +0 -0
- /package/dist/{198a3614cdc.27.js → 198a731cfbb.27.js} +0 -0
- /package/dist/{198a3614cdc.278.js → 198a731cfbb.278.js} +0 -0
- /package/dist/{198a3614cdc.339.js → 198a731cfbb.339.js} +0 -0
- /package/dist/{198a3614cdc.459.js → 198a731cfbb.459.js} +0 -0
- /package/dist/{198a3614cdc.490.js → 198a731cfbb.490.js} +0 -0
- /package/dist/{198a3614cdc.74.js → 198a731cfbb.74.js} +0 -0
- /package/dist/{198a3614cdc.997.js → 198a731cfbb.997.js} +0 -0
package/dist/HASH
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
198a731cfbb
|
package/dist/screenshoot.js
CHANGED
|
@@ -3873,7 +3873,10 @@ function jsonifyTextPlain(param, done) {
|
|
|
3873
3873
|
_defineProperty(this, "time", _ => ajax.setBaseUrl(this.ApiURL).withCredentials(true).setParser('json').get('/time'));
|
|
3874
3874
|
_defineProperty(this, "updateUser", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data));
|
|
3875
3875
|
_defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
|
|
3876
|
-
_defineProperty(this, "getAccountSetting", () =>
|
|
3876
|
+
_defineProperty(this, "getAccountSetting", () => {
|
|
3877
|
+
let href = util/* default */.A.get(document, 'location.href');
|
|
3878
|
+
return this.apireq.addQuery('url', href).get(`/accounts/${this.accid}/settings`);
|
|
3879
|
+
});
|
|
3877
3880
|
_defineProperty(this, "sendImpression", impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression));
|
|
3878
3881
|
_defineProperty(this, "sendConversion", conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion));
|
|
3879
3882
|
_defineProperty(this, "lookupOrder", key => ajax.setBaseUrl(this.ApiURL).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').addQuery('x-signed-key', key).get(`/orders/123`));
|
|
@@ -5090,6 +5093,7 @@ class Store {
|
|
|
5090
5093
|
});
|
|
5091
5094
|
}
|
|
5092
5095
|
}, 2000);
|
|
5096
|
+
this.loopCheckConnectionStatus();
|
|
5093
5097
|
}
|
|
5094
5098
|
async loopCheckConnectionStatus() {
|
|
5095
5099
|
while (true) {
|
|
@@ -5248,8 +5252,6 @@ class Store {
|
|
|
5248
5252
|
if (!this.isInsync('account')) this.reconnect();
|
|
5249
5253
|
}
|
|
5250
5254
|
async init(accid, mask, userRef, options) {
|
|
5251
|
-
this.readyGate.close();
|
|
5252
|
-
accid = (accid || '').trim();
|
|
5253
5255
|
this.g_sync = {};
|
|
5254
5256
|
if (!options || !options.use_subdomain_cookie) {
|
|
5255
5257
|
if (window && window.location && window.location.hostname) {
|
|
@@ -5284,69 +5286,58 @@ class Store {
|
|
|
5284
5286
|
cleanMyLocalStorage();
|
|
5285
5287
|
this.clearBrowserData();
|
|
5286
5288
|
}
|
|
5287
|
-
this.lightConvos = {};
|
|
5288
|
-
this.cache = new kv(new lsdb('sbz2023', true), 'kv');
|
|
5289
5289
|
this.api.setAuth({
|
|
5290
5290
|
accid: accid
|
|
5291
5291
|
});
|
|
5292
5292
|
if (userRef) this.cookie.set('__sbref', userRef);
|
|
5293
|
-
|
|
5293
|
+
return this._initResource(accid, {
|
|
5294
5294
|
accid: accid,
|
|
5295
5295
|
mask: mask,
|
|
5296
5296
|
ref: userRef
|
|
5297
|
+
}, {
|
|
5298
|
+
account_id: accid,
|
|
5299
|
+
user_ref: userRef,
|
|
5300
|
+
user_mask: mask
|
|
5297
5301
|
});
|
|
5302
|
+
}
|
|
5303
|
+
async _initResource(accid, auth, realtimep) {
|
|
5304
|
+
this.g_sync = {};
|
|
5305
|
+
let user = await this.api.setAuth(auth);
|
|
5298
5306
|
if (user.error) {
|
|
5299
5307
|
console.error(user);
|
|
5300
5308
|
return user;
|
|
5301
5309
|
}
|
|
5310
|
+
this.readyGate.close();
|
|
5311
|
+
accid = (accid || '').trim();
|
|
5312
|
+
this.lightConvos = this.kv.match('light_convos') || {};
|
|
5313
|
+
this.cache = new kv(new lsdb('sbz2023', true), 'kv');
|
|
5302
5314
|
if (this.realtime) this.realtime.stop();
|
|
5303
|
-
if (this.fake) this.realtime = new realtime_fake();else this.realtime = new Realtime(this.RealtimeURL,
|
|
5304
|
-
account_id: accid,
|
|
5305
|
-
user_ref: userRef,
|
|
5306
|
-
user_mask: mask
|
|
5307
|
-
}, xhrsend);
|
|
5315
|
+
if (this.fake) this.realtime = new realtime_fake();else this.realtime = new Realtime(this.RealtimeURL, realtimep, xhrsend);
|
|
5308
5316
|
this.realtime.onEvent(this.onWs.bind(this));
|
|
5309
5317
|
this.realtime.onInterrupted(async () => {
|
|
5310
5318
|
await this.reconnectWs(accid, user.id);
|
|
5311
5319
|
this.reconnect();
|
|
5312
5320
|
});
|
|
5313
|
-
this.lightConvos = this.kv.match('light_convos') || {};
|
|
5314
5321
|
this.seenLoop();
|
|
5315
5322
|
await this.reconnect({
|
|
5316
5323
|
user: user
|
|
5317
5324
|
});
|
|
5318
5325
|
this.readyGate.open();
|
|
5319
5326
|
this.reconnectWs(accid, user.id);
|
|
5320
|
-
this.loopCheckConnectionStatus();
|
|
5321
5327
|
return user;
|
|
5322
5328
|
}
|
|
5323
5329
|
async login(accid, user_id, tokenGenerator) {
|
|
5324
5330
|
if (this._die) return dieErr;
|
|
5325
|
-
|
|
5331
|
+
cleanMyLocalStorage();
|
|
5332
|
+
this.clearBrowserData();
|
|
5333
|
+
this.new_visitor = false;
|
|
5334
|
+
return this._initResource(accid, {
|
|
5326
5335
|
accid: accid,
|
|
5327
5336
|
profile_id: user_id,
|
|
5328
5337
|
tokenGenerator: tokenGenerator
|
|
5329
|
-
}
|
|
5330
|
-
if (user.error) return user;
|
|
5331
|
-
this.clearBrowserData();
|
|
5332
|
-
this.readyGate.close();
|
|
5333
|
-
accid = (accid || '').trim();
|
|
5334
|
-
this.g_sync = {};
|
|
5335
|
-
this.new_visitor = false;
|
|
5336
|
-
if (this.realtime) this.realtime.stop();
|
|
5337
|
-
if (this.fake) this.realtime = new realtime_fake();else this.realtime = new Realtime(this.RealtimeURL, {
|
|
5338
|
+
}, {
|
|
5338
5339
|
getAccessToken: () => this.api.token_generator()
|
|
5339
5340
|
});
|
|
5340
|
-
this.realtime.onEvent(this.onWs.bind(this));
|
|
5341
|
-
this.realtime.onInterrupted(async () => {
|
|
5342
|
-
await this.reconnectWs(accid, user.id);
|
|
5343
|
-
this.reconnect();
|
|
5344
|
-
});
|
|
5345
|
-
this.seenLoop();
|
|
5346
|
-
await this.reconnect();
|
|
5347
|
-
this.readyGate.open();
|
|
5348
|
-
this.reconnectWs(accid, user.id);
|
|
5349
|
-
return user;
|
|
5350
5341
|
}
|
|
5351
5342
|
logout(userRef) {
|
|
5352
5343
|
return this.api.setAuth({
|
|
@@ -9100,6 +9091,8 @@ class Event extends common/* Com */.Mw {
|
|
|
9100
9091
|
renderAIDevNote() {
|
|
9101
9092
|
if (!this.props.isLast) return null;
|
|
9102
9093
|
if (!this.props.store.isAIDevMode()) return null;
|
|
9094
|
+
let cid = util/* default */.A.get(this.props.event.ev, 'data.message.conversation_id', '');
|
|
9095
|
+
if (cid.startsWith('cslight')) return null;
|
|
9103
9096
|
let ev = util/* default */.A.get(this.props.event, 'ev') || {};
|
|
9104
9097
|
let pongs = util/* default */.A.get(ev, 'data.message.pongs') || [];
|
|
9105
9098
|
let hasLike = this.hasLike();
|
package/index.html
CHANGED
package/package.json
CHANGED
package/src/lib.js
CHANGED
|
@@ -117,6 +117,8 @@ class Widget {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
async setAccount(id, $container, mask, cb) {
|
|
120
|
+
if (typeof sbz_info != 'undefined') sbz_info.set_account = sb.Date.now()
|
|
121
|
+
|
|
120
122
|
if (!id) return {error: 'empty_account_id'} // do nothing
|
|
121
123
|
let outmask = await this.store.init(id, mask)
|
|
122
124
|
sb.setTimeout(() => window.postMessage({type: 'widget_loaded', account_id: id}, '*'), 0) // send to chrome extension
|
|
@@ -131,6 +133,8 @@ class Widget {
|
|
|
131
133
|
sb.clearInterval(clean)
|
|
132
134
|
}, 1000)
|
|
133
135
|
this.domGate.open()
|
|
136
|
+
if (typeof sbz_info != 'undefined') sbz_info.set_account_done = sb.Date.now()
|
|
137
|
+
|
|
134
138
|
cb && cb(outmask)
|
|
135
139
|
return outmask
|
|
136
140
|
}
|
package/src/plugin.js
CHANGED
|
@@ -73,6 +73,7 @@ function Plugin(plugin, store, $container, lib) {
|
|
|
73
73
|
|
|
74
74
|
if (plugin.type === 'chatbox') {
|
|
75
75
|
// if (!Chatbox) Chatbox = (await LoadChatbox()).default
|
|
76
|
+
if (typeof sbz_info != 'undefined' ) sbz_info.render_chatbox = sb.Date.now()
|
|
76
77
|
render(<Chatbox destroy={_destroy} plugin={plugin} store={store} ref={_ref} t={this.t} />, $div)
|
|
77
78
|
}
|
|
78
79
|
|
package/src/store/api.js
CHANGED
|
@@ -358,7 +358,10 @@ export default class {
|
|
|
358
358
|
updateUser = (data) => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data)
|
|
359
359
|
|
|
360
360
|
getUser = (_) => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`)
|
|
361
|
-
getAccountSetting = () =>
|
|
361
|
+
getAccountSetting = () => {
|
|
362
|
+
let href = sb.get(document, 'location.href') // send full href, this could be used to select which bot (ai-agent) should be returned
|
|
363
|
+
return this.apireq.addQuery('url', href).get(`/accounts/${this.accid}/settings`)
|
|
364
|
+
}
|
|
362
365
|
|
|
363
366
|
sendImpression = (impression) =>
|
|
364
367
|
this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression)
|
package/tracking.js
CHANGED
|
@@ -1,45 +1,123 @@
|
|
|
1
1
|
// send signal to server when the chatbox is not visible
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
} else {
|
|
18
|
-
// the chatbox is not found in DOM
|
|
19
|
-
status = 'not-found'
|
|
3
|
+
if (typeof sbz_info == 'undefined') {
|
|
4
|
+
var sbz_logs = []
|
|
5
|
+
var sbz_info = {}
|
|
6
|
+
// Catch synchronous runtime errors (ReferenceError, TypeError, etc.)
|
|
7
|
+
window.onerror = function (message, source, lineno, colno, error) {
|
|
8
|
+
sbz_logs.push({
|
|
9
|
+
created: Date.now(),
|
|
10
|
+
type: 'error',
|
|
11
|
+
message: message,
|
|
12
|
+
source: source,
|
|
13
|
+
line: lineno,
|
|
14
|
+
column: colno,
|
|
15
|
+
error: error,
|
|
16
|
+
})
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
// Catch unhandled Promise rejections
|
|
20
|
+
window.addEventListener('unhandledrejection', function (event) {
|
|
21
|
+
sbz_logs.push({
|
|
22
|
+
created: Date.now(),
|
|
23
|
+
type: 'rejection',
|
|
24
|
+
reason: event.reason + '',
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const _originalOpen = XMLHttpRequest.prototype.open
|
|
29
|
+
const _originalSend = XMLHttpRequest.prototype.send
|
|
30
|
+
|
|
31
|
+
XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
|
|
32
|
+
this._url = url // store URL for logging
|
|
33
|
+
return _originalOpen.apply(this, arguments)
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
XMLHttpRequest.prototype.send = function (body) {
|
|
37
|
+
this.addEventListener('load', function () {
|
|
38
|
+
if (this.status >= 400) {
|
|
39
|
+
sbz_logs.push({
|
|
40
|
+
type: 'xhrfailed',
|
|
41
|
+
url: this._url,
|
|
42
|
+
status: this.status,
|
|
43
|
+
response: this.responseText,
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
this.addEventListener('error', function () {
|
|
48
|
+
console.error('XHR network error:', {url: this._url})
|
|
49
|
+
})
|
|
50
|
+
return _originalSend.apply(this, arguments)
|
|
51
|
+
}
|
|
37
52
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
// ===== 4. Catch fetch errors =====
|
|
54
|
+
const originalFetch = window.fetch
|
|
55
|
+
window.fetch = function (...args) {
|
|
56
|
+
return originalFetch(...args)
|
|
57
|
+
.then((response) => {
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
sbz_logs.push({
|
|
60
|
+
type: 'fetchfailed',
|
|
61
|
+
url: args[0],
|
|
62
|
+
status: response.status,
|
|
63
|
+
statusText: response.statusText,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
return response
|
|
67
|
+
})
|
|
68
|
+
.catch((err) => {
|
|
69
|
+
sbz_logs.push({
|
|
70
|
+
type: 'fetchfailed2',
|
|
71
|
+
url: args[0],
|
|
72
|
+
error: err + '',
|
|
73
|
+
})
|
|
74
|
+
throw err // re-throw if needed
|
|
75
|
+
})
|
|
42
76
|
}
|
|
43
77
|
|
|
44
|
-
|
|
45
|
-
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
var $button = document.querySelector('div.chat-button')
|
|
80
|
+
|
|
81
|
+
let status = ''
|
|
82
|
+
if ($button) {
|
|
83
|
+
var rect = $button.getBoundingClientRect()
|
|
84
|
+
var visible = rect.width > 0 && rect.height > 0
|
|
85
|
+
if (visible) {
|
|
86
|
+
// the chatbox is visible
|
|
87
|
+
return
|
|
88
|
+
} else {
|
|
89
|
+
// the chatbox is not visible
|
|
90
|
+
status = 'hidden'
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
// the chatbox is not found in DOM
|
|
94
|
+
status = 'not-found'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Collect device and browser info
|
|
98
|
+
var info = {
|
|
99
|
+
status: status,
|
|
100
|
+
href: window.location.href,
|
|
101
|
+
userAgent: navigator.userAgent,
|
|
102
|
+
platform: navigator.platform,
|
|
103
|
+
language: navigator.language,
|
|
104
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
105
|
+
logs: sbz_logs,
|
|
106
|
+
info: sbz_info,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Send via XHR
|
|
110
|
+
var xhr = new XMLHttpRequest()
|
|
111
|
+
xhr.open('POST', 'https://api.subiz.com.vn/4.1/chatbox-failed', true)
|
|
112
|
+
xhr.withCredentials = false
|
|
113
|
+
xhr.setRequestHeader('Content-Type', 'text/plain')
|
|
114
|
+
|
|
115
|
+
xhr.onreadystatechange = function () {
|
|
116
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
117
|
+
console.log('Server responded with:', xhr.status, xhr.responseText)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
xhr.send(JSON.stringify(info))
|
|
122
|
+
}, 15000)
|
|
123
|
+
}
|