@subiz/widget-v4 4.1.203 → 4.1.204
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/api.md +646 -706
- package/compiled_src/lib.js +12 -13
- package/compiled_src/store/store.js +20 -4
- package/compiled_src/util/event.test.js +38 -0
- package/dist/19e1c4525c1.app.js +1 -0
- package/dist/{19df158c2ea.chat.html → 19e1c4525c1.chat.html} +1 -1
- package/dist/19e1c4525c1.chat.js +1 -0
- package/dist/{19df158c2ea.form.html → 19e1c4525c1.form.html} +1 -1
- package/dist/19e1c4525c1.form.js +1 -0
- package/dist/{19df158c2ea.index.html → 19e1c4525c1.index.html} +1 -1
- package/dist/{19df158c2ea.library.html → 19e1c4525c1.library.html} +1 -1
- package/dist/19e1c4525c1.library.js +1 -0
- package/dist/{19df158c2ea.preview.html → 19e1c4525c1.preview.html} +1 -1
- package/dist/19e1c4525c1.preview.js +1 -0
- package/dist/19e1c4525c1.webview.js +1 -0
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +50 -3
- package/package.json +3 -3
- package/src/lib.js +12 -13
- package/src/store/store.js +28 -19
- package/src/util/event.test.js +31 -0
- package/dist/19df158c2ea.app.js +0 -1
- package/dist/19df158c2ea.chat.js +0 -1
- package/dist/19df158c2ea.form.js +0 -1
- package/dist/19df158c2ea.library.js +0 -1
- package/dist/19df158c2ea.preview.js +0 -1
- package/dist/19df158c2ea.webview.js +0 -1
- /package/dist/{19df158c2ea.127.js → 19e1c4525c1.127.js} +0 -0
- /package/dist/{19df158c2ea.132.js → 19e1c4525c1.132.js} +0 -0
- /package/dist/{19df158c2ea.185.js → 19e1c4525c1.185.js} +0 -0
- /package/dist/{19df158c2ea.27.js → 19e1c4525c1.27.js} +0 -0
- /package/dist/{19df158c2ea.278.js → 19e1c4525c1.278.js} +0 -0
- /package/dist/{19df158c2ea.339.js → 19e1c4525c1.339.js} +0 -0
- /package/dist/{19df158c2ea.459.js → 19e1c4525c1.459.js} +0 -0
- /package/dist/{19df158c2ea.490.js → 19e1c4525c1.490.js} +0 -0
- /package/dist/{19df158c2ea.74.js → 19e1c4525c1.74.js} +0 -0
- /package/dist/{19df158c2ea.997.js → 19e1c4525c1.997.js} +0 -0
package/dist/HASH
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
19e1c4525c1
|
package/dist/screenshoot.js
CHANGED
|
@@ -1282,6 +1282,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1282
1282
|
window.cancelAnimationFrame(this.animationframe);
|
|
1283
1283
|
}
|
|
1284
1284
|
});
|
|
1285
|
+
(Object.getOwnPropertyDescriptor(__WEBPACK_DEFAULT_EXPORT__, "name") || {}).writable || Object.defineProperty(__WEBPACK_DEFAULT_EXPORT__, "name", { value: "default", configurable: true });
|
|
1285
1286
|
function linearTransform(from, to, t, duration) {
|
|
1286
1287
|
if (eqFloat(from, to)) return from;
|
|
1287
1288
|
var s = to - from;
|
|
@@ -4599,6 +4600,7 @@ let trackResponseFn = (param, done) => {
|
|
|
4599
4600
|
});
|
|
4600
4601
|
}
|
|
4601
4602
|
});
|
|
4603
|
+
(Object.getOwnPropertyDescriptor(api, "name") || {}).writable || Object.defineProperty(api, "name", { value: "default", configurable: true });
|
|
4602
4604
|
function fallbackGCSUrl(url) {
|
|
4603
4605
|
try {
|
|
4604
4606
|
const u = new URL(url);
|
|
@@ -4673,6 +4675,7 @@ const LIMIT = 80;
|
|
|
4673
4675
|
});
|
|
4674
4676
|
}
|
|
4675
4677
|
});
|
|
4678
|
+
(Object.getOwnPropertyDescriptor(lsdb, "name") || {}).writable || Object.defineProperty(lsdb, "name", { value: "default", configurable: true });
|
|
4676
4679
|
function lsdb_toString(obj) {
|
|
4677
4680
|
if (obj === undefined) return 'null';
|
|
4678
4681
|
return JSON.stringify(obj);
|
|
@@ -4977,6 +4980,7 @@ let KvMaxSize = 500;
|
|
|
4977
4980
|
this.initialized = false;
|
|
4978
4981
|
}
|
|
4979
4982
|
});
|
|
4983
|
+
(Object.getOwnPropertyDescriptor(kv, "name") || {}).writable || Object.defineProperty(kv, "name", { value: "default", configurable: true });
|
|
4980
4984
|
;// ./src/store/api_fake.js
|
|
4981
4985
|
function api_fake_defineProperty(e, r, t) { return (r = api_fake_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4982
4986
|
function api_fake_toPropertyKey(t) { var i = api_fake_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
@@ -5067,6 +5071,7 @@ const OK200 = Promise.resolve({
|
|
|
5067
5071
|
};
|
|
5068
5072
|
}
|
|
5069
5073
|
});
|
|
5074
|
+
(Object.getOwnPropertyDescriptor(api_fake, "name") || {}).writable || Object.defineProperty(api_fake, "name", { value: "default", configurable: true });
|
|
5070
5075
|
function makeFakeConvo(accid, convoid, userid, agentid) {
|
|
5071
5076
|
let inteid = accid + '.subizv4.subikon';
|
|
5072
5077
|
return {
|
|
@@ -5365,6 +5370,7 @@ function makeFakeMessages(accid, convoid, userid, agentid) {
|
|
|
5365
5370
|
}
|
|
5366
5371
|
reconnect() {}
|
|
5367
5372
|
});
|
|
5373
|
+
(Object.getOwnPropertyDescriptor(realtime_fake, "name") || {}).writable || Object.defineProperty(realtime_fake, "name", { value: "default", configurable: true });
|
|
5368
5374
|
;// ./src/store/store.js
|
|
5369
5375
|
function store_defineProperty(e, r, t) { return (r = store_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5370
5376
|
function store_toPropertyKey(t) { var i = store_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
@@ -7820,6 +7826,7 @@ class MessageInput extends common/* Com */.Mw {
|
|
|
7820
7826
|
}, 500);
|
|
7821
7827
|
this.resizeInput = util/* default */.A.throttle(function () {
|
|
7822
7828
|
const input = this.refMessageInput.current;
|
|
7829
|
+
if (!input) return;
|
|
7823
7830
|
input.style.setProperty('height', '1em', 'important');
|
|
7824
7831
|
const height = Math.min(200, input.scrollHeight);
|
|
7825
7832
|
input.style.setProperty('height', `${height}px`, 'important');
|
|
@@ -12194,6 +12201,9 @@ function encode(key) {
|
|
|
12194
12201
|
// EXTERNAL MODULE: ./src/chatbox/css.js
|
|
12195
12202
|
var chatbox_css = __webpack_require__(9278);
|
|
12196
12203
|
;// ./src/chatbox/main.js
|
|
12204
|
+
function main_defineProperty(e, r, t) { return (r = main_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
12205
|
+
function main_toPropertyKey(t) { var i = main_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
12206
|
+
function main_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12197
12207
|
|
|
12198
12208
|
|
|
12199
12209
|
|
|
@@ -12203,6 +12213,10 @@ var chatbox_css = __webpack_require__(9278);
|
|
|
12203
12213
|
class Main extends common/* Com */.Mw {
|
|
12204
12214
|
constructor(props) {
|
|
12205
12215
|
super(props);
|
|
12216
|
+
main_defineProperty(this, "state", {
|
|
12217
|
+
cssReady: false,
|
|
12218
|
+
changing: false
|
|
12219
|
+
});
|
|
12206
12220
|
this.refButton = (0,preact_module/* createRef */._3)();
|
|
12207
12221
|
this.refWidget = (0,preact_module/* createRef */._3)();
|
|
12208
12222
|
}
|
|
@@ -12230,9 +12244,6 @@ class Main extends common/* Com */.Mw {
|
|
|
12230
12244
|
this.$cssStyleDiv.type = 'text/css';
|
|
12231
12245
|
this.$cssStyleDiv.id = 'subiz-style-for-' + this.props.plugin.id;
|
|
12232
12246
|
}
|
|
12233
|
-
this.setState({
|
|
12234
|
-
cssReady: false
|
|
12235
|
-
});
|
|
12236
12247
|
this.checkExpand();
|
|
12237
12248
|
this.props.store.onResetCSS(this, () => this.refreshCSS());
|
|
12238
12249
|
this.props.store.onConvoEvent(this, ev => this.onConvoEvent(ev));
|
|
@@ -12244,11 +12255,32 @@ class Main extends common/* Com */.Mw {
|
|
|
12244
12255
|
});
|
|
12245
12256
|
});
|
|
12246
12257
|
this.refreshCSS();
|
|
12258
|
+
let lastview = this.props.store.matchLastview() || {};
|
|
12259
|
+
let cid = util/* default */.A.get(lastview, 'opts.cid');
|
|
12260
|
+
if (cid) {
|
|
12261
|
+
this._last_cid = cid;
|
|
12262
|
+
this.setState({
|
|
12263
|
+
changing: true
|
|
12264
|
+
}, () => {
|
|
12265
|
+
this.props.store.fetchConvo(cid).then(() => {
|
|
12266
|
+
let convo = this.props.store.matchConvo(cid);
|
|
12267
|
+
if (cid != this._last_cid) return;
|
|
12268
|
+
this.setState({
|
|
12269
|
+
changing: false
|
|
12270
|
+
});
|
|
12271
|
+
if (!convo) return this.showWidget({});
|
|
12272
|
+
});
|
|
12273
|
+
});
|
|
12274
|
+
}
|
|
12247
12275
|
this.setState({
|
|
12248
12276
|
cssReady: true
|
|
12249
12277
|
});
|
|
12250
12278
|
}
|
|
12251
12279
|
render() {
|
|
12280
|
+
if (this.state.changing) {
|
|
12281
|
+
if (typeof sbz_info != 'undefined') sbz_info.render_chatbox_changing_ready = util/* default */.A.Date.now();
|
|
12282
|
+
return null;
|
|
12283
|
+
}
|
|
12252
12284
|
if (!this.state.cssReady) {
|
|
12253
12285
|
if (typeof sbz_info != 'undefined') sbz_info.render_chatbox_css_not_ready = util/* default */.A.Date.now();
|
|
12254
12286
|
return null;
|
|
@@ -12744,6 +12776,21 @@ class lib_Widget {
|
|
|
12744
12776
|
lib_defineProperty(this, "setViewingProduct", p => this.store.linkProduct(p));
|
|
12745
12777
|
lib_defineProperty(this, "getViewingProduct", () => this.store.getLinkedProduct());
|
|
12746
12778
|
lib_defineProperty(this, "track", v => this.store.track(v));
|
|
12779
|
+
lib_defineProperty(this, "event", async v => {
|
|
12780
|
+
await this.store.readyGate.entry();
|
|
12781
|
+
return this.store.api.sendEvent(v);
|
|
12782
|
+
});
|
|
12783
|
+
lib_defineProperty(this, "pageview", v => {
|
|
12784
|
+
v = v || {};
|
|
12785
|
+
return this.event({
|
|
12786
|
+
type: 'content_viewed',
|
|
12787
|
+
payload: {
|
|
12788
|
+
url: v.url || location.href,
|
|
12789
|
+
title: v.title || document.title,
|
|
12790
|
+
referrer: v.referrer || document.referrer
|
|
12791
|
+
}
|
|
12792
|
+
});
|
|
12793
|
+
});
|
|
12747
12794
|
this.impressionTokens = {};
|
|
12748
12795
|
this.domGate = new util/* default */.A.Gate();
|
|
12749
12796
|
this.store = new Store(ApiURL, FileURL, RealtimeURL, inmem, fake);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subiz/widget-v4",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.204",
|
|
4
4
|
"main": "./compiled_src/lib.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "npx webpack serve --config webpack.dev.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"babel-loader": "^10.1.1",
|
|
31
31
|
"babel-plugin-syntax-jsx": "^6.18.0",
|
|
32
32
|
"html-webpack-plugin": "^5.6.7",
|
|
33
|
-
"puppeteer": "^
|
|
34
|
-
"webpack": "^5.
|
|
33
|
+
"puppeteer": "^25.0.4",
|
|
34
|
+
"webpack": "^5.107.1",
|
|
35
35
|
"webpack-bundle-analyzer": "^5.3.0",
|
|
36
36
|
"webpack-cli": "^7.0.2",
|
|
37
37
|
"webpack-dev-server": "^5.2.4"
|
package/src/lib.js
CHANGED
|
@@ -317,21 +317,11 @@ class Widget {
|
|
|
317
317
|
getViewingProduct = () => this.store.getLinkedProduct()
|
|
318
318
|
|
|
319
319
|
track = (v) => this.store.track(v)
|
|
320
|
-
event = async (
|
|
320
|
+
event = async (type, payload, options) => {
|
|
321
321
|
await this.store.readyGate.entry()
|
|
322
|
-
return this.store.api.sendEvent(
|
|
323
|
-
}
|
|
324
|
-
pageview = (v) => {
|
|
325
|
-
v = v || {}
|
|
326
|
-
return this.event({
|
|
327
|
-
type: 'content_viewed',
|
|
328
|
-
payload: {
|
|
329
|
-
url: v.url || location.href,
|
|
330
|
-
title: v.title || document.title,
|
|
331
|
-
referrer: v.referrer || document.referrer,
|
|
332
|
-
},
|
|
333
|
-
})
|
|
322
|
+
return this.store.api.sendEvent(normalizeCdpEvent(type, payload, options))
|
|
334
323
|
}
|
|
324
|
+
pageview = (v) => this.store.sendPageview(v)
|
|
335
325
|
|
|
336
326
|
async setLocale(locale) {
|
|
337
327
|
await this.domGate.entry()
|
|
@@ -413,6 +403,15 @@ class Widget {
|
|
|
413
403
|
}
|
|
414
404
|
}
|
|
415
405
|
|
|
406
|
+
function normalizeCdpEvent(type, payload, options) {
|
|
407
|
+
if (type && typeof type === 'object') return type
|
|
408
|
+
|
|
409
|
+
let data = {type: type}
|
|
410
|
+
if (payload !== undefined) data.payload = payload
|
|
411
|
+
if (options && typeof options === 'object') data = Object.assign({}, options, data)
|
|
412
|
+
return data
|
|
413
|
+
}
|
|
414
|
+
|
|
416
415
|
// for debugging purpose
|
|
417
416
|
window.__sbz_WIDGET = Widget
|
|
418
417
|
export default Widget
|
package/src/store/store.js
CHANGED
|
@@ -76,6 +76,13 @@ export default class Store {
|
|
|
76
76
|
this.sendPresence()
|
|
77
77
|
})
|
|
78
78
|
window.addEventListener('beforeunload', () => this.api.sendLostFocus())
|
|
79
|
+
this._lastPresenceURL = window.location.href
|
|
80
|
+
this._urlCheckInterval = sb.setInterval(() => {
|
|
81
|
+
if (this._die) return sb.clearInterval(this._urlCheckInterval)
|
|
82
|
+
if (this._lastPresenceURL === window.location.href) return
|
|
83
|
+
this._lastPresenceURL = window.location.href
|
|
84
|
+
this.sendPresence()
|
|
85
|
+
}, 2_000)
|
|
79
86
|
|
|
80
87
|
this.doNotStartBot = () => {
|
|
81
88
|
this._donotstartbot = true
|
|
@@ -508,24 +515,16 @@ export default class Store {
|
|
|
508
515
|
submitForm2 = (accid, token, data) => this.api.submitForm2(accid, token, data)
|
|
509
516
|
sendPresence = sb.throttle(
|
|
510
517
|
async () => {
|
|
518
|
+
if (!this._track_page_view) return
|
|
511
519
|
if (this._die) return dieErr
|
|
512
520
|
await this.readyGate.entry()
|
|
513
521
|
if (!sb.get(this.cache.match('user'), 'id')) return // store not init
|
|
514
522
|
if (sb.isUserBanned(this.cache.match('user'))) return
|
|
515
523
|
|
|
516
|
-
if (!this._track_page_view) return
|
|
517
|
-
|
|
518
524
|
let hasfocus = this.browserVisibility === 'visible' && document.hasFocus()
|
|
519
525
|
if (!hasfocus) return this.api.sendLostFocus()
|
|
520
526
|
|
|
521
|
-
this.
|
|
522
|
-
this.device,
|
|
523
|
-
location.href,
|
|
524
|
-
document.title,
|
|
525
|
-
this._currentViewingProduct.id,
|
|
526
|
-
this._currentViewingProduct.source_id,
|
|
527
|
-
this._currentViewingProduct.sku,
|
|
528
|
-
)
|
|
527
|
+
this.sendPageview()
|
|
529
528
|
},
|
|
530
529
|
1000, // dont send presence update too tight
|
|
531
530
|
{leading: false}, // dont send right after load. should send after content_view
|
|
@@ -915,21 +914,30 @@ export default class Store {
|
|
|
915
914
|
this.pubsub.publish('account')
|
|
916
915
|
}
|
|
917
916
|
|
|
917
|
+
async sendPageview(p) {
|
|
918
|
+
if (!p) p = {}
|
|
919
|
+
let device = Object.assign({}, this.device)
|
|
920
|
+
if (p.referrer) device.source_referrer = p.referrer
|
|
921
|
+
device.page_url = p.url || location.href
|
|
922
|
+
device.page_title = p.title || document.title
|
|
923
|
+
return this.api.sendContentView(
|
|
924
|
+
device,
|
|
925
|
+
p.url || location.href,
|
|
926
|
+
p.title || document.title,
|
|
927
|
+
this._currentViewingProduct.id,
|
|
928
|
+
this._currentViewingProduct.source_id,
|
|
929
|
+
this._currentViewingProduct.sku,
|
|
930
|
+
)
|
|
931
|
+
}
|
|
932
|
+
|
|
918
933
|
// send the content view, the first presence and record domain
|
|
919
934
|
async track(e) {
|
|
920
935
|
if (!e) {
|
|
921
|
-
let out = await this.
|
|
922
|
-
this.device,
|
|
923
|
-
location.href,
|
|
924
|
-
document.title,
|
|
925
|
-
this._currentViewingProduct.id,
|
|
926
|
-
this._currentViewingProduct.source_id,
|
|
927
|
-
this._currentViewingProduct.sku,
|
|
928
|
-
)
|
|
936
|
+
let out = await this.sendPageview()
|
|
929
937
|
|
|
930
938
|
let traffic_source = sb.get(out, 'body.by.device.source', '')
|
|
931
939
|
if (traffic_source) this.kv.put('traffic_source', traffic_source)
|
|
932
|
-
return
|
|
940
|
+
return out
|
|
933
941
|
}
|
|
934
942
|
|
|
935
943
|
if (typeof e === 'object') {
|
|
@@ -1501,6 +1509,7 @@ export default class Store {
|
|
|
1501
1509
|
this._die = true
|
|
1502
1510
|
this.clearBrowserData()
|
|
1503
1511
|
sb.clearInterval(this._seenInterval)
|
|
1512
|
+
sb.clearInterval(this._urlCheckInterval)
|
|
1504
1513
|
if (this.realtime) this.realtime.stop()
|
|
1505
1514
|
this.readyGate.close()
|
|
1506
1515
|
window.removeEventListener('blur', this.sendPresence)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var test = require('tape')
|
|
2
|
+
var {normalizeCdpEvent} = require('./event.js')
|
|
3
|
+
|
|
4
|
+
test('normalize cdp event new signature', (t) => {
|
|
5
|
+
t.deepEqual(
|
|
6
|
+
normalizeCdpEvent('content_viewed', {
|
|
7
|
+
url: 'https://example.com/products/pd2345',
|
|
8
|
+
title: 'Bàn phím cơ không dây',
|
|
9
|
+
}, {event_source_id: 'evt_1234'}),
|
|
10
|
+
{
|
|
11
|
+
type: 'content_viewed',
|
|
12
|
+
payload: {
|
|
13
|
+
url: 'https://example.com/products/pd2345',
|
|
14
|
+
title: 'Bàn phím cơ không dây',
|
|
15
|
+
},
|
|
16
|
+
event_source_id: 'evt_1234',
|
|
17
|
+
},
|
|
18
|
+
)
|
|
19
|
+
t.end()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('normalize cdp event without payload', (t) => {
|
|
23
|
+
t.deepEqual(normalizeCdpEvent('login'), {type: 'login'})
|
|
24
|
+
t.end()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('normalize cdp event keeps old object signature', (t) => {
|
|
28
|
+
let event = {type: 'product_viewed', payload: {id: 'pd2345'}}
|
|
29
|
+
t.equal(normalizeCdpEvent(event), event)
|
|
30
|
+
t.end()
|
|
31
|
+
})
|