qiscus-sdk-core 2.13.1 → 2.13.3
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
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.13.
|
|
29969
|
+
module.exports = JSON.parse("{\"name\":\"qiscus-sdk-core\",\"version\":\"2.13.3\",\"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
|
|
|
@@ -30743,6 +30743,11 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
30743
30743
|
self.selected.comments[commentToBeFound].message = 'this message has been deleted';
|
|
30744
30744
|
}
|
|
30745
30745
|
}
|
|
30746
|
+
|
|
30747
|
+
// Find last comment object on `self.selected.comments` array
|
|
30748
|
+
var lastComment = self.selected.comments[self.selected.comments.length - 1];
|
|
30749
|
+
self.selected.last_comment_id = lastComment.id;
|
|
30750
|
+
self.selected.last_comment_message = lastComment.message;
|
|
30746
30751
|
});
|
|
30747
30752
|
}
|
|
30748
30753
|
if (self.options.commentDeletedCallback) {
|
|
@@ -33287,83 +33292,68 @@ var ExpiredTokenAdapter = /*#__PURE__*/function () {
|
|
|
33287
33292
|
this._expiredAt = new Date(expiredAt);
|
|
33288
33293
|
}
|
|
33289
33294
|
this._isExpiredTokenEnabled = this._refreshToken != null && this._expiredAt != null;
|
|
33290
|
-
|
|
33291
|
-
// this._timerId = setInterval(this._checkToken, 1000)
|
|
33292
|
-
this._checkToken();
|
|
33295
|
+
this._setTimer(this._expiredAt);
|
|
33293
33296
|
}
|
|
33297
|
+
|
|
33298
|
+
/**
|
|
33299
|
+
* @param {Date | null} expiredAt
|
|
33300
|
+
*
|
|
33301
|
+
* Sets a timer to refresh the authentication token when it expires.
|
|
33302
|
+
* If the token is already expired, it will immediately trigger the refresh.
|
|
33303
|
+
*/
|
|
33294
33304
|
return _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(ExpiredTokenAdapter, [{
|
|
33295
|
-
key: "
|
|
33305
|
+
key: "_setTimer",
|
|
33306
|
+
value: function _setTimer(expiredAt) {
|
|
33307
|
+
var _expiredAt$getTime,
|
|
33308
|
+
_this = this;
|
|
33309
|
+
if (this._timerId != null) {
|
|
33310
|
+
clearTimeout(this._timerId);
|
|
33311
|
+
this._timerId = null;
|
|
33312
|
+
}
|
|
33313
|
+
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());
|
|
33314
|
+
if (!isNaN(delay) && delay > 0) {
|
|
33315
|
+
this._timerId = setTimeout(function () {
|
|
33316
|
+
_this.refreshAuthToken();
|
|
33317
|
+
}, delay);
|
|
33318
|
+
}
|
|
33319
|
+
}
|
|
33320
|
+
}, {
|
|
33321
|
+
key: "refreshAuthToken",
|
|
33296
33322
|
value: function () {
|
|
33297
|
-
var
|
|
33298
|
-
var
|
|
33323
|
+
var _refreshAuthToken = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.mark(function _callee() {
|
|
33324
|
+
var _this2 = this;
|
|
33299
33325
|
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.wrap(function _callee$(_context) {
|
|
33300
33326
|
while (1) switch (_context.prev = _context.next) {
|
|
33301
33327
|
case 0:
|
|
33302
|
-
timeToSleep = 5000; // 5 seconds
|
|
33303
33328
|
if (!(this._getAuthenticationStatus() == false || this._refreshToken == null)) {
|
|
33304
|
-
_context.next =
|
|
33329
|
+
_context.next = 2;
|
|
33305
33330
|
break;
|
|
33306
33331
|
}
|
|
33307
33332
|
return _context.abrupt("return");
|
|
33308
|
-
case
|
|
33309
|
-
|
|
33310
|
-
_context.next = 9;
|
|
33311
|
-
break;
|
|
33312
|
-
}
|
|
33313
|
-
now = Date.now(); // @ts-ignore
|
|
33314
|
-
diff = Math.floor((this._expiredAt - now) / 1000); // console.log('diff', diff)
|
|
33315
|
-
if (!(diff < timeToSleep / 1000)) {
|
|
33316
|
-
_context.next = 9;
|
|
33317
|
-
break;
|
|
33318
|
-
}
|
|
33319
|
-
_context.next = 9;
|
|
33320
|
-
return this.refreshAuthToken();
|
|
33321
|
-
case 9:
|
|
33322
|
-
_context.next = 11;
|
|
33323
|
-
return Object(_util__WEBPACK_IMPORTED_MODULE_5__["sleep"])(timeToSleep);
|
|
33324
|
-
case 11:
|
|
33325
|
-
this._checkToken();
|
|
33326
|
-
case 12:
|
|
33327
|
-
case "end":
|
|
33328
|
-
return _context.stop();
|
|
33329
|
-
}
|
|
33330
|
-
}, _callee, this);
|
|
33331
|
-
}));
|
|
33332
|
-
function _checkToken() {
|
|
33333
|
-
return _checkToken2.apply(this, arguments);
|
|
33334
|
-
}
|
|
33335
|
-
return _checkToken;
|
|
33336
|
-
}()
|
|
33337
|
-
}, {
|
|
33338
|
-
key: "refreshAuthToken",
|
|
33339
|
-
value: function () {
|
|
33340
|
-
var _refreshAuthToken = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.mark(function _callee2() {
|
|
33341
|
-
var _this = this;
|
|
33342
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.wrap(function _callee2$(_context2) {
|
|
33343
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
33344
|
-
case 0:
|
|
33345
|
-
return _context2.abrupt("return", this._http.post('api/v2/sdk/refresh_user_token', {
|
|
33333
|
+
case 2:
|
|
33334
|
+
return _context.abrupt("return", this._http.post('api/v2/sdk/refresh_user_token', {
|
|
33346
33335
|
user_id: this._userId,
|
|
33347
33336
|
refresh_token: this._refreshToken
|
|
33348
33337
|
}).then(function (r) {
|
|
33349
|
-
var
|
|
33338
|
+
var _this2$_onTokenRefres;
|
|
33350
33339
|
var res = r.body.results;
|
|
33351
33340
|
var token = res.token;
|
|
33352
|
-
|
|
33353
|
-
|
|
33341
|
+
_this2._refreshToken = res.refresh_token;
|
|
33342
|
+
_this2._http.setToken(res.token);
|
|
33354
33343
|
if (res.token_expires_at != null) {
|
|
33355
|
-
|
|
33344
|
+
_this2._expiredAt = new Date(res.token_expires_at);
|
|
33356
33345
|
}
|
|
33357
33346
|
|
|
33358
33347
|
// @ts-ignore
|
|
33359
|
-
(
|
|
33348
|
+
(_this2$_onTokenRefres = _this2._onTokenRefreshed) === null || _this2$_onTokenRefres === void 0 || _this2$_onTokenRefres.call(_this2, token, _this2._refreshToken, _this2._expiredAt);
|
|
33349
|
+
_this2._setTimer(_this2._expiredAt);
|
|
33360
33350
|
return res;
|
|
33361
33351
|
}));
|
|
33362
|
-
case
|
|
33352
|
+
case 3:
|
|
33363
33353
|
case "end":
|
|
33364
|
-
return
|
|
33354
|
+
return _context.stop();
|
|
33365
33355
|
}
|
|
33366
|
-
},
|
|
33356
|
+
}, _callee, this);
|
|
33367
33357
|
}));
|
|
33368
33358
|
function refreshAuthToken() {
|
|
33369
33359
|
return _refreshAuthToken.apply(this, arguments);
|
|
@@ -33373,19 +33363,19 @@ var ExpiredTokenAdapter = /*#__PURE__*/function () {
|
|
|
33373
33363
|
}, {
|
|
33374
33364
|
key: "logout",
|
|
33375
33365
|
value: function () {
|
|
33376
|
-
var _logout = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.mark(function
|
|
33377
|
-
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.wrap(function
|
|
33378
|
-
while (1) switch (
|
|
33366
|
+
var _logout = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0___default()(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.mark(function _callee2() {
|
|
33367
|
+
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default.a.wrap(function _callee2$(_context2) {
|
|
33368
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
33379
33369
|
case 0:
|
|
33380
|
-
return
|
|
33370
|
+
return _context2.abrupt("return", this._http.post('api/v2/sdk/logout', {
|
|
33381
33371
|
user_id: this._userId,
|
|
33382
33372
|
token: this._http.token
|
|
33383
33373
|
}));
|
|
33384
33374
|
case 1:
|
|
33385
33375
|
case "end":
|
|
33386
|
-
return
|
|
33376
|
+
return _context2.stop();
|
|
33387
33377
|
}
|
|
33388
|
-
},
|
|
33378
|
+
}, _callee2, this);
|
|
33389
33379
|
}));
|
|
33390
33380
|
function logout() {
|
|
33391
33381
|
return _logout.apply(this, arguments);
|