@subiz/widget-v4 4.1.1 → 4.1.4

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 (45) hide show
  1. package/compiled_src/chatbox/ChatButton.js +25 -0
  2. package/compiled_src/lib.js +18 -3
  3. package/compiled_src/store/api.js +116 -108
  4. package/compiled_src/store/api_fake.js +4 -5
  5. package/compiled_src/store/store.js +51 -36
  6. package/compiled_src/util/common.js +1 -1
  7. package/dist/132.js +30 -1
  8. package/dist/185588facf6.132.js +1 -0
  9. package/dist/{184d8eee275.178.js → 185588facf6.178.js} +0 -0
  10. package/dist/{184d8eee275.213.js → 185588facf6.213.js} +0 -0
  11. package/dist/{184d8eee275.335.js → 185588facf6.335.js} +0 -0
  12. package/dist/{184d8eee275.362.js → 185588facf6.362.js} +0 -0
  13. package/dist/185588facf6.441.js +1 -0
  14. package/dist/{184d8eee275.605.js → 185588facf6.605.js} +0 -0
  15. package/dist/{184d8eee275.678.js → 185588facf6.678.js} +0 -0
  16. package/dist/{184d8eee275.782.js → 185588facf6.782.js} +0 -0
  17. package/dist/185588facf6.app.js +1 -0
  18. package/dist/{184d8eee275.index.html → 185588facf6.index.html} +1 -1
  19. package/dist/{184d8eee275.library.html → 185588facf6.library.html} +1 -1
  20. package/dist/185588facf6.library.js +1 -0
  21. package/dist/{184d8eee275.preview.html → 185588facf6.preview.html} +1 -1
  22. package/dist/185588facf6.preview.js +1 -0
  23. package/dist/185588facf6.screenshoot.js +1 -0
  24. package/dist/185588facf6.webview.js +1 -0
  25. package/dist/441.js +51 -36
  26. package/dist/HASH +1 -1
  27. package/dist/screenshoot.html +1 -1
  28. package/dist/screenshoot.js +230 -195
  29. package/inject.js +2 -6
  30. package/package.json +9 -8
  31. package/src/chatbox/ChatButton.js +30 -0
  32. package/src/lib.js +23 -3
  33. package/src/store/api.js +139 -114
  34. package/src/store/api_fake.js +1 -2
  35. package/src/store/store.js +54 -45
  36. package/src/util/common.js +1 -1
  37. package/webpack.dev.js +1 -0
  38. package/webpack.prod.js +1 -0
  39. package/webview.js +43 -0
  40. package/dist/184d8eee275.132.js +0 -1
  41. package/dist/184d8eee275.441.js +0 -1
  42. package/dist/184d8eee275.app.js +0 -1
  43. package/dist/184d8eee275.library.js +0 -1
  44. package/dist/184d8eee275.preview.js +0 -1
  45. package/dist/184d8eee275.screenshoot.js +0 -1
@@ -560,7 +560,7 @@ function Conn(apiUrl, credential, onDead, onEvents, callAPI) {
560
560
  var lastToken = ''
561
561
 
562
562
  // kill force the connection to dead state
563
- this.kill = function() {
563
+ this.kill = function () {
564
564
  dead = true
565
565
  }
566
566
 
@@ -569,9 +569,9 @@ function Conn(apiUrl, credential, onDead, onEvents, callAPI) {
569
569
  // exponential backoff algorithm. Polling loop will terminate if it encounter an
570
570
  // un-retryable error
571
571
  // the polling loop starts after the first subscribe call finished successfully
572
- var polling = function(backoff) {
572
+ var polling = function (backoff) {
573
573
  if (dead) return
574
- callAPI('get', apiUrl + 'poll?token=' + lastToken, undefined, function(body, code) {
574
+ callAPI('get', apiUrl + 'poll?token=' + lastToken, undefined, function (body, code) {
575
575
  if (dead) return
576
576
  if (retryable(code)) return setTimeout(polling, calcNextBackoff(backoff), backoff + 1)
577
577
  if (code !== 200) {
@@ -593,20 +593,26 @@ function Conn(apiUrl, credential, onDead, onEvents, callAPI) {
593
593
  })
594
594
  }
595
595
 
596
- var subQueue = flow.batch(50, 100, function(events) {
596
+ var subQueue = flow.batch(50, 100, function (events) {
597
597
  if (dead) return ['dead']
598
598
  if (events.length <= 0) return []
599
599
 
600
600
  var out = []
601
601
  return flow
602
- .loop(function() {
603
- return new Promise(function(rs) {
602
+ .loop(function () {
603
+ return new Promise(function (rs) {
604
604
  var query = '?token=' + lastToken
605
- credential.getAccessToken().then(function(access_token) {
606
- if (credential.user_mask) query += '&user-mask=' + encodeURIComponent(credential.user_mask)
605
+ credential.getAccessToken().then(function (access_token) {
606
+ if (credential.user_ref)
607
+ query +=
608
+ '&user_ref=' +
609
+ encodeURIComponent(credential.user_ref) +
610
+ '&account_id=' +
611
+ encodeURIComponent(credential.account_id)
612
+ else if (credential.user_mask) query += '&user-mask=' + encodeURIComponent(credential.user_mask)
607
613
  else if (access_token) query += '&access-token=' + access_token
608
614
 
609
- callAPI('post', apiUrl + 'subs' + query, JSON.stringify({events: events}), function(body, code) {
615
+ callAPI('post', apiUrl + 'subs' + query, JSON.stringify({events: events}), function (body, code) {
610
616
  if (dead) {
611
617
  out = repeat('dead', events.length)
612
618
  return rs(false) // break loop
@@ -639,7 +645,7 @@ function Conn(apiUrl, credential, onDead, onEvents, callAPI) {
639
645
  })
640
646
  })
641
647
  })
642
- .then(function() {
648
+ .then(function () {
643
649
  return out
644
650
  })
645
651
  })
@@ -661,7 +667,7 @@ function Realtime(apiUrls, credential, callAPI) {
661
667
  if (typeof apiUrls === 'string' || apiUrls instanceof String) apiUrls = [apiUrls]
662
668
  credential = credential || {}
663
669
  if (!credential.getAccessToken) {
664
- credential.getAccessToken = function() {
670
+ credential.getAccessToken = function () {
665
671
  return Promise.resolve('')
666
672
  }
667
673
  }
@@ -678,22 +684,22 @@ function Realtime(apiUrls, credential, callAPI) {
678
684
 
679
685
  // stop the connection
680
686
  var stop = false
681
- this.stop = function() {
687
+ this.stop = function () {
682
688
  if (stop) return
683
689
  stop = true
684
690
  conn.kill()
685
691
  }
686
692
 
687
- this.onEvent = function(cb) {
693
+ this.onEvent = function (cb) {
688
694
  return pubsub.on('event', cb)
689
695
  }
690
696
 
691
- this.onInterrupted = function(cb) {
697
+ this.onInterrupted = function (cb) {
692
698
  return pubsub.on('interrupted', cb)
693
699
  }
694
700
 
695
701
  var conn
696
- this.subscribe = function(events) {
702
+ this.subscribe = function (events) {
697
703
  if (stop) return Promise.resolve({})
698
704
  if (typeof events === 'string') events = [events]
699
705
  if (!Array.isArray(events)) return Promise.resolve({error: 'param should be an array or string'})
@@ -706,7 +712,7 @@ function Realtime(apiUrls, credential, callAPI) {
706
712
  if (!topics[topic]) all.push(conn.subscribe(topic))
707
713
  }
708
714
  if (all.length === 0) return Promise.resolve({})
709
- return Promise.all(all).then(function(errs) {
715
+ return Promise.all(all).then(function (errs) {
710
716
  for (var i = 0; i < errs.length; i++) if (errs[i]) return {error: errs[i]}
711
717
  for (var j = 0; j < events.length; j++) topics[events[j]] = true
712
718
  return {}
@@ -715,7 +721,7 @@ function Realtime(apiUrls, credential, callAPI) {
715
721
 
716
722
  // reconnect make sure there is alway a Conn running in the background
717
723
  // if the Conn is dead, it recreate a new one
718
- var reconnect = function() {
724
+ var reconnect = function () {
719
725
  if (stop) return
720
726
  // reset subscribed topic
721
727
  var allTopics = Object.keys(topics)
@@ -725,12 +731,12 @@ function Realtime(apiUrls, credential, callAPI) {
725
731
  conn = new Conn(
726
732
  randomUrl,
727
733
  credential,
728
- function(code, body, status) {
734
+ function (code, body, status) {
729
735
  if (stop) return
730
736
  pubsub.emit('interrupted', code, body, status)
731
737
  setTimeout(reconnect, 2000) // reconnect and resubscribe after 2 sec
732
738
  },
733
- function(topics) {
739
+ function (topics) {
734
740
  if (stop) return
735
741
  for (var i = 0; i < topics.length; i++) pubsub.emit('event', topics[i])
736
742
  },
@@ -744,7 +750,7 @@ function Realtime(apiUrls, credential, callAPI) {
744
750
  reconnect()
745
751
  }
746
752
 
747
- var dofetch = function(method, url, body, cb) {
753
+ var dofetch = function (method, url, body, cb) {
748
754
  let headers = {}
749
755
  if (body) headers['content-type'] = 'text/plain'
750
756
  fetch(url, {
@@ -756,16 +762,16 @@ var dofetch = function(method, url, body, cb) {
756
762
  .catch((err) => cb && cb(err, -1))
757
763
  }
758
764
  // xhrsend sends an HTTP request
759
- var xhrsend = function(method, url, body, cb) {
765
+ var xhrsend = function (method, url, body, cb) {
760
766
  if (typeof XMLHttpRequest === 'undefined') return dofetch(method, url, body, cb)
761
767
  var request = new XMLHttpRequest()
762
- request.onreadystatechange = function(e) {
768
+ request.onreadystatechange = function (e) {
763
769
  if (request.readyState !== 4) return
764
770
  cb && cb(request.responseText, request.status)
765
771
  cb = undefined // dont call cb anymore
766
772
  }
767
773
 
768
- request.onerror = function() {
774
+ request.onerror = function () {
769
775
  cb && cb(request.responseText, -1) // network error
770
776
  cb = undefined // dont call cb anymore
771
777
  }
@@ -793,7 +799,7 @@ function Pubsub() {
793
799
 
794
800
  // emit notifies any callback functions that previously
795
801
  // subscribed to the topic (by the on function)
796
- this.emit = function(topic) {
802
+ this.emit = function (topic) {
797
803
  // skip the first item in arguments, which is the topic
798
804
  var args = []
799
805
  for (var i = 1; i < arguments.length; i++) args.push(arguments[i])
@@ -806,7 +812,7 @@ function Pubsub() {
806
812
  // register a callback function for a topic
807
813
  // when something is sent to the topic (by the emit function),
808
814
  // the callback function will be called
809
- this.on = function(topic, cb) {
815
+ this.on = function (topic, cb) {
810
816
  if (!listeners[topic]) listeners[topic] = []
811
817
  listeners[topic].push(cb)
812
818
  }
@@ -1704,7 +1710,7 @@ function orderBy(a, k, d) {
1704
1710
  return clone;
1705
1711
  }
1706
1712
  function isPhone(phone) {
1707
- var re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;
1713
+ var re = /^[\+]?[(]?[0-9]{2,3}[)]?[-\s\.]?[0-9]{3,4}[-\s\.]?[0-9]{4,6}$/im;
1708
1714
  return re.test(String(phone));
1709
1715
  }
1710
1716
  function isURL(url) {
@@ -3359,7 +3365,6 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
3359
3365
 
3360
3366
  const ajax = __webpack_require__(7460);
3361
3367
  ajax.env.XMLHttpRequest = window.XMLHttpRequest;
3362
- const findAnswer = challenge => challenge.answer;
3363
3368
  function jsonifyTextPlain(param, done) {
3364
3369
  let req = param.request;
3365
3370
  if (req.content_type === 'text/plain' && req.body !== undefined) req.body = util/* default.stringify */.Z.stringify(req.body);
@@ -3367,8 +3372,8 @@ function jsonifyTextPlain(param, done) {
3367
3372
  }
3368
3373
  /* harmony default export */ const api = (class {
3369
3374
  constructor(ApiURL, FileURL) {
3370
- _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get('/conversations'));
3371
- _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/conversations/${cid}/messages`));
3375
+ _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`));
3376
+ _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/accounts/${this.accid}/conversations/${cid}/messages`));
3372
3377
  _defineProperty(this, "ajax", ajax);
3373
3378
  _defineProperty(this, "start", extraData => {
3374
3379
  let data = {
@@ -3382,16 +3387,16 @@ function jsonifyTextPlain(param, done) {
3382
3387
  util/* default.each */.Z.each(extraData, (v, k) => {
3383
3388
  data[k] = v;
3384
3389
  });
3385
- return this.apireq.post('/conversations', data);
3390
+ return this.apireq.post(`/accounts/${this.accid}/conversations`, data);
3386
3391
  });
3387
3392
  _defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));
3388
3393
  _defineProperty(this, "createPostback", (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p));
3389
- _defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/receive`));
3390
- _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/seen`));
3391
- _defineProperty(this, "getConversation", cid => this.apireq.get(`/conversations/${cid}`));
3394
+ _defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/receive`));
3395
+ _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/seen`));
3396
+ _defineProperty(this, "getConversation", cid => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`));
3392
3397
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
3393
- _defineProperty(this, "sendEvent", data => this.apireq.post(`/users/${this.uid}/events`, data));
3394
- _defineProperty(this, "sendTyping", cid => this.apireq.post(`/conversations/${cid}/typing`));
3398
+ _defineProperty(this, "sendEvent", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
3399
+ _defineProperty(this, "sendTyping", cid => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`));
3395
3400
  _defineProperty(this, "sendLostFocus", (device, productid, source_id, sku) => this.sendEvent({
3396
3401
  by: {
3397
3402
  id: this.uid,
@@ -3443,9 +3448,8 @@ function jsonifyTextPlain(param, done) {
3443
3448
  url: this.FileURL + body.url
3444
3449
  };
3445
3450
  });
3446
- _defineProperty(this, "getChallenge", accid => this.apireq.post(`/accounts/${accid}/scrypt-challenges`));
3447
- _defineProperty(this, "time", _ => this.apireq.get('/time'));
3448
- _defineProperty(this, "updateUser", data => this.apireq.post(`/users/${this.uid}`, data));
3451
+ _defineProperty(this, "time", _ => ajax.setBaseUrl(this.ApiURL).withCredentials(true).setParser('json').get('/time'));
3452
+ _defineProperty(this, "updateUser", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data));
3449
3453
  _defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
3450
3454
  _defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
3451
3455
  _defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
@@ -3477,99 +3481,130 @@ function jsonifyTextPlain(param, done) {
3477
3481
  });
3478
3482
  return;
3479
3483
  }
3480
- if (this.mask) param.request = param.request.addQuery('x-user-mask', this.mask);
3484
+ if (this.ref) param.request = param.request.addQuery('x-user-ref', this.ref);else if (this.mask) param.request = param.request.addQuery('x-user-mask', this.mask);
3481
3485
  return done(true);
3482
3486
  });
3483
3487
  }
3484
3488
  setAgentId(agid) {
3485
3489
  this.agentid = agid;
3486
3490
  }
3487
- setAuth(obj) {
3488
- this.accid = obj.accid;
3491
+ async setAuth(obj) {
3492
+ if (obj.accid) this.accid = obj.accid;
3493
+ if (obj.ref) this.ref = obj.ref;
3489
3494
  this.mask = obj.mask;
3490
- this.uid = obj.uid;
3491
- }
3492
- async setTokenGenerator(accid, uid, tokenGenerator) {
3493
- this.tokensession = this.tokensession || 0;
3494
- this.tokensession++;
3495
- let tokensession = this.tokensession;
3496
- if (!accid || !util/* default.startsWith */.Z.startsWith(accid, 'ac')) return {
3497
- error: 'invalid_account_id'
3498
- };
3499
- if (!uid) return {
3500
- error: 'invalid_user_id'
3501
- };
3502
- if (typeof tokenGenerator !== 'function') return {
3503
- error: 'invalid_token_generator'
3504
- };
3505
- this.accid = accid;
3506
- this.profile_id = uid;
3507
- this.token_generator = async force => {
3508
- await this.refreshLock.lock();
3509
- if (tokensession != this.tokensession) {
3510
- this.refreshLock.unlock();
3511
- return;
3495
+ this.profile_id = obj.profile_id;
3496
+ if (obj.ref) {
3497
+ let outuser;
3498
+ for (let i = 0; true; i++) {
3499
+ outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-user-ref', this.ref).setParser('json').get(`/accounts/${this.accid}/users/${this.ref}`);
3500
+ if (!util/* default.get */.Z.get(outuser, 'body.id')) {
3501
+ let sleeptime = Math.min(2000 + i * 200, 60000);
3502
+ await util/* default.sleep */.Z.sleep(sleeptime);
3503
+ continue;
3504
+ }
3505
+ break;
3512
3506
  }
3513
- let age = (util/* default.Date.now */.Z.Date.now() - (this.last_token_at || 0)) / 1000;
3514
- if (!force && this.last_token && age < 1800) {
3515
- this.refreshLock.unlock();
3516
- return this.last_token;
3507
+ if (outuser.error) {
3508
+ if (util/* default.get */.Z.get(outuser.body.code)) return {
3509
+ error: outuser.body.code
3510
+ };
3511
+ return outuser;
3517
3512
  }
3518
- if (!force && this.last_token && age < 3000) {
3519
- if (this.token_generator) setTimeout(async () => {
3520
- let token, err;
3521
- try {
3522
- token = await tokenGenerator(uid);
3523
- } catch (e) {
3524
- err = e;
3525
- }
3526
- if (tokensession != this.tokensession) {
3513
+ this.uid = outuser.body.id;
3514
+ return outuser.body;
3515
+ }
3516
+ if (obj.tokenGenerator) {
3517
+ this.tokensession = this.tokensession || 0;
3518
+ this.tokensession++;
3519
+ let tokensession = this.tokensession;
3520
+ if (!this.accid || !util/* default.startsWith */.Z.startsWith(this.accid, 'ac')) return {
3521
+ error: 'invalid_account_id'
3522
+ };
3523
+ if (!this.profile_id) return {
3524
+ error: 'invalid_profile_id'
3525
+ };
3526
+ if (typeof this.tokenGenerator !== 'function') return {
3527
+ error: 'invalid_token_generator'
3528
+ };
3529
+ let profile_id = this.profile_id;
3530
+ this.token_generator = async force => {
3531
+ await this.refreshLock.lock();
3532
+ if (tokensession != this.tokensession) {
3533
+ this.refreshLock.unlock();
3534
+ return;
3535
+ }
3536
+ let age = (util/* default.Date.now */.Z.Date.now() - (this.last_token_at || 0)) / 1000;
3537
+ if (!force && this.last_token && age < 1800) {
3538
+ this.refreshLock.unlock();
3539
+ return this.last_token;
3540
+ }
3541
+ if (!force && this.last_token && age < 3000) {
3542
+ if (this.token_generator) setTimeout(async () => {
3543
+ let token, err;
3544
+ try {
3545
+ token = await tokenGenerator(profile_id);
3546
+ } catch (e) {
3547
+ err = e;
3548
+ }
3549
+ if (tokensession != this.tokensession) {
3550
+ this.refreshLock.unlock();
3551
+ return;
3552
+ }
3553
+ if (err) this.last_token = 'error';else this.last_token = token;
3554
+ this.last_token_at = util/* default.Date.now */.Z.Date.now();
3527
3555
  this.refreshLock.unlock();
3528
- return;
3529
- }
3530
- if (err) this.last_token = 'error';else this.last_token = token;
3531
- this.last_token_at = util/* default.Date.now */.Z.Date.now();
3556
+ });
3557
+ return this.last_token;
3558
+ }
3559
+ let token;
3560
+ let err;
3561
+ try {
3562
+ token = await tokenGenerator(profile_id);
3563
+ } catch (e) {
3564
+ err = e;
3565
+ }
3566
+ if (tokensession != this.tokensession) {
3532
3567
  this.refreshLock.unlock();
3533
- });
3534
- return this.last_token;
3535
- }
3536
- let token;
3537
- let err;
3538
- try {
3539
- token = await tokenGenerator(uid);
3540
- } catch (e) {
3541
- err = e;
3542
- }
3543
- if (tokensession != this.tokensession) {
3568
+ return;
3569
+ }
3570
+ if (err) this.last_token = 'error';else this.last_token = token;
3571
+ this.last_token_at = util/* default.Date.now */.Z.Date.now();
3544
3572
  this.refreshLock.unlock();
3545
- return;
3573
+ return this.last_token;
3574
+ };
3575
+ let outuser;
3576
+ for (let i = 0; true; i++) {
3577
+ await this.token_generator(true);
3578
+ if (tokensession != this.tokensession) break;
3579
+ outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-access-token', this.last_token).setParser('json').get(`/accounts/${accid}/users/${profile_id}`);
3580
+ if (!util/* default.get */.Z.get(outuser, 'body.id')) {
3581
+ let sleeptime = Math.min(2000 + i * 100, 120000);
3582
+ await util/* default.sleep */.Z.sleep(sleeptime);
3583
+ continue;
3584
+ }
3585
+ break;
3546
3586
  }
3547
- if (err) this.last_token = 'error';else this.last_token = token;
3548
- this.last_token_at = util/* default.Date.now */.Z.Date.now();
3549
- this.refreshLock.unlock();
3550
- return this.last_token;
3551
- };
3552
- let outuser;
3553
- for (let i = 0; true; i++) {
3554
- await this.token_generator(true);
3555
- if (tokensession != this.tokensession) break;
3556
- 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}`);
3557
- if (!util/* default.get */.Z.get(outuser, 'body.id')) {
3558
- let sleeptime = Math.min(2000 + i * 100, 120000);
3559
- await util/* default.sleep */.Z.sleep(sleeptime);
3560
- continue;
3587
+ if (outuser.error) {
3588
+ if (util/* default.get */.Z.get(outuser.body.code)) return {
3589
+ error: outuser.body.code
3590
+ };
3591
+ return outuser;
3561
3592
  }
3562
- break;
3593
+ this.uid = outuser.body.id;
3594
+ return outuser.body;
3563
3595
  }
3564
- if (outuser.error) {
3565
- if (util/* default.get */.Z.get(outuser.body.code)) return {
3566
- error: outuser.body.code
3596
+ if (this.mask) {
3597
+ let parts = this.mask.split('@');
3598
+ this.uid = parts[1];
3599
+ return {
3600
+ id: this.uid
3567
3601
  };
3568
- return outuser;
3569
3602
  }
3570
- this.uid = outuser.body.id;
3571
- return outuser.body;
3603
+ return {
3604
+ error: 'invalid_auth'
3605
+ };
3572
3606
  }
3607
+ async setTokenGenerator(accid, uid, tokenGenerator) {}
3573
3608
  sendContentView(device, pageUrl, pageTitle, id, source_id, sku) {
3574
3609
  if (!id) id = undefined;
3575
3610
  if (!source_id) source_id = undefined;
@@ -3591,27 +3626,6 @@ function jsonifyTextPlain(param, done) {
3591
3626
  }
3592
3627
  });
3593
3628
  }
3594
- async createUser(accid) {
3595
- for (var i = 0; i < 10; i++) {
3596
- const {
3597
- body: challenge
3598
- } = await this.getChallenge(accid);
3599
- const answer = findAnswer(challenge);
3600
- const data = {
3601
- challenge_id: challenge.id,
3602
- answer: '' + answer
3603
- };
3604
- let {
3605
- body: user,
3606
- error
3607
- } = await this.apireq.post(`/accounts/${accid}/scrypt-challenges/users`, data);
3608
- if (error) {
3609
- await util/* default.sleep */.Z.sleep(1000);
3610
- continue;
3611
- }
3612
- return user;
3613
- }
3614
- }
3615
3629
  });
3616
3630
  ;// CONCATENATED MODULE: ./src/store/api_fake.js
3617
3631
  function api_fake_defineProperty(obj, key, value) { key = api_fake_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -3620,7 +3634,7 @@ function api_fake_toPrimitive(input, hint) { if (typeof input !== "object" || in
3620
3634
 
3621
3635
  const api_fake_ajax = __webpack_require__(7460);
3622
3636
  api_fake_ajax.env.XMLHttpRequest = window.XMLHttpRequest;
3623
- const api_fake_findAnswer = challenge => challenge.answer;
3637
+ const findAnswer = challenge => challenge.answer;
3624
3638
  function api_fake_jsonifyTextPlain(param, done) {
3625
3639
  let req = param.request;
3626
3640
  if (req.content_type === 'text/plain' && req.body !== undefined) req.body = util/* default.stringify */.Z.stringify(req.body);
@@ -3665,11 +3679,6 @@ const OK200 = Promise.resolve({
3665
3679
  api_fake_defineProperty(this, "sendContent", data => OK200);
3666
3680
  api_fake_defineProperty(this, "uploadToS3", async file => OK200);
3667
3681
  api_fake_defineProperty(this, "getChallenge", accid => OK200);
3668
- api_fake_defineProperty(this, "createUser", accid => Promise.resolve({
3669
- account_id: accid,
3670
- id: 'usqzgtgfake',
3671
- mask: 'fakemask'
3672
- }));
3673
3682
  api_fake_defineProperty(this, "time", _ => Promise.resolve({
3674
3683
  code: 200,
3675
3684
  body: new util/* default.Date */.Z.Date().toISOString()
@@ -3698,6 +3707,10 @@ const OK200 = Promise.resolve({
3698
3707
  this.accid = obj.accid;
3699
3708
  this.mask = obj.mask;
3700
3709
  this.uid = obj.uid;
3710
+ return {
3711
+ account_id: accid,
3712
+ id: 'usqzgtgfake'
3713
+ };
3701
3714
  }
3702
3715
  });
3703
3716
  function makeFakeConvo(accid, convoid, userid, agentid) {
@@ -4179,6 +4192,14 @@ class Store {
4179
4192
  this.fake = fakeapi;
4180
4193
  this.FileURL = FileURL;
4181
4194
  if (this.fake) this.api = new api_fake(ApiURL, FileURL);else this.api = new api(ApiURL, FileURL);
4195
+ if (!inmem) {
4196
+ try {
4197
+ document.cookie;
4198
+ localStorage;
4199
+ } catch (e) {
4200
+ inmem = true;
4201
+ }
4202
+ }
4182
4203
  if (inmem) {
4183
4204
  this.inmem = inmem;
4184
4205
  this.cookie = inmemCookie;
@@ -4318,58 +4339,64 @@ class Store {
4318
4339
  await this.readyGate.entry();
4319
4340
  if (!this.isInsync('account')) this.reconnect();
4320
4341
  }
4321
- async init(accid, mask) {
4342
+ async init(accid, mask, userRef) {
4322
4343
  this.readyGate.close();
4323
4344
  accid = (accid || '').trim();
4324
4345
  this.api.setAuth({
4325
4346
  accid: accid
4326
4347
  });
4327
4348
  this.g_sync = {};
4328
- if (!mask) {
4349
+ if (!userRef) {
4329
4350
  try {
4330
- mask = this.cookie.get('__sbmask', '');
4351
+ userRef = this.cookie.get('__sbref', '');
4331
4352
  } catch (e) {}
4353
+ if (!userRef) {
4354
+ if (!mask) {
4355
+ try {
4356
+ mask = this.cookie.get('__sbmask', '');
4357
+ } catch (e) {}
4358
+ }
4359
+ if (mask) {
4360
+ let parts = mask.split('@');
4361
+ if (parts[0] != accid) {
4362
+ userRef = util/* default.randomString */.Z.randomString(40);
4363
+ this.new_visitor = true;
4364
+ }
4365
+ this.new_visitor = false;
4366
+ this.cookie.set('__sbmask', mask);
4367
+ } else {
4368
+ userRef = util/* default.randomString */.Z.randomString(40);
4369
+ this.new_visitor = true;
4370
+ }
4371
+ }
4332
4372
  }
4333
- let localstorageMask = this.kv.match('mask');
4334
- if (!mask && localstorageMask) mask = localstorageMask;
4335
- if (mask && localstorageMask && mask !== localstorageMask) this.clearBrowserData();
4336
- var userId = '';
4337
- if (mask) {
4338
- let parts = mask.split('@');
4339
- if (parts[0] != accid) {
4340
- mask = '';
4341
- this.clearBrowserData();
4342
- } else userId = parts[1];
4343
- }
4344
- if (!mask) {
4345
- let user = await this.api.createUser(accid);
4346
- this.new_visitor = true;
4347
- mask = user.mask;
4348
- userId = user.id;
4349
- } else {
4350
- this.new_visitor = false;
4351
- }
4352
- this.cookie.set('__sbmask', mask);
4353
- this.kv.put('mask', mask);
4373
+ if (userRef) this.cookie.set('__sbref', userRef);
4374
+ let user = await this.api.setAuth({
4375
+ accid: accid,
4376
+ mask: mask,
4377
+ ref: userRef
4378
+ });
4379
+ if (user.error) return;
4354
4380
  if (this.realtime) this.realtime.stop();
4355
4381
  if (this.fake) this.realtime = new realtime_fake();else this.realtime = new Realtime(this.RealtimeURL, {
4382
+ account_id: accid,
4383
+ user_ref: userRef,
4356
4384
  user_mask: mask
4357
4385
  });
4358
4386
  this.realtime.onEvent(this.onWs.bind(this));
4359
- this.realtime.onInterrupted(() => this.reconnectWs(accid, userId));
4360
- this.api.setAuth({
4361
- accid: accid,
4362
- uid: userId,
4363
- mask: mask
4364
- });
4387
+ this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id));
4365
4388
  this.seenLoop();
4366
4389
  await this.reconnect();
4367
4390
  this.readyGate.open();
4368
- this.reconnectWs(accid, userId);
4369
- return mask;
4391
+ this.reconnectWs(accid, user.id);
4392
+ return user;
4370
4393
  }
4371
4394
  async login(accid, user_id, tokenGenerator) {
4372
- let user = await this.api.setTokenGenerator(accid, user_id, tokenGenerator);
4395
+ let user = await this.api.setAuth({
4396
+ accid: accid,
4397
+ profile_id: user_id,
4398
+ tokenGenerator: tokenGenerator
4399
+ });
4373
4400
  if (user.error) return user;
4374
4401
  this.clearBrowserData();
4375
4402
  this.readyGate.close();
@@ -4388,8 +4415,10 @@ class Store {
4388
4415
  this.reconnectWs(accid, user.id);
4389
4416
  return user;
4390
4417
  }
4391
- logout(user_id) {
4392
- this.api.setTokenGenerator(undefined, undefined, undefined);
4418
+ logout(userRef) {
4419
+ return this.api.setAuth({
4420
+ ref: userRef
4421
+ });
4393
4422
  }
4394
4423
  seenLoop() {
4395
4424
  this.seenQueue = [];
@@ -4409,7 +4438,7 @@ class Store {
4409
4438
  this.api.markAsSeen(id, lastmsgsent.id);
4410
4439
  let convo = this.cache.match('convo_' + id) || {};
4411
4440
  let mem = util/* default.find */.Z.find(convo.members, m => m.id === user.id);
4412
- mem.seen_at = Date.now();
4441
+ if (mem) mem.seen_at = Date.now();
4413
4442
  this._setConvo(convo);
4414
4443
  this.g_haveSentSeenM[lastmsgsent.id] = true;
4415
4444
  });
@@ -5351,9 +5380,6 @@ class Widget {
5351
5380
  lib_defineProperty(this, "setSetting", setting => this.store.setSetting({
5352
5381
  account_setting: setting
5353
5382
  }));
5354
- lib_defineProperty(this, "getSetting", _ => ({
5355
- account_setting: util/* default.cloneDeep */.Z.cloneDeep(this.store.matchAccountSetting())
5356
- }));
5357
5383
  lib_defineProperty(this, "getUser", () => util/* default.parseJSON */.Z.parseJSON(util/* default.stringify */.Z.stringify(this.store.matchUser())));
5358
5384
  lib_defineProperty(this, "setViewingProduct", p => this.store.linkProduct(p));
5359
5385
  lib_defineProperty(this, "getViewingProduct", () => this.store.getLinkedProduct());
@@ -5366,16 +5392,6 @@ class Widget {
5366
5392
  _isMounted: true
5367
5393
  }, ev => util/* default.map */.Z.map(this.subs, sub => sub(ev)));
5368
5394
  }
5369
- setLang(obj) {
5370
- var xhttp = new XMLHttpRequest();
5371
- xhttp.open('GET', 'https://api.sbz.vn/4.0/oldlang', true);
5372
- xhttp.send();
5373
- }
5374
- toggleLangDebugMode() {
5375
- var xhttp = new XMLHttpRequest();
5376
- xhttp.open('GET', 'https://api.sbz.vn/4.0/oldlangdebug', true);
5377
- xhttp.send();
5378
- }
5379
5395
  async waitReady(cb) {
5380
5396
  await this.store.readyGate.entry();
5381
5397
  cb();
@@ -5393,12 +5409,27 @@ class Widget {
5393
5409
  this.domGate.open();
5394
5410
  return user;
5395
5411
  }
5396
- logout(accid) {
5397
- return this.store.logout();
5412
+ logout(userref) {
5413
+ return this.store.logout(userref);
5414
+ }
5415
+ async init(param, $container) {
5416
+ param = param || {};
5417
+ let accid = param.account_id;
5418
+ let ref = param.ref;
5419
+ let user = await this.store.init(accid, undefined, ref);
5420
+ if (!$container) $container = document.body || document;
5421
+ this.pluginMgr = new PluginMgr(this, $container);
5422
+ let clean = setInterval(() => {
5423
+ if ($container && $container.isConnected) return;
5424
+ this.pluginMgr.destroy();
5425
+ clearInterval(clean);
5426
+ }, 1000);
5427
+ this.domGate.open();
5428
+ return user;
5398
5429
  }
5399
5430
  async setAccount(id, $container, mask, cb) {
5400
5431
  let outmask = await this.store.init(id, mask);
5401
- if (!$container) $container = document.body;
5432
+ if (!$container) $container = document.body || document;
5402
5433
  this.pluginMgr = new PluginMgr(this, $container);
5403
5434
  let clean = setInterval(() => {
5404
5435
  if ($container && $container.isConnected) return;
@@ -5478,6 +5509,10 @@ class Widget {
5478
5509
  await this.domGate.entry();
5479
5510
  return this.pluginMgr.setCurrentChatboxLocale(locale);
5480
5511
  }
5512
+ async setLanguage(locale) {
5513
+ await this.domGate.entry();
5514
+ return this.pluginMgr.setCurrentChatboxLocale(locale);
5515
+ }
5481
5516
  async setPluginLocale(id, locale) {
5482
5517
  await this.domGate.entry();
5483
5518
  return this.pluginMgr.setPluginLocale(id, locale);
@@ -5522,7 +5557,7 @@ window.__sbz_WIDGET = Widget;
5522
5557
  /* harmony default export */ const lib = (Widget);
5523
5558
  ;// CONCATENATED MODULE: ./screenshoot.js
5524
5559
 
5525
- let accid = 'acqsulrowbxiugvginhw';
5560
+ let screenshoot_accid = 'acqsulrowbxiugvginhw';
5526
5561
  let widget = new lib('https://api.subiz.com.vn/4.0/', 'https://file-subiz.com/', 'https://rt-0.subiz.com.vn/', true, true);
5527
5562
  function main() {
5528
5563
  var $div = document.createElement('div');
@@ -5562,9 +5597,9 @@ function main() {
5562
5597
  }];
5563
5598
  }
5564
5599
  }
5565
- plugin.account_id = accid;
5600
+ plugin.account_id = screenshoot_accid;
5566
5601
  widget._overridePlugin([plugin]);
5567
- widget.setAccount(accid, $div);
5602
+ widget.setAccount(screenshoot_accid, $div);
5568
5603
  }
5569
5604
  main();
5570
5605
  })();