qiscus-sdk-core 2.13.2 → 2.14.0
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/dist/qiscus-sdk-core.js +496 -290
- package/dist/qiscus-sdk-core.js.map +1 -1
- package/dist/qiscus-sdk-core.min.js +3 -3
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +233 -106
- package/lib/lib/adapters/custom-event.js +3 -3
- package/lib/lib/adapters/expired-token.js +45 -60
- package/lib/lib/adapters/http.js +156 -82
- package/lib/lib/adapters/mqtt.js +26 -23
- package/lib/lib/adapters/sync.js +20 -7
- package/package.json +1 -1
package/dist/qiscus-sdk-core.js
CHANGED
|
@@ -29966,7 +29966,7 @@ function extend() {
|
|
|
29966
29966
|
/*! exports provided: name, version, description, license, main, browser, unpkg, files, scripts, devDependencies, dependencies, babel, prettier, engines, packageManager, default */
|
|
29967
29967
|
/***/ (function(module) {
|
|
29968
29968
|
|
|
29969
|
-
module.exports = JSON.parse("{\"name\":\"qiscus-sdk-core\",\"version\":\"2.
|
|
29969
|
+
module.exports = JSON.parse("{\"name\":\"qiscus-sdk-core\",\"version\":\"2.14.0\",\"description\":\"Qiscus Web SDK Core\",\"license\":\"MIT\",\"main\":\"lib/index.js\",\"browser\":\"dist/qiscus-sdk-core.min.js\",\"unpkg\":\"dist/qiscus-sdk-core.min.js\",\"files\":[\"lib\",\"dist\"],\"scripts\":{\"build\":\"npm-run-all --parallel build:node build:web build:web:dev\",\"build:dev\":\"npm-run-all --parallel build:node build:web:dev\",\"build:dev:watch\":\"npm-run-all --parallel build:web:watch serve\",\"build:node\":\"babel -d lib src\",\"build:node:watch\":\"babel -w -d lib src\",\"build:web\":\"webpack --env.production --env.target=web\",\"build:web:dev\":\"webpack --env.development --env.target=web\",\"build:web:watch\":\"webpack --env.development --env.target=web --watch\",\"dev\":\"webpack --env.development --progress --colors --watch\",\"watch\":\"npm-run-all build:web:watch build:node:watch\",\"test\":\"mocha --require @babel/register --colors 'test/**/*test.js'\",\"test:watch\":\"npm run test -- -w\",\"clean\":\"rimraf dist lib\",\"preversion\":\"npm-run-all clean build\",\"prepublishOnly\":\"npm-run-all clean build\",\"serve\":\"http-server -p 1234 -c-1 dist\",\"dev:serve\":\"run-p serve watch\",\"release:patch\":\"np patch --any-branch --yolo\"},\"devDependencies\":{\"@babel/cli\":\"^7.10.5\",\"@babel/core\":\"^7.11.4\",\"@babel/plugin-proposal-class-properties\":\"^7.10.4\",\"@babel/plugin-transform-runtime\":\"^7.11.0\",\"@babel/polyfill\":\"^7.10.4\",\"@babel/preset-env\":\"^7.11.0\",\"@babel/register\":\"^7.10.5\",\"@commitlint/cli\":\"^8.3.5\",\"@commitlint/config-conventional\":\"^8.3.4\",\"babel-eslint\":\"^8.2.6\",\"babel-loader\":\"^8.0.6\",\"babel-plugin-add-module-exports\":\"^1.0.2\",\"babel-plugin-date-fns\":\"^0.1.0\",\"chai\":\"^4.2.0\",\"chai-spies\":\"^1.0.0\",\"eslint\":\"5.0.0\",\"eslint-config-standard\":\"^12.0.0\",\"eslint-loader\":\"^2.2.1\",\"eslint-plugin-import\":\"^2.22.0\",\"eslint-plugin-node\":\"^8.0.1\",\"eslint-plugin-promise\":\"^4.2.1\",\"eslint-plugin-standard\":\"^4.0.1\",\"http-server\":\"^0.12.3\",\"mocha\":\"^5.2.0\",\"np\":\"^8.0.4\",\"npm-run-all\":\"^4.1.5\",\"rimraf\":\"^2.7.1\",\"serve\":\"^12.0.0\",\"webpack\":\"^4.44.1\",\"webpack-cli\":\"^3.3.12\"},\"dependencies\":{\"@babel/runtime\":\"^7.11.2\",\"date-fns\":\"^1.30.1\",\"is_js\":\"^0.9.0\",\"lodash.debounce\":\"^4.0.8\",\"lodash.throttle\":\"^4.1.1\",\"mitt\":\"^1.2.0\",\"mqtt\":\"~4.2.6\",\"superagent\":\"^3.8.3\"},\"babel\":{\"presets\":[[\"@babel/preset-env\",{\"modules\":\"auto\"}]],\"plugins\":[\"@babel/plugin-transform-runtime\",\"@babel/plugin-proposal-class-properties\",\"babel-plugin-add-module-exports\"]},\"prettier\":{\"semi\":false,\"singleQuote\":true,\"trailingComma\":\"es5\"},\"engines\":{\"node\":\"16.15.1\"},\"packageManager\":\"pnpm@8.15.9\"}");
|
|
29970
29970
|
|
|
29971
29971
|
/***/ }),
|
|
29972
29972
|
|
|
@@ -30067,6 +30067,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
30067
30067
|
function QiscusSDK() {
|
|
30068
30068
|
var _this = this;
|
|
30069
30069
|
_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_2___default()(this, QiscusSDK);
|
|
30070
|
+
_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_4___default()(this, "_pendingComments", []);
|
|
30071
|
+
// count of how much does a comment has been retried
|
|
30072
|
+
_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_4___default()(this, "_pendingCommentsCount", {});
|
|
30070
30073
|
_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_4___default()(this, "_readComment", function (roomId, commentId) {
|
|
30071
30074
|
return _this._updateStatus(roomId, commentId);
|
|
30072
30075
|
});
|
|
@@ -30478,9 +30481,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
30478
30481
|
_this2.events.emit('room-cleared', room);
|
|
30479
30482
|
});
|
|
30480
30483
|
});
|
|
30484
|
+
this.syncAdapter.on('synchronize', function () {
|
|
30485
|
+
_this2._pendingComments.forEach(function (m) {
|
|
30486
|
+
return _this2._retrySendComment(m);
|
|
30487
|
+
});
|
|
30488
|
+
});
|
|
30481
30489
|
this.customEventAdapter = Object(_lib_adapters_custom_event__WEBPACK_IMPORTED_MODULE_18__["default"])(this.realtimeAdapter, this.user_id);
|
|
30482
30490
|
this.setEventListeners();
|
|
30483
|
-
case
|
|
30491
|
+
case 56:
|
|
30484
30492
|
case "end":
|
|
30485
30493
|
return _context3.stop();
|
|
30486
30494
|
}
|
|
@@ -30657,6 +30665,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
30657
30665
|
version: _this3.version,
|
|
30658
30666
|
getCustomHeader: function getCustomHeader() {
|
|
30659
30667
|
return _this3._customHeader;
|
|
30668
|
+
},
|
|
30669
|
+
expiredTokenAdapterGetter: function expiredTokenAdapterGetter() {
|
|
30670
|
+
return _this3.expiredTokenAdapter;
|
|
30660
30671
|
}
|
|
30661
30672
|
});
|
|
30662
30673
|
_this3.HTTPAdapter.setToken(_this3.userData.token);
|
|
@@ -31621,7 +31632,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
31621
31632
|
}, {
|
|
31622
31633
|
key: "sendComment",
|
|
31623
31634
|
value: (function () {
|
|
31624
|
-
var _sendComment = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function
|
|
31635
|
+
var _sendComment = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee15(topicId, commentMessage, uniqueId) {
|
|
31625
31636
|
var _this13 = this;
|
|
31626
31637
|
var type,
|
|
31627
31638
|
payload,
|
|
@@ -31633,13 +31644,23 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
31633
31644
|
repliedMessage,
|
|
31634
31645
|
extrasToBeSubmitted,
|
|
31635
31646
|
messageData,
|
|
31636
|
-
|
|
31637
|
-
|
|
31638
|
-
|
|
31647
|
+
sendComment,
|
|
31648
|
+
_this$options$comment,
|
|
31649
|
+
_this$options,
|
|
31650
|
+
res,
|
|
31651
|
+
commentIndex,
|
|
31652
|
+
_error$message$toLowe,
|
|
31653
|
+
_error$message,
|
|
31654
|
+
whitelistedErrorStatus,
|
|
31655
|
+
message,
|
|
31656
|
+
isOffline,
|
|
31657
|
+
_args15 = arguments;
|
|
31658
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee15$(_context15) {
|
|
31659
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
31639
31660
|
case 0:
|
|
31640
|
-
type =
|
|
31641
|
-
payload =
|
|
31642
|
-
extras =
|
|
31661
|
+
type = _args15.length > 3 && _args15[3] !== undefined ? _args15[3] : 'text';
|
|
31662
|
+
payload = _args15.length > 4 ? _args15[4] : undefined;
|
|
31663
|
+
extras = _args15.length > 5 ? _args15[5] : undefined;
|
|
31643
31664
|
self = this; // set extra data, etc
|
|
31644
31665
|
if (self.options.prePostCommentCallback) {
|
|
31645
31666
|
self.options.prePostCommentCallback(commentMessage);
|
|
@@ -31655,6 +31676,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
31655
31676
|
}
|
|
31656
31677
|
self.pendingCommentId--;
|
|
31657
31678
|
commentData = {
|
|
31679
|
+
room_id: topicId,
|
|
31658
31680
|
message: commentMessage,
|
|
31659
31681
|
username_as: this.username,
|
|
31660
31682
|
username_real: this.user_id,
|
|
@@ -31683,64 +31705,169 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
31683
31705
|
pendingComment.payload = parsedPayload;
|
|
31684
31706
|
}
|
|
31685
31707
|
extrasToBeSubmitted = extras || self.extras;
|
|
31686
|
-
|
|
31708
|
+
_context15.next = 13;
|
|
31687
31709
|
return this._hookAdapter.trigger(_lib_adapters_hook__WEBPACK_IMPORTED_MODULE_23__["Hooks"].MESSAGE_BEFORE_SENT, _objectSpread(_objectSpread({}, pendingComment), {}, {
|
|
31688
31710
|
extras: extrasToBeSubmitted
|
|
31689
31711
|
}));
|
|
31690
31712
|
case 13:
|
|
31691
|
-
messageData =
|
|
31713
|
+
messageData = _context15.sent;
|
|
31692
31714
|
messageData = self.prepareCommentToBeSubmitted(messageData);
|
|
31693
31715
|
if (self.selected) self.selected.comments.push(messageData);
|
|
31694
|
-
|
|
31695
|
-
|
|
31696
|
-
|
|
31697
|
-
|
|
31716
|
+
sendComment = function sendComment() {
|
|
31717
|
+
return _this13.userAdapter.postComment('' + topicId, messageData.message, messageData.unique_id, messageData.type, messageData.payload, messageData.extras);
|
|
31718
|
+
};
|
|
31719
|
+
_context15.prev = 17;
|
|
31720
|
+
_context15.next = 20;
|
|
31721
|
+
return sendComment();
|
|
31722
|
+
case 20:
|
|
31723
|
+
res = _context15.sent;
|
|
31724
|
+
_context15.next = 23;
|
|
31725
|
+
return this._hookAdapter.trigger(_lib_adapters_hook__WEBPACK_IMPORTED_MODULE_23__["Hooks"].MESSAGE_BEFORE_RECEIVED, res);
|
|
31726
|
+
case 23:
|
|
31727
|
+
res = _context15.sent;
|
|
31728
|
+
Object.assign(messageData, res);
|
|
31729
|
+
if (self.selected) {
|
|
31730
|
+
_context15.next = 27;
|
|
31731
|
+
break;
|
|
31732
|
+
}
|
|
31733
|
+
return _context15.abrupt("return", Promise.resolve(messageData));
|
|
31734
|
+
case 27:
|
|
31735
|
+
// When the posting succeeded, we mark the Comment as sent,
|
|
31736
|
+
// so all the interested party can be notified.
|
|
31737
|
+
messageData.markAsSent();
|
|
31738
|
+
messageData.id = res.id;
|
|
31739
|
+
messageData.before_id = res.comment_before_id;
|
|
31740
|
+
// update the timestamp also then re-sort the comment list
|
|
31741
|
+
messageData.unix_timestamp = res.unix_timestamp;
|
|
31742
|
+
(_this$options$comment = (_this$options = this.options).commentSentCallback) === null || _this$options$comment === void 0 || _this$options$comment.call(_this$options, {
|
|
31743
|
+
comment: messageData
|
|
31744
|
+
});
|
|
31745
|
+
self.events.emit('comment-sent', messageData);
|
|
31746
|
+
self.sortComments();
|
|
31747
|
+
commentIndex = self._pendingComments.findIndex(function (c) {
|
|
31748
|
+
return c.unique_id === messageData.unique_id;
|
|
31749
|
+
});
|
|
31750
|
+
if (commentIndex > -1) {
|
|
31751
|
+
self._pendingComments.splice(commentIndex, 1);
|
|
31752
|
+
}
|
|
31753
|
+
return _context15.abrupt("return", messageData);
|
|
31754
|
+
case 39:
|
|
31755
|
+
_context15.prev = 39;
|
|
31756
|
+
_context15.t0 = _context15["catch"](17);
|
|
31757
|
+
messageData.markAsFailed();
|
|
31758
|
+
// From superagent: `https://forwardemail.github.io/superagent/#retrying-requests`
|
|
31759
|
+
whitelistedErrorStatus = [undefined, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524];
|
|
31760
|
+
message = (_error$message$toLowe = (_error$message = _context15.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.toLowerCase()) !== null && _error$message$toLowe !== void 0 ? _error$message$toLowe : '';
|
|
31761
|
+
isOffline = message.includes('offline');
|
|
31762
|
+
if (whitelistedErrorStatus.includes(_context15.t0.status) || isOffline) {
|
|
31763
|
+
this._pendingComments.push(messageData);
|
|
31764
|
+
this.logger('Failed sending comment', _context15.t0);
|
|
31765
|
+
}
|
|
31766
|
+
return _context15.abrupt("return", Promise.reject(_context15.t0));
|
|
31767
|
+
case 47:
|
|
31768
|
+
case "end":
|
|
31769
|
+
return _context15.stop();
|
|
31770
|
+
}
|
|
31771
|
+
}, _callee15, this, [[17, 39]]);
|
|
31772
|
+
}));
|
|
31773
|
+
function sendComment(_x12, _x13, _x14) {
|
|
31774
|
+
return _sendComment.apply(this, arguments);
|
|
31775
|
+
}
|
|
31776
|
+
return sendComment;
|
|
31777
|
+
}())
|
|
31778
|
+
}, {
|
|
31779
|
+
key: "_retrySendComment",
|
|
31780
|
+
value: function () {
|
|
31781
|
+
var _retrySendComment2 = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee17(comment) {
|
|
31782
|
+
var _this$_pendingComment,
|
|
31783
|
+
_this14 = this;
|
|
31784
|
+
var _this$options$comment2, _this$options2, index;
|
|
31785
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee17$(_context17) {
|
|
31786
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
31787
|
+
case 0:
|
|
31788
|
+
this.logger('Retrying send comment', comment);
|
|
31789
|
+
this._pendingCommentsCount[comment.unique_id] = ((_this$_pendingComment = this._pendingCommentsCount[comment.unique_id]) !== null && _this$_pendingComment !== void 0 ? _this$_pendingComment : 0) + 1;
|
|
31790
|
+
|
|
31791
|
+
// If it is exceeding the maximum retry count (which is 10), we will not retry anymore
|
|
31792
|
+
if (!(this._pendingCommentsCount[comment.unique_id] > 10)) {
|
|
31793
|
+
_context17.next = 10;
|
|
31794
|
+
break;
|
|
31795
|
+
}
|
|
31796
|
+
this.logger("Exceeding maximum retry count for comment ".concat(comment.unique_id, ", not retrying anymore"));
|
|
31797
|
+
(_this$options$comment2 = (_this$options2 = this.options).commentRetryExceedCallback) === null || _this$options$comment2 === void 0 || _this$options$comment2.call(_this$options2, comment);
|
|
31798
|
+
// Remove the comment from pending comments
|
|
31799
|
+
index = this._pendingComments.findIndex(function (c) {
|
|
31800
|
+
return c.unique_id === comment.unique_id;
|
|
31801
|
+
});
|
|
31802
|
+
if (index > -1) {
|
|
31803
|
+
this._pendingComments.splice(index, 1);
|
|
31804
|
+
}
|
|
31805
|
+
// Mark the comment as failed
|
|
31806
|
+
comment.markAsFailed();
|
|
31807
|
+
// Emit the event
|
|
31808
|
+
this.events.emit('comment-retry-exceed', comment);
|
|
31809
|
+
return _context17.abrupt("return", Promise.reject(new Error('Exceeding maximum retry count')));
|
|
31810
|
+
case 10:
|
|
31811
|
+
return _context17.abrupt("return", this.userAdapter.postComment('' + comment.room_id, comment.message, comment.unique_id, comment.type, comment.payload, comment.extras).then(/*#__PURE__*/function () {
|
|
31812
|
+
var _ref12 = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee16(res) {
|
|
31813
|
+
var _this14$selected, _this14$selected2, _this14$options$comme, _this14$options;
|
|
31814
|
+
var index, commentIndex;
|
|
31815
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee16$(_context16) {
|
|
31816
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
31698
31817
|
case 0:
|
|
31699
|
-
|
|
31700
|
-
|
|
31701
|
-
case 2:
|
|
31702
|
-
res = _context15.sent;
|
|
31703
|
-
Object.assign(messageData, res);
|
|
31704
|
-
if (self.selected) {
|
|
31705
|
-
_context15.next = 6;
|
|
31818
|
+
if (!(((_this14$selected = _this14.selected) === null || _this14$selected === void 0 ? void 0 : _this14$selected.id) !== comment.room_id)) {
|
|
31819
|
+
_context16.next = 2;
|
|
31706
31820
|
break;
|
|
31707
31821
|
}
|
|
31708
|
-
return
|
|
31709
|
-
case
|
|
31710
|
-
|
|
31711
|
-
|
|
31712
|
-
|
|
31713
|
-
|
|
31714
|
-
|
|
31715
|
-
|
|
31716
|
-
|
|
31717
|
-
|
|
31718
|
-
|
|
31719
|
-
|
|
31822
|
+
return _context16.abrupt("return", res);
|
|
31823
|
+
case 2:
|
|
31824
|
+
Object.assign(comment, res);
|
|
31825
|
+
comment.markAsSent();
|
|
31826
|
+
comment.id = res.id;
|
|
31827
|
+
comment.before_id = res.comment_before_id;
|
|
31828
|
+
comment.unix_timestamp = res.unix_timestamp;
|
|
31829
|
+
index = (_this14$selected2 = _this14.selected) === null || _this14$selected2 === void 0 ? void 0 : _this14$selected2.comments.findIndex(function (c) {
|
|
31830
|
+
return c.unique_id === comment.unique_id;
|
|
31831
|
+
});
|
|
31832
|
+
if (index > -1) {
|
|
31833
|
+
_this14.selected.comments[index] = comment;
|
|
31834
|
+
}
|
|
31835
|
+
_this14.sortComments();
|
|
31836
|
+
(_this14$options$comme = (_this14$options = _this14.options).commentSentCallback) === null || _this14$options$comme === void 0 || _this14$options$comme.call(_this14$options, {
|
|
31837
|
+
comment: comment
|
|
31838
|
+
});
|
|
31839
|
+
_this14.events.emit('comment-sent', comment);
|
|
31840
|
+
commentIndex = _this14._pendingComments.findIndex(function (c) {
|
|
31841
|
+
return c.unique_id === comment.unique_id;
|
|
31842
|
+
});
|
|
31843
|
+
if (commentIndex > -1) {
|
|
31844
|
+
_this14._pendingComments.splice(commentIndex, 1);
|
|
31845
|
+
}
|
|
31846
|
+
return _context16.abrupt("return", comment);
|
|
31847
|
+
case 15:
|
|
31720
31848
|
case "end":
|
|
31721
|
-
return
|
|
31849
|
+
return _context16.stop();
|
|
31722
31850
|
}
|
|
31723
|
-
},
|
|
31851
|
+
}, _callee16);
|
|
31724
31852
|
}));
|
|
31725
|
-
return function (
|
|
31853
|
+
return function (_x16) {
|
|
31726
31854
|
return _ref12.apply(this, arguments);
|
|
31727
31855
|
};
|
|
31728
31856
|
}())["catch"](function (err) {
|
|
31729
|
-
|
|
31857
|
+
comment.markAsFailed();
|
|
31730
31858
|
return Promise.reject(err);
|
|
31731
31859
|
}));
|
|
31732
|
-
case
|
|
31860
|
+
case 11:
|
|
31733
31861
|
case "end":
|
|
31734
|
-
return
|
|
31862
|
+
return _context17.stop();
|
|
31735
31863
|
}
|
|
31736
|
-
},
|
|
31864
|
+
}, _callee17, this);
|
|
31737
31865
|
}));
|
|
31738
|
-
function
|
|
31739
|
-
return
|
|
31866
|
+
function _retrySendComment(_x15) {
|
|
31867
|
+
return _retrySendComment2.apply(this, arguments);
|
|
31740
31868
|
}
|
|
31741
|
-
return
|
|
31869
|
+
return _retrySendComment;
|
|
31742
31870
|
}() // #endregion
|
|
31743
|
-
)
|
|
31744
31871
|
}, {
|
|
31745
31872
|
key: "getUsers",
|
|
31746
31873
|
value: function getUsers() {
|
|
@@ -31918,12 +32045,12 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
31918
32045
|
}, {
|
|
31919
32046
|
key: "removeParticipantsFromGroup",
|
|
31920
32047
|
value: function removeParticipantsFromGroup(roomId, emails) {
|
|
31921
|
-
var
|
|
32048
|
+
var _this15 = this;
|
|
31922
32049
|
if (is_js__WEBPACK_IMPORTED_MODULE_8___default.a.not.array(emails)) {
|
|
31923
32050
|
return Promise.reject(new Error('`emails` must have type of array'));
|
|
31924
32051
|
}
|
|
31925
32052
|
return this.roomAdapter.removeParticipantsFromGroup(roomId, emails).then(function (res) {
|
|
31926
|
-
|
|
32053
|
+
_this15.events.emit('participants-removed', emails);
|
|
31927
32054
|
return Promise.resolve(res);
|
|
31928
32055
|
});
|
|
31929
32056
|
}
|
|
@@ -32086,12 +32213,12 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32086
32213
|
}, {
|
|
32087
32214
|
key: "deleteComment",
|
|
32088
32215
|
value: function deleteComment(roomId, commentUniqueIds, isForEveryone, isHard) {
|
|
32089
|
-
var
|
|
32216
|
+
var _this16 = this;
|
|
32090
32217
|
if (!Array.isArray(commentUniqueIds)) {
|
|
32091
32218
|
throw new Error("unique ids' must be type of Array");
|
|
32092
32219
|
}
|
|
32093
32220
|
return this.userAdapter.deleteComment(roomId, commentUniqueIds, isForEveryone, isHard).then(function (res) {
|
|
32094
|
-
|
|
32221
|
+
_this16.events.emit('comment-deleted', {
|
|
32095
32222
|
roomId: roomId,
|
|
32096
32223
|
commentUniqueIds: commentUniqueIds,
|
|
32097
32224
|
isForEveryone: isForEveryone,
|
|
@@ -32105,7 +32232,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32105
32232
|
}, {
|
|
32106
32233
|
key: "clearRoomsCache",
|
|
32107
32234
|
value: function clearRoomsCache() {
|
|
32108
|
-
var
|
|
32235
|
+
var _this17 = this;
|
|
32109
32236
|
// remove all room except currently selected
|
|
32110
32237
|
if (this.selected) {
|
|
32111
32238
|
// clear the map
|
|
@@ -32113,14 +32240,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32113
32240
|
// get current index and array length
|
|
32114
32241
|
var roomLength = this.rooms.length;
|
|
32115
32242
|
var curIndex = this.rooms.findIndex(function (room) {
|
|
32116
|
-
return room.id ===
|
|
32243
|
+
return room.id === _this17.selected.id;
|
|
32117
32244
|
});
|
|
32118
32245
|
if (!(curIndex + 1 === roomLength)) {
|
|
32119
32246
|
this.rooms.splice(curIndex + 1, roomLength - (curIndex + 1));
|
|
32120
32247
|
}
|
|
32121
32248
|
// ambil ulang cur index nya, klo udah di awal ga perlu lagi kode dibawah ini
|
|
32122
32249
|
curIndex = this.rooms.findIndex(function (room) {
|
|
32123
|
-
return room.id ===
|
|
32250
|
+
return room.id === _this17.selected.id;
|
|
32124
32251
|
});
|
|
32125
32252
|
if (curIndex > 0 && this.rooms.length > 1) {
|
|
32126
32253
|
this.rooms.splice(1, this.rooms.length - 1);
|
|
@@ -32130,18 +32257,18 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32130
32257
|
}, {
|
|
32131
32258
|
key: "exitChatRoom",
|
|
32132
32259
|
value: function exitChatRoom() {
|
|
32133
|
-
var
|
|
32260
|
+
var _this18 = this;
|
|
32134
32261
|
// remove all subscriber
|
|
32135
32262
|
this.realtimeAdapter.unsubscribeTyping();
|
|
32136
32263
|
Object(_lib_util__WEBPACK_IMPORTED_MODULE_21__["tryCatch"])(function () {
|
|
32137
|
-
return
|
|
32138
|
-
return it.email !==
|
|
32264
|
+
return _this18.selected.participants.filter(function (it) {
|
|
32265
|
+
return it.email !== _this18.user_id;
|
|
32139
32266
|
}).map(function (it) {
|
|
32140
32267
|
return it.email;
|
|
32141
32268
|
});
|
|
32142
32269
|
}, null, this.noop, function (userIds) {
|
|
32143
32270
|
return userIds.forEach(function (userId) {
|
|
32144
|
-
return
|
|
32271
|
+
return _this18.realtimeAdapter.unsubscribeRoomPresence(userId);
|
|
32145
32272
|
});
|
|
32146
32273
|
});
|
|
32147
32274
|
this.selected = null;
|
|
@@ -32339,7 +32466,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32339
32466
|
}, {
|
|
32340
32467
|
key: "searchMessage",
|
|
32341
32468
|
value: (function () {
|
|
32342
|
-
var _searchMessage = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function
|
|
32469
|
+
var _searchMessage = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee18() {
|
|
32343
32470
|
var _ref13,
|
|
32344
32471
|
query,
|
|
32345
32472
|
_ref13$roomIds,
|
|
@@ -32352,20 +32479,20 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32352
32479
|
url,
|
|
32353
32480
|
isValidRoomType,
|
|
32354
32481
|
room,
|
|
32355
|
-
|
|
32356
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function
|
|
32357
|
-
while (1) switch (
|
|
32482
|
+
_args18 = arguments;
|
|
32483
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee18$(_context18) {
|
|
32484
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
32358
32485
|
case 0:
|
|
32359
|
-
_ref13 =
|
|
32486
|
+
_ref13 = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {}, query = _ref13.query, _ref13$roomIds = _ref13.roomIds, roomIds = _ref13$roomIds === void 0 ? [] : _ref13$roomIds, userId = _ref13.userId, type = _ref13.type, roomType = _ref13.roomType, page = _ref13.page, limit = _ref13.limit;
|
|
32360
32487
|
url = 'api/v2/sdk/search';
|
|
32361
32488
|
isValidRoomType = ['group', 'single', 'channel'].some(function (it) {
|
|
32362
32489
|
return it === roomType;
|
|
32363
32490
|
});
|
|
32364
32491
|
if (!(roomType != null && !isValidRoomType)) {
|
|
32365
|
-
|
|
32492
|
+
_context18.next = 5;
|
|
32366
32493
|
break;
|
|
32367
32494
|
}
|
|
32368
|
-
return
|
|
32495
|
+
return _context18.abrupt("return", Promise.reject('Invalid room type, valid room type are: `group`, `single`, and `channel`'));
|
|
32369
32496
|
case 5:
|
|
32370
32497
|
room = function (roomType) {
|
|
32371
32498
|
var rType = roomType == null ? undefined : roomType === 'single' ? 'single' : 'group';
|
|
@@ -32375,7 +32502,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32375
32502
|
isPublic: isPublic
|
|
32376
32503
|
};
|
|
32377
32504
|
}(roomType);
|
|
32378
|
-
return
|
|
32505
|
+
return _context18.abrupt("return", this.HTTPAdapter.post_json(url, {
|
|
32379
32506
|
token: this.token,
|
|
32380
32507
|
query: query,
|
|
32381
32508
|
sender: userId,
|
|
@@ -32392,9 +32519,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32392
32519
|
}));
|
|
32393
32520
|
case 7:
|
|
32394
32521
|
case "end":
|
|
32395
|
-
return
|
|
32522
|
+
return _context18.stop();
|
|
32396
32523
|
}
|
|
32397
|
-
},
|
|
32524
|
+
}, _callee18, this);
|
|
32398
32525
|
}));
|
|
32399
32526
|
function searchMessage() {
|
|
32400
32527
|
return _searchMessage.apply(this, arguments);
|
|
@@ -32418,7 +32545,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32418
32545
|
}, {
|
|
32419
32546
|
key: "getFileList",
|
|
32420
32547
|
value: (function () {
|
|
32421
|
-
var _getFileList = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function
|
|
32548
|
+
var _getFileList = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee19() {
|
|
32422
32549
|
var _ref14,
|
|
32423
32550
|
_ref14$roomIds,
|
|
32424
32551
|
roomIds,
|
|
@@ -32431,17 +32558,17 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32431
32558
|
excludeExtensions,
|
|
32432
32559
|
url,
|
|
32433
32560
|
opts,
|
|
32434
|
-
|
|
32435
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function
|
|
32436
|
-
while (1) switch (
|
|
32561
|
+
_args19 = arguments;
|
|
32562
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee19$(_context19) {
|
|
32563
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
32437
32564
|
case 0:
|
|
32438
|
-
_ref14 =
|
|
32565
|
+
_ref14 = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {}, _ref14$roomIds = _ref14.roomIds, roomIds = _ref14$roomIds === void 0 ? [] : _ref14$roomIds, fileType = _ref14.fileType, page = _ref14.page, limit = _ref14.limit, sender = _ref14.sender, userId = _ref14.userId, includeExtensions = _ref14.includeExtensions, excludeExtensions = _ref14.excludeExtensions;
|
|
32439
32566
|
url = 'api/v2/sdk/file_list';
|
|
32440
32567
|
if (this.isLogin) {
|
|
32441
|
-
|
|
32568
|
+
_context19.next = 4;
|
|
32442
32569
|
break;
|
|
32443
32570
|
}
|
|
32444
|
-
return
|
|
32571
|
+
return _context19.abrupt("return", Promise.reject('You need to login to use this method'));
|
|
32445
32572
|
case 4:
|
|
32446
32573
|
// intended to check for undefined, so user can provide user
|
|
32447
32574
|
// with null. If null, backend can determine that we want to
|
|
@@ -32463,14 +32590,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32463
32590
|
exclude_extensions: excludeExtensions
|
|
32464
32591
|
};
|
|
32465
32592
|
if (sender != null) opts['sender'] = sender;
|
|
32466
|
-
return
|
|
32593
|
+
return _context19.abrupt("return", this.HTTPAdapter.post_json(url, opts).then(function (res) {
|
|
32467
32594
|
return res.body;
|
|
32468
32595
|
}));
|
|
32469
32596
|
case 9:
|
|
32470
32597
|
case "end":
|
|
32471
|
-
return
|
|
32598
|
+
return _context19.stop();
|
|
32472
32599
|
}
|
|
32473
|
-
},
|
|
32600
|
+
}, _callee19, this);
|
|
32474
32601
|
}));
|
|
32475
32602
|
function getFileList() {
|
|
32476
32603
|
return _getFileList.apply(this, arguments);
|
|
@@ -32600,18 +32727,18 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32600
32727
|
}, {
|
|
32601
32728
|
key: "updateMessage",
|
|
32602
32729
|
value: function () {
|
|
32603
|
-
var _updateMessage = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function
|
|
32604
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function
|
|
32605
|
-
while (1) switch (
|
|
32730
|
+
var _updateMessage = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee20(message) {
|
|
32731
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee20$(_context20) {
|
|
32732
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
32606
32733
|
case 0:
|
|
32607
|
-
return
|
|
32734
|
+
return _context20.abrupt("return", this.userAdapter.updateMessage(message));
|
|
32608
32735
|
case 1:
|
|
32609
32736
|
case "end":
|
|
32610
|
-
return
|
|
32737
|
+
return _context20.stop();
|
|
32611
32738
|
}
|
|
32612
|
-
},
|
|
32739
|
+
}, _callee20, this);
|
|
32613
32740
|
}));
|
|
32614
|
-
function updateMessage(
|
|
32741
|
+
function updateMessage(_x17) {
|
|
32615
32742
|
return _updateMessage.apply(this, arguments);
|
|
32616
32743
|
}
|
|
32617
32744
|
return updateMessage;
|
|
@@ -32619,10 +32746,10 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32619
32746
|
}, {
|
|
32620
32747
|
key: "onMessageUpdated",
|
|
32621
32748
|
value: function onMessageUpdated(handler) {
|
|
32622
|
-
var
|
|
32749
|
+
var _this19 = this;
|
|
32623
32750
|
this.realtimeAdapter.on('message:updated', handler);
|
|
32624
32751
|
return function () {
|
|
32625
|
-
return
|
|
32752
|
+
return _this19.realtimeAdapter.off('message:updated', handler);
|
|
32626
32753
|
};
|
|
32627
32754
|
}
|
|
32628
32755
|
|
|
@@ -32633,16 +32760,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32633
32760
|
}, {
|
|
32634
32761
|
key: "closeRealtimeConnection",
|
|
32635
32762
|
value: (function () {
|
|
32636
|
-
var _closeRealtimeConnection = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function
|
|
32637
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function
|
|
32638
|
-
while (1) switch (
|
|
32763
|
+
var _closeRealtimeConnection = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee21() {
|
|
32764
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee21$(_context21) {
|
|
32765
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
32639
32766
|
case 0:
|
|
32640
|
-
return
|
|
32767
|
+
return _context21.abrupt("return", this.realtimeAdapter.closeConnection());
|
|
32641
32768
|
case 1:
|
|
32642
32769
|
case "end":
|
|
32643
|
-
return
|
|
32770
|
+
return _context21.stop();
|
|
32644
32771
|
}
|
|
32645
|
-
},
|
|
32772
|
+
}, _callee21, this);
|
|
32646
32773
|
}));
|
|
32647
32774
|
function closeRealtimeConnection() {
|
|
32648
32775
|
return _closeRealtimeConnection.apply(this, arguments);
|
|
@@ -32657,16 +32784,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32657
32784
|
}, {
|
|
32658
32785
|
key: "openRealtimeConnection",
|
|
32659
32786
|
value: (function () {
|
|
32660
|
-
var _openRealtimeConnection = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function
|
|
32661
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function
|
|
32662
|
-
while (1) switch (
|
|
32787
|
+
var _openRealtimeConnection = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee22() {
|
|
32788
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee22$(_context22) {
|
|
32789
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
32663
32790
|
case 0:
|
|
32664
|
-
return
|
|
32791
|
+
return _context22.abrupt("return", this.realtimeAdapter.openConnection());
|
|
32665
32792
|
case 1:
|
|
32666
32793
|
case "end":
|
|
32667
|
-
return
|
|
32794
|
+
return _context22.stop();
|
|
32668
32795
|
}
|
|
32669
|
-
},
|
|
32796
|
+
}, _callee22, this);
|
|
32670
32797
|
}));
|
|
32671
32798
|
function openRealtimeConnection() {
|
|
32672
32799
|
return _openRealtimeConnection.apply(this, arguments);
|
|
@@ -32676,16 +32803,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32676
32803
|
}, {
|
|
32677
32804
|
key: "startSync",
|
|
32678
32805
|
value: function () {
|
|
32679
|
-
var _startSync = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function
|
|
32680
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function
|
|
32681
|
-
while (1) switch (
|
|
32806
|
+
var _startSync = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee23() {
|
|
32807
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee23$(_context23) {
|
|
32808
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
32682
32809
|
case 0:
|
|
32683
32810
|
this._forceEnableSync = true;
|
|
32684
32811
|
case 1:
|
|
32685
32812
|
case "end":
|
|
32686
|
-
return
|
|
32813
|
+
return _context23.stop();
|
|
32687
32814
|
}
|
|
32688
|
-
},
|
|
32815
|
+
}, _callee23, this);
|
|
32689
32816
|
}));
|
|
32690
32817
|
function startSync() {
|
|
32691
32818
|
return _startSync.apply(this, arguments);
|
|
@@ -32695,16 +32822,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
32695
32822
|
}, {
|
|
32696
32823
|
key: "stopSync",
|
|
32697
32824
|
value: function () {
|
|
32698
|
-
var _stopSync = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function
|
|
32699
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function
|
|
32700
|
-
while (1) switch (
|
|
32825
|
+
var _stopSync = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.mark(function _callee24() {
|
|
32826
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_5___default.a.wrap(function _callee24$(_context24) {
|
|
32827
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
32701
32828
|
case 0:
|
|
32702
32829
|
this._forceEnableSync = false;
|
|
32703
32830
|
case 1:
|
|
32704
32831
|
case "end":
|
|
32705
|
-
return
|
|
32832
|
+
return _context24.stop();
|
|
32706
32833
|
}
|
|
32707
|
-
},
|
|
32834
|
+
}, _callee24, this);
|
|
32708
32835
|
}));
|
|
32709
32836
|
function stopSync() {
|
|
32710
32837
|
return _stopSync.apply(this, arguments);
|
|
@@ -33182,7 +33309,7 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
33182
33309
|
// ?
|
|
33183
33310
|
data: payload
|
|
33184
33311
|
});
|
|
33185
|
-
mqttAdapter.
|
|
33312
|
+
mqttAdapter.publish(getTopic(roomId), _payload);
|
|
33186
33313
|
},
|
|
33187
33314
|
subscribeEvent: function subscribeEvent(roomId, callback) {
|
|
33188
33315
|
if (is_js__WEBPACK_IMPORTED_MODULE_0___default.a.undefined(roomId)) throw new Error('`roomId` required');
|
|
@@ -33192,7 +33319,7 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
33192
33319
|
var topic = getTopic(roomId);
|
|
33193
33320
|
// Only allow 1 subcription for now
|
|
33194
33321
|
if (subscribedTopics[topic]) return;
|
|
33195
|
-
mqttAdapter.
|
|
33322
|
+
mqttAdapter.subscribe(topic);
|
|
33196
33323
|
var cb = function cb(payload) {
|
|
33197
33324
|
var parsedPayload = JSON.parse(payload);
|
|
33198
33325
|
callback(parsedPayload);
|
|
@@ -33205,7 +33332,7 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
33205
33332
|
if (is_js__WEBPACK_IMPORTED_MODULE_0___default.a.not.string(roomId)) throw new TypeError('`roomId` must have type of string');
|
|
33206
33333
|
var topic = getTopic(roomId);
|
|
33207
33334
|
if (!subscribedTopics[topic]) return;
|
|
33208
|
-
mqttAdapter.
|
|
33335
|
+
mqttAdapter.unsubscribe(topic);
|
|
33209
33336
|
events.off(topic, subscribedTopics[topic]);
|
|
33210
33337
|
subscribedTopics[topic] = null;
|
|
33211
33338
|
delete subscribedTopics[topic];
|
|
@@ -33292,83 +33419,68 @@ var ExpiredTokenAdapter = /*#__PURE__*/function () {
|
|
|
33292
33419
|
this._expiredAt = new Date(expiredAt);
|
|
33293
33420
|
}
|
|
33294
33421
|
this._isExpiredTokenEnabled = this._refreshToken != null && this._expiredAt != null;
|
|
33295
|
-
|
|
33296
|
-
// this._timerId = setInterval(this._checkToken, 1000)
|
|
33297
|
-
this._checkToken();
|
|
33422
|
+
this._setTimer(this._expiredAt);
|
|
33298
33423
|
}
|
|
33424
|
+
|
|
33425
|
+
/**
|
|
33426
|
+
* @param {Date | null} expiredAt
|
|
33427
|
+
*
|
|
33428
|
+
* Sets a timer to refresh the authentication token when it expires.
|
|
33429
|
+
* If the token is already expired, it will immediately trigger the refresh.
|
|
33430
|
+
*/
|
|
33299
33431
|
return _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(ExpiredTokenAdapter, [{
|
|
33300
|
-
key: "
|
|
33432
|
+
key: "_setTimer",
|
|
33433
|
+
value: function _setTimer(expiredAt) {
|
|
33434
|
+
var _expiredAt$getTime,
|
|
33435
|
+
_this = this;
|
|
33436
|
+
if (this._timerId != null) {
|
|
33437
|
+
clearTimeout(this._timerId);
|
|
33438
|
+
this._timerId = null;
|
|
33439
|
+
}
|
|
33440
|
+
var delay = Math.floor(((_expiredAt$getTime = expiredAt === null || expiredAt === void 0 ? void 0 : expiredAt.getTime()) !== null && _expiredAt$getTime !== void 0 ? _expiredAt$getTime : NaN) - Date.now());
|
|
33441
|
+
if (!isNaN(delay) && delay > 0) {
|
|
33442
|
+
this._timerId = setTimeout(function () {
|
|
33443
|
+
_this.refreshAuthToken();
|
|
33444
|
+
}, delay);
|
|
33445
|
+
}
|
|
33446
|
+
}
|
|
33447
|
+
}, {
|
|
33448
|
+
key: "refreshAuthToken",
|
|
33301
33449
|
value: function () {
|
|
33302
|
-
var
|
|
33303
|
-
var
|
|
33450
|
+
var _refreshAuthToken = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.mark(function _callee() {
|
|
33451
|
+
var _this2 = this;
|
|
33304
33452
|
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.wrap(function _callee$(_context) {
|
|
33305
33453
|
while (1) switch (_context.prev = _context.next) {
|
|
33306
33454
|
case 0:
|
|
33307
|
-
timeToSleep = 5000; // 5 seconds
|
|
33308
33455
|
if (!(this._getAuthenticationStatus() == false || this._refreshToken == null)) {
|
|
33309
|
-
_context.next =
|
|
33456
|
+
_context.next = 2;
|
|
33310
33457
|
break;
|
|
33311
33458
|
}
|
|
33312
33459
|
return _context.abrupt("return");
|
|
33313
|
-
case
|
|
33314
|
-
|
|
33315
|
-
_context.next = 9;
|
|
33316
|
-
break;
|
|
33317
|
-
}
|
|
33318
|
-
now = Date.now(); // @ts-ignore
|
|
33319
|
-
diff = Math.floor((this._expiredAt - now) / 1000); // console.log('diff', diff)
|
|
33320
|
-
if (!(diff < timeToSleep / 1000)) {
|
|
33321
|
-
_context.next = 9;
|
|
33322
|
-
break;
|
|
33323
|
-
}
|
|
33324
|
-
_context.next = 9;
|
|
33325
|
-
return this.refreshAuthToken();
|
|
33326
|
-
case 9:
|
|
33327
|
-
_context.next = 11;
|
|
33328
|
-
return Object(_util__WEBPACK_IMPORTED_MODULE_5__["sleep"])(timeToSleep);
|
|
33329
|
-
case 11:
|
|
33330
|
-
this._checkToken();
|
|
33331
|
-
case 12:
|
|
33332
|
-
case "end":
|
|
33333
|
-
return _context.stop();
|
|
33334
|
-
}
|
|
33335
|
-
}, _callee, this);
|
|
33336
|
-
}));
|
|
33337
|
-
function _checkToken() {
|
|
33338
|
-
return _checkToken2.apply(this, arguments);
|
|
33339
|
-
}
|
|
33340
|
-
return _checkToken;
|
|
33341
|
-
}()
|
|
33342
|
-
}, {
|
|
33343
|
-
key: "refreshAuthToken",
|
|
33344
|
-
value: function () {
|
|
33345
|
-
var _refreshAuthToken = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.mark(function _callee2() {
|
|
33346
|
-
var _this = this;
|
|
33347
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.wrap(function _callee2$(_context2) {
|
|
33348
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
33349
|
-
case 0:
|
|
33350
|
-
return _context2.abrupt("return", this._http.post('api/v2/sdk/refresh_user_token', {
|
|
33460
|
+
case 2:
|
|
33461
|
+
return _context.abrupt("return", this._http.post('api/v2/sdk/refresh_user_token', {
|
|
33351
33462
|
user_id: this._userId,
|
|
33352
33463
|
refresh_token: this._refreshToken
|
|
33353
33464
|
}).then(function (r) {
|
|
33354
|
-
var
|
|
33465
|
+
var _this2$_onTokenRefres;
|
|
33355
33466
|
var res = r.body.results;
|
|
33356
33467
|
var token = res.token;
|
|
33357
|
-
|
|
33358
|
-
|
|
33468
|
+
_this2._refreshToken = res.refresh_token;
|
|
33469
|
+
_this2._http.setToken(res.token);
|
|
33359
33470
|
if (res.token_expires_at != null) {
|
|
33360
|
-
|
|
33471
|
+
_this2._expiredAt = new Date(res.token_expires_at);
|
|
33361
33472
|
}
|
|
33362
33473
|
|
|
33363
33474
|
// @ts-ignore
|
|
33364
|
-
(
|
|
33475
|
+
(_this2$_onTokenRefres = _this2._onTokenRefreshed) === null || _this2$_onTokenRefres === void 0 || _this2$_onTokenRefres.call(_this2, token, _this2._refreshToken, _this2._expiredAt);
|
|
33476
|
+
_this2._setTimer(_this2._expiredAt);
|
|
33365
33477
|
return res;
|
|
33366
33478
|
}));
|
|
33367
|
-
case
|
|
33479
|
+
case 3:
|
|
33368
33480
|
case "end":
|
|
33369
|
-
return
|
|
33481
|
+
return _context.stop();
|
|
33370
33482
|
}
|
|
33371
|
-
},
|
|
33483
|
+
}, _callee, this);
|
|
33372
33484
|
}));
|
|
33373
33485
|
function refreshAuthToken() {
|
|
33374
33486
|
return _refreshAuthToken.apply(this, arguments);
|
|
@@ -33378,19 +33490,19 @@ var ExpiredTokenAdapter = /*#__PURE__*/function () {
|
|
|
33378
33490
|
}, {
|
|
33379
33491
|
key: "logout",
|
|
33380
33492
|
value: function () {
|
|
33381
|
-
var _logout = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.mark(function
|
|
33382
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.wrap(function
|
|
33383
|
-
while (1) switch (
|
|
33493
|
+
var _logout = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.mark(function _callee2() {
|
|
33494
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.wrap(function _callee2$(_context2) {
|
|
33495
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
33384
33496
|
case 0:
|
|
33385
|
-
return
|
|
33497
|
+
return _context2.abrupt("return", this._http.post('api/v2/sdk/logout', {
|
|
33386
33498
|
user_id: this._userId,
|
|
33387
33499
|
token: this._http.token
|
|
33388
33500
|
}));
|
|
33389
33501
|
case 1:
|
|
33390
33502
|
case "end":
|
|
33391
|
-
return
|
|
33503
|
+
return _context2.stop();
|
|
33392
33504
|
}
|
|
33393
|
-
},
|
|
33505
|
+
}, _callee2, this);
|
|
33394
33506
|
}));
|
|
33395
33507
|
function logout() {
|
|
33396
33508
|
return _logout.apply(this, arguments);
|
|
@@ -33453,12 +33565,18 @@ function hookAdapterFactory() {
|
|
|
33453
33565
|
"use strict";
|
|
33454
33566
|
__webpack_require__.r(__webpack_exports__);
|
|
33455
33567
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return HttpAdapter; });
|
|
33456
|
-
/* harmony import */ var
|
|
33457
|
-
/* harmony import */ var
|
|
33458
|
-
/* harmony import */ var
|
|
33459
|
-
/* harmony import */ var
|
|
33460
|
-
/* harmony import */ var
|
|
33461
|
-
/* harmony import */ var
|
|
33568
|
+
/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ "./node_modules/.pnpm/@babel+runtime@7.26.9/node_modules/@babel/runtime/helpers/asyncToGenerator.js");
|
|
33569
|
+
/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__);
|
|
33570
|
+
/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/.pnpm/@babel+runtime@7.26.9/node_modules/@babel/runtime/helpers/classCallCheck.js");
|
|
33571
|
+
/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__);
|
|
33572
|
+
/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/.pnpm/@babel+runtime@7.26.9/node_modules/@babel/runtime/helpers/createClass.js");
|
|
33573
|
+
/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__);
|
|
33574
|
+
/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/.pnpm/@babel+runtime@7.26.9/node_modules/@babel/runtime/regenerator/index.js");
|
|
33575
|
+
/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3__);
|
|
33576
|
+
/* harmony import */ var superagent__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! superagent */ "./node_modules/.pnpm/superagent@3.8.3/node_modules/superagent/lib/client.js");
|
|
33577
|
+
/* harmony import */ var superagent__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(superagent__WEBPACK_IMPORTED_MODULE_4__);
|
|
33578
|
+
|
|
33579
|
+
|
|
33462
33580
|
|
|
33463
33581
|
|
|
33464
33582
|
|
|
@@ -33468,16 +33586,19 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
33468
33586
|
AppId = _ref.AppId,
|
|
33469
33587
|
userId = _ref.userId,
|
|
33470
33588
|
version = _ref.version,
|
|
33471
|
-
getCustomHeader = _ref.getCustomHeader
|
|
33472
|
-
|
|
33589
|
+
getCustomHeader = _ref.getCustomHeader,
|
|
33590
|
+
expiredTokenAdapterGetter = _ref.expiredTokenAdapterGetter;
|
|
33591
|
+
_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default()(this, HttpAdapter);
|
|
33473
33592
|
this.baseURL = baseURL;
|
|
33474
33593
|
this.token = null;
|
|
33475
33594
|
this.userId = userId;
|
|
33476
33595
|
this.AppId = AppId;
|
|
33477
33596
|
this.version = version;
|
|
33478
33597
|
this.getCustomHeader = getCustomHeader;
|
|
33598
|
+
/** @type {() => import('./expired-token.js').ExpiredTokenAdapter} */
|
|
33599
|
+
this._expiredTokenAdapterGetter = expiredTokenAdapterGetter;
|
|
33479
33600
|
}
|
|
33480
|
-
return
|
|
33601
|
+
return _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(HttpAdapter, [{
|
|
33481
33602
|
key: "setToken",
|
|
33482
33603
|
value: function setToken(token) {
|
|
33483
33604
|
this.token = token;
|
|
@@ -33488,135 +33609,167 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
33488
33609
|
var _this = this;
|
|
33489
33610
|
var headers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33490
33611
|
var options = arguments.length > 2 ? arguments[2] : undefined;
|
|
33491
|
-
return
|
|
33492
|
-
var req
|
|
33493
|
-
|
|
33494
|
-
|
|
33495
|
-
|
|
33496
|
-
|
|
33497
|
-
|
|
33498
|
-
|
|
33612
|
+
return this._retryHelper(/*#__PURE__*/_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.mark(function _callee() {
|
|
33613
|
+
var req;
|
|
33614
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.wrap(function _callee$(_context) {
|
|
33615
|
+
while (1) switch (_context.prev = _context.next) {
|
|
33616
|
+
case 0:
|
|
33617
|
+
req = superagent__WEBPACK_IMPORTED_MODULE_4___default.a.get("".concat(_this.baseURL, "/").concat(path));
|
|
33618
|
+
if (options && options.baseURL) req = superagent__WEBPACK_IMPORTED_MODULE_4___default.a.get("".concat(options.baseURL, "/").concat(path));
|
|
33619
|
+
req = _this.setupHeaders(req, headers);
|
|
33620
|
+
return _context.abrupt("return", req);
|
|
33621
|
+
case 4:
|
|
33622
|
+
case "end":
|
|
33623
|
+
return _context.stop();
|
|
33499
33624
|
}
|
|
33500
|
-
|
|
33501
|
-
|
|
33502
|
-
});
|
|
33625
|
+
}, _callee);
|
|
33626
|
+
})));
|
|
33503
33627
|
}
|
|
33504
33628
|
// eslint-disable-next-line
|
|
33505
33629
|
}, {
|
|
33506
33630
|
key: "get_request",
|
|
33507
33631
|
value: function get_request(path) {
|
|
33508
|
-
var
|
|
33509
|
-
|
|
33510
|
-
|
|
33632
|
+
var _this2 = this;
|
|
33633
|
+
return this._retryHelper(/*#__PURE__*/_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.mark(function _callee2() {
|
|
33634
|
+
var req;
|
|
33635
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.wrap(function _callee2$(_context2) {
|
|
33636
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
33637
|
+
case 0:
|
|
33638
|
+
req = superagent__WEBPACK_IMPORTED_MODULE_4___default.a.get("".concat(_this2.baseURL, "/").concat(path));
|
|
33639
|
+
req = _this2.setupHeaders(req, {});
|
|
33640
|
+
return _context2.abrupt("return", req);
|
|
33641
|
+
case 3:
|
|
33642
|
+
case "end":
|
|
33643
|
+
return _context2.stop();
|
|
33644
|
+
}
|
|
33645
|
+
}, _callee2);
|
|
33646
|
+
})));
|
|
33511
33647
|
}
|
|
33512
33648
|
}, {
|
|
33513
33649
|
key: "post",
|
|
33514
33650
|
value: function post(path) {
|
|
33515
|
-
var
|
|
33651
|
+
var _this3 = this;
|
|
33516
33652
|
var body = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33517
33653
|
var headers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
33518
|
-
return
|
|
33519
|
-
var req
|
|
33520
|
-
|
|
33521
|
-
|
|
33522
|
-
|
|
33523
|
-
|
|
33524
|
-
|
|
33654
|
+
return this._retryHelper(/*#__PURE__*/_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.mark(function _callee3() {
|
|
33655
|
+
var req;
|
|
33656
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.wrap(function _callee3$(_context3) {
|
|
33657
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
33658
|
+
case 0:
|
|
33659
|
+
req = superagent__WEBPACK_IMPORTED_MODULE_4___default.a.post("".concat(_this3.baseURL, "/").concat(path));
|
|
33660
|
+
req = _this3.setupHeaders(req, headers);
|
|
33661
|
+
return _context3.abrupt("return", req.send(body).set('Content-Type', 'application/x-www-form-urlencoded'));
|
|
33662
|
+
case 3:
|
|
33663
|
+
case "end":
|
|
33664
|
+
return _context3.stop();
|
|
33525
33665
|
}
|
|
33526
|
-
|
|
33527
|
-
|
|
33528
|
-
});
|
|
33666
|
+
}, _callee3);
|
|
33667
|
+
})));
|
|
33529
33668
|
}
|
|
33530
33669
|
|
|
33531
33670
|
// eslint-disable-next-line
|
|
33532
33671
|
}, {
|
|
33533
33672
|
key: "post_json",
|
|
33534
33673
|
value: function post_json(path) {
|
|
33535
|
-
var
|
|
33674
|
+
var _this4 = this;
|
|
33536
33675
|
var body = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33537
33676
|
var headers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
33538
|
-
return
|
|
33539
|
-
var req
|
|
33540
|
-
|
|
33541
|
-
|
|
33542
|
-
|
|
33543
|
-
|
|
33544
|
-
|
|
33677
|
+
return this._retryHelper(/*#__PURE__*/_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.mark(function _callee4() {
|
|
33678
|
+
var req;
|
|
33679
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.wrap(function _callee4$(_context4) {
|
|
33680
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
33681
|
+
case 0:
|
|
33682
|
+
req = superagent__WEBPACK_IMPORTED_MODULE_4___default.a.post("".concat(_this4.baseURL, "/").concat(path));
|
|
33683
|
+
req = _this4.setupHeaders(req, headers);
|
|
33684
|
+
req.send(body);
|
|
33685
|
+
return _context4.abrupt("return", req);
|
|
33686
|
+
case 4:
|
|
33687
|
+
case "end":
|
|
33688
|
+
return _context4.stop();
|
|
33545
33689
|
}
|
|
33546
|
-
|
|
33547
|
-
|
|
33548
|
-
});
|
|
33690
|
+
}, _callee4);
|
|
33691
|
+
})));
|
|
33549
33692
|
}
|
|
33550
33693
|
}, {
|
|
33551
33694
|
key: "put",
|
|
33552
33695
|
value: function put(path) {
|
|
33553
|
-
var
|
|
33696
|
+
var _this5 = this;
|
|
33554
33697
|
var body = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33555
33698
|
var headers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
33556
|
-
return
|
|
33557
|
-
var req
|
|
33558
|
-
|
|
33559
|
-
|
|
33560
|
-
|
|
33561
|
-
|
|
33562
|
-
|
|
33699
|
+
return this._retryHelper(/*#__PURE__*/_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.mark(function _callee5() {
|
|
33700
|
+
var req;
|
|
33701
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.wrap(function _callee5$(_context5) {
|
|
33702
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
33703
|
+
case 0:
|
|
33704
|
+
req = superagent__WEBPACK_IMPORTED_MODULE_4___default.a.put("".concat(_this5.baseURL, "/").concat(path));
|
|
33705
|
+
req = _this5.setupHeaders(req, headers);
|
|
33706
|
+
return _context5.abrupt("return", req.send(body).set('Content-Type', 'application/x-www-form-urlencoded'));
|
|
33707
|
+
case 3:
|
|
33708
|
+
case "end":
|
|
33709
|
+
return _context5.stop();
|
|
33563
33710
|
}
|
|
33564
|
-
|
|
33565
|
-
|
|
33566
|
-
});
|
|
33711
|
+
}, _callee5);
|
|
33712
|
+
})));
|
|
33567
33713
|
}
|
|
33568
33714
|
}, {
|
|
33569
33715
|
key: "patch",
|
|
33570
33716
|
value: function patch(path) {
|
|
33571
|
-
var
|
|
33717
|
+
var _this6 = this;
|
|
33572
33718
|
var body = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33573
33719
|
var headers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
33574
|
-
return
|
|
33575
|
-
var req
|
|
33576
|
-
|
|
33577
|
-
|
|
33578
|
-
|
|
33579
|
-
|
|
33580
|
-
|
|
33720
|
+
return this._retryHelper(/*#__PURE__*/_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.mark(function _callee6() {
|
|
33721
|
+
var req;
|
|
33722
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.wrap(function _callee6$(_context6) {
|
|
33723
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
33724
|
+
case 0:
|
|
33725
|
+
req = superagent__WEBPACK_IMPORTED_MODULE_4___default.a.patch("".concat(_this6.baseURL, "/").concat(path));
|
|
33726
|
+
req = _this6.setupHeaders(req, headers);
|
|
33727
|
+
return _context6.abrupt("return", req.send(body).set('Content-Type', 'application/x-www-form-urlencoded'));
|
|
33728
|
+
case 3:
|
|
33729
|
+
case "end":
|
|
33730
|
+
return _context6.stop();
|
|
33581
33731
|
}
|
|
33582
|
-
|
|
33583
|
-
|
|
33584
|
-
});
|
|
33732
|
+
}, _callee6);
|
|
33733
|
+
})));
|
|
33585
33734
|
}
|
|
33586
33735
|
}, {
|
|
33587
33736
|
key: "del",
|
|
33588
33737
|
value: function del(path) {
|
|
33589
|
-
var
|
|
33738
|
+
var _this7 = this;
|
|
33590
33739
|
var body = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33591
33740
|
var headers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
33592
|
-
return
|
|
33593
|
-
var req
|
|
33594
|
-
|
|
33595
|
-
|
|
33596
|
-
|
|
33597
|
-
|
|
33598
|
-
|
|
33741
|
+
return this._retryHelper(/*#__PURE__*/_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.mark(function _callee7() {
|
|
33742
|
+
var req;
|
|
33743
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.wrap(function _callee7$(_context7) {
|
|
33744
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
33745
|
+
case 0:
|
|
33746
|
+
req = superagent__WEBPACK_IMPORTED_MODULE_4___default.a.del("".concat(_this7.baseURL, "/").concat(path));
|
|
33747
|
+
req = _this7.setupHeaders(req, headers);
|
|
33748
|
+
return _context7.abrupt("return", req.send(body).set('Content-Type', 'application/json'));
|
|
33749
|
+
case 3:
|
|
33750
|
+
case "end":
|
|
33751
|
+
return _context7.stop();
|
|
33599
33752
|
}
|
|
33600
|
-
|
|
33601
|
-
|
|
33602
|
-
});
|
|
33753
|
+
}, _callee7);
|
|
33754
|
+
})));
|
|
33603
33755
|
}
|
|
33604
33756
|
}, {
|
|
33605
33757
|
key: "setupHeaders",
|
|
33606
33758
|
value: function setupHeaders(req) {
|
|
33607
33759
|
var headers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33760
|
+
req.set('QISCUS-SDK-PLATFORM', 'javascript');
|
|
33608
33761
|
// let's give this default Authorization Header
|
|
33609
33762
|
if (this.AppId != null) {
|
|
33610
|
-
req.set(
|
|
33763
|
+
req.set('QISCUS-SDK-APP-ID', "".concat(this.AppId));
|
|
33611
33764
|
}
|
|
33612
33765
|
if (this.userId != null) {
|
|
33613
|
-
req.set(
|
|
33766
|
+
req.set('QISCUS-SDK-USER-ID', "".concat(this.userId));
|
|
33614
33767
|
}
|
|
33615
33768
|
if (this.token != null) {
|
|
33616
|
-
req.set(
|
|
33769
|
+
req.set('QISCUS-SDK-TOKEN', "".concat(this.token));
|
|
33617
33770
|
}
|
|
33618
33771
|
if (this.version != null) {
|
|
33619
|
-
req.set(
|
|
33772
|
+
req.set('QISCUS-SDK-VERSION', "".concat(this.version));
|
|
33620
33773
|
}
|
|
33621
33774
|
if (this.getCustomHeader != null) {
|
|
33622
33775
|
var customHeaders = this.getCustomHeader();
|
|
@@ -33634,16 +33787,53 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
33634
33787
|
}
|
|
33635
33788
|
return req;
|
|
33636
33789
|
}
|
|
33790
|
+
|
|
33791
|
+
/**
|
|
33792
|
+
* @param {() => request.Request} fn
|
|
33793
|
+
* @returns {Promise<unknown>}
|
|
33794
|
+
*/
|
|
33637
33795
|
}, {
|
|
33638
|
-
key: "
|
|
33639
|
-
value: function
|
|
33640
|
-
var
|
|
33641
|
-
|
|
33642
|
-
|
|
33643
|
-
|
|
33644
|
-
|
|
33796
|
+
key: "_retryHelper",
|
|
33797
|
+
value: (function () {
|
|
33798
|
+
var _retryHelper2 = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.mark(function _callee8(fn) {
|
|
33799
|
+
var _err$response, _err$response2, _body$error, status, body;
|
|
33800
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default.a.wrap(function _callee8$(_context8) {
|
|
33801
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
33802
|
+
case 0:
|
|
33803
|
+
_context8.prev = 0;
|
|
33804
|
+
_context8.next = 3;
|
|
33805
|
+
return fn();
|
|
33806
|
+
case 3:
|
|
33807
|
+
return _context8.abrupt("return", _context8.sent);
|
|
33808
|
+
case 6:
|
|
33809
|
+
_context8.prev = 6;
|
|
33810
|
+
_context8.t0 = _context8["catch"](0);
|
|
33811
|
+
status = _context8.t0 === null || _context8.t0 === void 0 || (_err$response = _context8.t0.response) === null || _err$response === void 0 ? void 0 : _err$response.status;
|
|
33812
|
+
body = _context8.t0 === null || _context8.t0 === void 0 || (_err$response2 = _context8.t0.response) === null || _err$response2 === void 0 ? void 0 : _err$response2.body;
|
|
33813
|
+
if (!(status === 403 && ((_body$error = body.error) === null || _body$error === void 0 || (_body$error = _body$error.message) === null || _body$error === void 0 ? void 0 : _body$error.toLowerCase()) === 'unauthorized. token is expired')) {
|
|
33814
|
+
_context8.next = 18;
|
|
33815
|
+
break;
|
|
33816
|
+
}
|
|
33817
|
+
_context8.next = 13;
|
|
33818
|
+
return this._expiredTokenAdapterGetter().refreshAuthToken();
|
|
33819
|
+
case 13:
|
|
33820
|
+
_context8.next = 15;
|
|
33821
|
+
return fn();
|
|
33822
|
+
case 15:
|
|
33823
|
+
return _context8.abrupt("return", _context8.sent);
|
|
33824
|
+
case 18:
|
|
33825
|
+
throw _context8.t0;
|
|
33826
|
+
case 19:
|
|
33827
|
+
case "end":
|
|
33828
|
+
return _context8.stop();
|
|
33829
|
+
}
|
|
33830
|
+
}, _callee8, this, [[0, 6]]);
|
|
33831
|
+
}));
|
|
33832
|
+
function _retryHelper(_x) {
|
|
33833
|
+
return _retryHelper2.apply(this, arguments);
|
|
33645
33834
|
}
|
|
33646
|
-
|
|
33835
|
+
return _retryHelper;
|
|
33836
|
+
}())
|
|
33647
33837
|
}]);
|
|
33648
33838
|
}();
|
|
33649
33839
|
|
|
@@ -33910,7 +34100,7 @@ var MqttAdapter = /*#__PURE__*/function () {
|
|
|
33910
34100
|
while (1) switch (_context2.prev = _context2.next) {
|
|
33911
34101
|
case 0:
|
|
33912
34102
|
this.shouldConnect = true;
|
|
33913
|
-
this.__mqtt_conneck();
|
|
34103
|
+
this.mqtt = this.__mqtt_conneck();
|
|
33914
34104
|
case 2:
|
|
33915
34105
|
case "end":
|
|
33916
34106
|
return _context2.stop();
|
|
@@ -33930,12 +34120,18 @@ var MqttAdapter = /*#__PURE__*/function () {
|
|
|
33930
34120
|
key: "closeConnection",
|
|
33931
34121
|
value: (function () {
|
|
33932
34122
|
var _closeConnection = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_2___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_6___default.a.mark(function _callee3() {
|
|
34123
|
+
var _this2 = this;
|
|
33933
34124
|
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_6___default.a.wrap(function _callee3$(_context3) {
|
|
33934
34125
|
while (1) switch (_context3.prev = _context3.next) {
|
|
33935
34126
|
case 0:
|
|
33936
34127
|
this.shouldConnect = false;
|
|
33937
|
-
this.mqtt.end(true)
|
|
33938
|
-
|
|
34128
|
+
this.mqtt.end(true, function (err) {
|
|
34129
|
+
if (err) {
|
|
34130
|
+
_this2.logger('error when close connection', err.message);
|
|
34131
|
+
}
|
|
34132
|
+
});
|
|
34133
|
+
this.mqtt = null;
|
|
34134
|
+
case 3:
|
|
33939
34135
|
case "end":
|
|
33940
34136
|
return _context3.stop();
|
|
33941
34137
|
}
|
|
@@ -33986,12 +34182,12 @@ var MqttAdapter = /*#__PURE__*/function () {
|
|
|
33986
34182
|
}
|
|
33987
34183
|
this.logger('subscribe to', args);
|
|
33988
34184
|
this.subscribtionBuffer.push(args);
|
|
33989
|
-
|
|
33990
|
-
|
|
34185
|
+
while (this.mqtt != null && this.subscribtionBuffer.length > 0) {
|
|
34186
|
+
var subs = this.subscribtionBuffer.shift();
|
|
34187
|
+
if (subs != null) {
|
|
33991
34188
|
var _this$mqtt;
|
|
33992
|
-
|
|
33993
|
-
|
|
33994
|
-
} while (this.subscribtionBuffer.length > 0);
|
|
34189
|
+
(_this$mqtt = this.mqtt).subscribe.apply(_this$mqtt, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(subs));
|
|
34190
|
+
}
|
|
33995
34191
|
}
|
|
33996
34192
|
}
|
|
33997
34193
|
}, {
|
|
@@ -34000,16 +34196,13 @@ var MqttAdapter = /*#__PURE__*/function () {
|
|
|
34000
34196
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
34001
34197
|
args[_key3] = arguments[_key3];
|
|
34002
34198
|
}
|
|
34003
|
-
this.logger('unsubscribe from', args);
|
|
34004
34199
|
this.unsubscribtionBuffer.push(args);
|
|
34005
|
-
|
|
34006
|
-
|
|
34007
|
-
|
|
34008
|
-
|
|
34009
|
-
|
|
34010
|
-
|
|
34011
|
-
}
|
|
34012
|
-
} while (this.unsubscribtionBuffer.length > 0);
|
|
34200
|
+
while (this.mqtt != null && this.unsubscribtionBuffer.length > 0) {
|
|
34201
|
+
var subs = this.unsubscribtionBuffer.shift();
|
|
34202
|
+
if (subs != null) {
|
|
34203
|
+
var _this$mqtt2;
|
|
34204
|
+
(_this$mqtt2 = this.mqtt).unsubscribe.apply(_this$mqtt2, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(subs));
|
|
34205
|
+
}
|
|
34013
34206
|
}
|
|
34014
34207
|
}
|
|
34015
34208
|
}, {
|
|
@@ -34021,12 +34214,12 @@ var MqttAdapter = /*#__PURE__*/function () {
|
|
|
34021
34214
|
payload: payload,
|
|
34022
34215
|
options: options
|
|
34023
34216
|
});
|
|
34024
|
-
|
|
34217
|
+
while (this.mqtt != null && this.publishBuffer.length > 0) {
|
|
34025
34218
|
var data = this.publishBuffer.shift();
|
|
34026
34219
|
if (data != null) {
|
|
34027
|
-
|
|
34220
|
+
this.mqtt.publish(data.topic, data.payload.toString(), data.options);
|
|
34028
34221
|
}
|
|
34029
|
-
}
|
|
34222
|
+
}
|
|
34030
34223
|
}
|
|
34031
34224
|
}, {
|
|
34032
34225
|
key: "emit",
|
|
@@ -34118,13 +34311,13 @@ var MqttAdapter = /*#__PURE__*/function () {
|
|
|
34118
34311
|
}, {
|
|
34119
34312
|
key: "notificationHandler",
|
|
34120
34313
|
value: function notificationHandler(topic, message) {
|
|
34121
|
-
var
|
|
34314
|
+
var _this3 = this;
|
|
34122
34315
|
this.logger('on:notification', message);
|
|
34123
34316
|
message = JSON.parse(message);
|
|
34124
34317
|
var data = message.payload.data;
|
|
34125
34318
|
if ('deleted_messages' in data) {
|
|
34126
34319
|
data.deleted_messages.forEach(function (message) {
|
|
34127
|
-
|
|
34320
|
+
_this3.emit('comment-deleted', {
|
|
34128
34321
|
roomId: message.room_id,
|
|
34129
34322
|
commentUniqueIds: message.message_unique_ids,
|
|
34130
34323
|
isForEveryone: true,
|
|
@@ -34134,7 +34327,7 @@ var MqttAdapter = /*#__PURE__*/function () {
|
|
|
34134
34327
|
}
|
|
34135
34328
|
if ('deleted_rooms' in data) {
|
|
34136
34329
|
data.deleted_rooms.forEach(function (room) {
|
|
34137
|
-
|
|
34330
|
+
_this3.emit('room-cleared', room);
|
|
34138
34331
|
});
|
|
34139
34332
|
}
|
|
34140
34333
|
}
|
|
@@ -34647,16 +34840,20 @@ function synchronizeFactory(getHttp, getInterval, getSync, getId, logger) {
|
|
|
34647
34840
|
}
|
|
34648
34841
|
result = _step.value;
|
|
34649
34842
|
try {
|
|
34650
|
-
|
|
34651
|
-
|
|
34652
|
-
|
|
34653
|
-
messages
|
|
34654
|
-
|
|
34655
|
-
|
|
34656
|
-
|
|
34843
|
+
emitter.emit('synchronize', Date.now());
|
|
34844
|
+
if ((result === null || result === void 0 ? void 0 : result.lastMessageId) != null && (result === null || result === void 0 ? void 0 : result.messages) != null) {
|
|
34845
|
+
messageId = result.lastMessageId;
|
|
34846
|
+
messages = result.messages;
|
|
34847
|
+
if (messageId > getId()) {
|
|
34848
|
+
messages.forEach(function (m) {
|
|
34849
|
+
return emitter.emit('message.new', m);
|
|
34850
|
+
});
|
|
34851
|
+
emitter.emit('last-message-id.new', messageId);
|
|
34852
|
+
}
|
|
34657
34853
|
}
|
|
34658
34854
|
} catch (e) {
|
|
34659
34855
|
logger('error when sync', e.message);
|
|
34856
|
+
console.log('error when sync', e);
|
|
34660
34857
|
}
|
|
34661
34858
|
case 9:
|
|
34662
34859
|
_iteratorAbruptCompletion = false;
|
|
@@ -34905,6 +35102,9 @@ function SyncAdapter(getHttpAdapter, _ref) {
|
|
|
34905
35102
|
syncFactory.on('message.new', function (m) {
|
|
34906
35103
|
return emitter.emit('message.new', m);
|
|
34907
35104
|
});
|
|
35105
|
+
syncFactory.on('synchronize', function (m) {
|
|
35106
|
+
return emitter.emit('synchronize', m);
|
|
35107
|
+
});
|
|
34908
35108
|
syncFactory.run()["catch"](function (err) {
|
|
34909
35109
|
return logger('got error when sync', err);
|
|
34910
35110
|
});
|
|
@@ -34939,6 +35139,12 @@ function SyncAdapter(getHttpAdapter, _ref) {
|
|
|
34939
35139
|
get off() {
|
|
34940
35140
|
return emitter.off;
|
|
34941
35141
|
},
|
|
35142
|
+
get interval() {
|
|
35143
|
+
return getInterval();
|
|
35144
|
+
},
|
|
35145
|
+
get enabled() {
|
|
35146
|
+
return enableSync();
|
|
35147
|
+
},
|
|
34942
35148
|
synchronize: function synchronize() {
|
|
34943
35149
|
syncFactory.synchronize();
|
|
34944
35150
|
},
|