qiscus-sdk-core 2.12.4 → 2.12.6-logger

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.
@@ -1,20 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = void 0;
9
-
10
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
10
  var _format = _interopRequireDefault(require("date-fns/format"));
15
-
16
11
  var _utils = require("./utils.js");
17
-
18
12
  var Comment = /*#__PURE__*/function () {
19
13
  function Comment(comment) {
20
14
  (0, _classCallCheck2["default"])(this, Comment);
@@ -36,8 +30,8 @@ var Comment = /*#__PURE__*/function () {
36
30
  this.unix_timestamp = comment.unix_timestamp;
37
31
  this.unix_nano_timestamp = comment.unix_nano_timestamp;
38
32
  this.extras = comment.extras;
39
- /* comment status */
40
33
 
34
+ /* comment status */
41
35
  this.is_deleted = comment.is_deleted;
42
36
  this.isPending = false;
43
37
  this.isFailed = false;
@@ -46,22 +40,23 @@ var Comment = /*#__PURE__*/function () {
46
40
  this.isSent = false;
47
41
  this.attachment = null;
48
42
  this.payload = comment.payload;
49
- this.status = comment.status; // manage comment type
43
+ this.status = comment.status;
50
44
 
45
+ // manage comment type
51
46
  if (comment.type === 'reply') {
52
47
  comment.payload.replied_comment_message = (0, _utils.escapeHTML)(comment.payload.replied_comment_message);
53
48
  comment.payload.text = (0, _utils.escapeHTML)(comment.payload.text);
54
- } // supported comment type text, account_linking, buttons
49
+ }
50
+
51
+ // supported comment type text, account_linking, buttons
55
52
  // let supported_comment_type = [
56
53
  // 'text','account_linking','buttons','reply','system_event','card', 'custom', 'contact_person', 'location',
57
54
  // 'carousel'
58
55
  // ];
59
-
60
-
61
56
  this.type = comment.type;
62
- this.subtype = comment.type === 'custom' ? comment.payload.type : null; // comment status
57
+ this.subtype = comment.type === 'custom' ? comment.payload.type : null;
58
+ // comment status
63
59
  // comment status
64
-
65
60
  if (comment.status === 'sent') {
66
61
  this.markAsSent();
67
62
  } else if (comment.status === 'delivered') {
@@ -70,8 +65,7 @@ var Comment = /*#__PURE__*/function () {
70
65
  this.markAsRead();
71
66
  }
72
67
  }
73
-
74
- (0, _createClass2["default"])(Comment, [{
68
+ return (0, _createClass2["default"])(Comment, [{
75
69
  key: "isAttachment",
76
70
  value: function isAttachment(message) {
77
71
  return message.substring(0, '[file]'.length) === '[file]';
@@ -119,9 +113,8 @@ var Comment = /*#__PURE__*/function () {
119
113
  key: "markAsDelivered",
120
114
  value: function markAsDelivered() {
121
115
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
122
- actor = _ref.actor,
123
- activeActorId = _ref.activeActorId;
124
-
116
+ actor = _ref.actor,
117
+ activeActorId = _ref.activeActorId;
125
118
  if (actor === activeActorId) return;
126
119
  if (this.isRead || this.status === 'read') return;
127
120
  this.isSent = true;
@@ -133,9 +126,8 @@ var Comment = /*#__PURE__*/function () {
133
126
  key: "markAsRead",
134
127
  value: function markAsRead() {
135
128
  var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
136
- actor = _ref2.actor,
137
- activeActorId = _ref2.activeActorId;
138
-
129
+ actor = _ref2.actor,
130
+ activeActorId = _ref2.activeActorId;
139
131
  if (actor === activeActorId) return;
140
132
  this.isPending = false;
141
133
  this.isSent = true;
@@ -149,9 +141,9 @@ var Comment = /*#__PURE__*/function () {
149
141
  this.isFailed = true;
150
142
  this.isPending = false;
151
143
  this.isStatus = 'failed';
152
- } // usually called when there's new comment with the same id
144
+ }
145
+ // usually called when there's new comment with the same id
153
146
  // we just need to update its content
154
-
155
147
  }, {
156
148
  key: "update",
157
149
  value: function update(data) {
@@ -160,16 +152,16 @@ var Comment = /*#__PURE__*/function () {
160
152
  this.before_id = data.comment_before_id;
161
153
  this.message = (0, _utils.escapeHTML)(data.message);
162
154
  /* comment status */
163
-
164
155
  if (data.payload) this.payload = data.payload;
165
- if (data.status) this.status = data.status; // manage comment type
156
+ if (data.status) this.status = data.status;
166
157
 
158
+ // manage comment type
167
159
  if (data.type === 'reply') {
168
160
  this.payload.replied_comment_message = (0, _utils.escapeHTML)(data.payload.replied_comment_message);
169
161
  this.payload.text = (0, _utils.escapeHTML)(data.payload.text);
170
- } // comment status
171
-
162
+ }
172
163
 
164
+ // comment status
173
165
  if (data.status === 'sent') {
174
166
  this.markAsSent();
175
167
  } else if (data.status === 'delivered') {
@@ -179,9 +171,6 @@ var Comment = /*#__PURE__*/function () {
179
171
  }
180
172
  }
181
173
  }]);
182
- return Comment;
183
174
  }();
184
-
185
- var _default = Comment;
186
- exports["default"] = _default;
175
+ var _default = exports["default"] = Comment;
187
176
  module.exports = exports.default;
package/lib/lib/Room.js CHANGED
@@ -1,20 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = exports.Room = void 0;
9
-
10
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
11
  var _Comment = _interopRequireDefault(require("./Comment"));
17
-
18
12
  /**
19
13
  * Holds chat rooms for qiscus chat sdk
20
14
  *
@@ -23,7 +17,7 @@ var _Comment = _interopRequireDefault(require("./Comment"));
23
17
  * @export
24
18
  * @class Room
25
19
  */
26
- var Room = /*#__PURE__*/function () {
20
+ var Room = exports.Room = /*#__PURE__*/function () {
27
21
  /**
28
22
  * Creates an instance of Room.
29
23
  * @param {any} roomData
@@ -58,8 +52,7 @@ var Room = /*#__PURE__*/function () {
58
52
  this.participantNumber = roomData.room_total_participants;
59
53
  if (roomData.comments) this.receiveComments(roomData.comments);
60
54
  }
61
-
62
- (0, _createClass2["default"])(Room, [{
55
+ return (0, _createClass2["default"])(Room, [{
63
56
  key: "isCurrentlySelected",
64
57
  value: function isCurrentlySelected(selected) {
65
58
  return this.id === selected.id;
@@ -83,23 +76,22 @@ var Room = /*#__PURE__*/function () {
83
76
  value: function setSubTitle(subtitle) {
84
77
  this.custom_subtitle = subtitle;
85
78
  }
79
+
86
80
  /**
87
81
  * Receive a single comment
88
82
  *
89
83
  * @param {Comment} comment
90
84
  * @memberof Room
91
85
  */
92
-
93
86
  }, {
94
87
  key: "receiveComment",
95
88
  value: function receiveComment(comment) {
96
89
  // Ignore if not from the same room
97
- if (comment.room_id !== this.id) return; // let's check first whether this room already has this specific comment
98
-
90
+ if (comment.room_id !== this.id) return;
91
+ // let's check first whether this room already has this specific comment
99
92
  var commentToFind = this.comments.find(function (cmt) {
100
93
  return cmt.unique_id === comment.unique_id;
101
94
  });
102
-
103
95
  if (commentToFind) {
104
96
  commentToFind.id = comment.id;
105
97
  commentToFind.message = comment.message;
@@ -114,7 +106,6 @@ var Room = /*#__PURE__*/function () {
114
106
  key: "receiveComments",
115
107
  value: function receiveComments(comments) {
116
108
  var _this = this;
117
-
118
109
  comments.forEach(function (comment) {
119
110
  _this.receiveComment(new _Comment["default"](comment));
120
111
  });
@@ -134,9 +125,5 @@ var Room = /*#__PURE__*/function () {
134
125
  if (!participantToFind) this.participants.push(participant);
135
126
  }
136
127
  }]);
137
- return Room;
138
128
  }();
139
-
140
- exports.Room = Room;
141
- var _default = Room;
142
- exports["default"] = _default;
129
+ var _default = exports["default"] = Room;
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = void 0;
9
-
10
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
- var AuthAdapter = /*#__PURE__*/function () {
10
+ var AuthAdapter = exports["default"] = /*#__PURE__*/function () {
15
11
  /**
16
12
  * Params used in this class
17
13
  * @method constructor
@@ -25,8 +21,7 @@ var AuthAdapter = /*#__PURE__*/function () {
25
21
  this.userId = null;
26
22
  this.autoRefreshToken = false;
27
23
  }
28
-
29
- (0, _createClass2["default"])(AuthAdapter, [{
24
+ return (0, _createClass2["default"])(AuthAdapter, [{
30
25
  key: "getNonce",
31
26
  value: function getNonce() {
32
27
  return this.HTTPAdapter.post('api/v2/sdk/auth/nonce').then(function (res) {
@@ -37,7 +32,6 @@ var AuthAdapter = /*#__PURE__*/function () {
37
32
  key: "loginOrRegister",
38
33
  value: function loginOrRegister(params) {
39
34
  var _this = this;
40
-
41
35
  return this.HTTPAdapter.post('api/v2/sdk/login_or_register', params).then(function (resp) {
42
36
  if (resp.body.status !== 200) return Promise.reject(resp);
43
37
  var result = resp.body.results;
@@ -50,7 +44,6 @@ var AuthAdapter = /*#__PURE__*/function () {
50
44
  key: "verifyIdentityToken",
51
45
  value: function verifyIdentityToken(token) {
52
46
  var _this2 = this;
53
-
54
47
  return this.HTTPAdapter.post('api/v2/sdk/auth/verify_identity_token', {
55
48
  identity_token: token
56
49
  }).then(function (resp) {
@@ -64,7 +57,6 @@ var AuthAdapter = /*#__PURE__*/function () {
64
57
  key: "refreshAuthToken",
65
58
  value: function refreshAuthToken() {
66
59
  var _this3 = this;
67
-
68
60
  return this.HTTPAdapter.post('api/v2/sdk/refresh_user_token', {
69
61
  user_id: this.userId,
70
62
  refresh_token: this.refreshToken
@@ -85,8 +77,5 @@ var AuthAdapter = /*#__PURE__*/function () {
85
77
  });
86
78
  }
87
79
  }]);
88
- return AuthAdapter;
89
80
  }();
90
-
91
- exports["default"] = AuthAdapter;
92
81
  module.exports = exports.default;
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = CustomEventAdapter;
9
-
10
8
  var _is_js = _interopRequireDefault(require("is_js"));
11
-
12
9
  var _mitt = _interopRequireDefault(require("mitt"));
13
-
14
10
  function CustomEventAdapter(mqttAdapter, userId) {
15
11
  var events = (0, _mitt["default"])();
16
12
  var subscribedTopics = {};
@@ -18,24 +14,20 @@ function CustomEventAdapter(mqttAdapter, userId) {
18
14
  mqttAdapter.mqtt.on('message', function (topic, payload) {
19
15
  if (reTopic.test(topic)) events.emit(topic, payload);
20
16
  });
21
-
22
17
  var getTopic = function getTopic(roomId) {
23
18
  return "r/".concat(roomId, "/").concat(roomId, "/e");
24
19
  };
25
-
26
20
  return {
27
21
  publishEvent: function publishEvent(roomId, payload) {
28
22
  if (_is_js["default"].undefined(roomId)) throw new Error('`roomId` required');
29
23
  if (_is_js["default"].not.string(roomId)) throw new TypeError('`roomId` must have type of string');
30
24
  if (_is_js["default"].undefined(payload)) throw new Error('`payload` required');
31
25
  if (_is_js["default"].not.object(payload)) throw new TypeError('`payload` must have type of object');
32
-
33
26
  var _payload = JSON.stringify({
34
27
  sender: userId,
35
28
  // ?
36
29
  data: payload
37
30
  });
38
-
39
31
  mqttAdapter.mqtt.publish(getTopic(roomId), _payload);
40
32
  },
41
33
  subscribeEvent: function subscribeEvent(roomId, callback) {
@@ -43,16 +35,14 @@ function CustomEventAdapter(mqttAdapter, userId) {
43
35
  if (_is_js["default"].not.string(roomId)) throw new TypeError('`roomId` must have type of string');
44
36
  if (_is_js["default"].undefined(callback)) throw new Error('`callback` required');
45
37
  if (_is_js["default"].not["function"](callback)) throw new TypeError('`callback` must have type of function');
46
- var topic = getTopic(roomId); // Only allow 1 subcription for now
47
-
38
+ var topic = getTopic(roomId);
39
+ // Only allow 1 subcription for now
48
40
  if (subscribedTopics[topic]) return;
49
41
  mqttAdapter.mqtt.subscribe(topic);
50
-
51
42
  var cb = function cb(payload) {
52
43
  var parsedPayload = JSON.parse(payload);
53
44
  callback(parsedPayload);
54
45
  };
55
-
56
46
  events.on(topic, cb);
57
47
  subscribedTopics[topic] = cb;
58
48
  },
@@ -68,5 +58,4 @@ function CustomEventAdapter(mqttAdapter, userId) {
68
58
  }
69
59
  };
70
60
  }
71
-
72
61
  module.exports = exports.default;
@@ -1,40 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.ExpiredTokenAdapter = void 0;
9
-
10
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
-
20
13
  var _util = require("../util");
21
-
22
14
  // @ts-check
23
- var ExpiredTokenAdapter = /*#__PURE__*/function () {
24
- /** @type {boolean} */
25
-
26
- /** @type {string | null} */
27
-
28
- /** @type {Date | null} */
29
-
30
- /** @type {import('./http').default} */
31
-
32
- /** @type {(token: string, refreshToken: string, expiredAt: Date) => void | undefined} */
33
-
34
- /** @type {any} */
35
-
36
- /** @type {() => boolean} */
37
-
15
+ var ExpiredTokenAdapter = exports.ExpiredTokenAdapter = /*#__PURE__*/function () {
38
16
  /**
39
17
  * @constructor
40
18
  *
@@ -49,170 +27,143 @@ var ExpiredTokenAdapter = /*#__PURE__*/function () {
49
27
  */
50
28
  function ExpiredTokenAdapter(_ref) {
51
29
  var httpAdapter = _ref.httpAdapter,
52
- refreshToken = _ref.refreshToken,
53
- expiredAt = _ref.expiredAt,
54
- userId = _ref.userId,
55
- onTokenRefreshed = _ref.onTokenRefreshed,
56
- getAuthenticationStatus = _ref.getAuthenticationStatus;
30
+ refreshToken = _ref.refreshToken,
31
+ expiredAt = _ref.expiredAt,
32
+ userId = _ref.userId,
33
+ onTokenRefreshed = _ref.onTokenRefreshed,
34
+ getAuthenticationStatus = _ref.getAuthenticationStatus;
57
35
  (0, _classCallCheck2["default"])(this, ExpiredTokenAdapter);
36
+ /** @type {boolean} */
58
37
  (0, _defineProperty2["default"])(this, "_isExpiredTokenEnabled", false);
38
+ /** @type {string | null} */
59
39
  (0, _defineProperty2["default"])(this, "_refreshToken", null);
40
+ /** @type {Date | null} */
60
41
  (0, _defineProperty2["default"])(this, "_expiredAt", null);
42
+ /** @type {import('./http').default} */
61
43
  (0, _defineProperty2["default"])(this, "_http", void 0);
44
+ /** @type {(token: string, refreshToken: string, expiredAt: Date) => void | undefined} */
62
45
  (0, _defineProperty2["default"])(this, "_onTokenRefreshed", void 0);
46
+ /** @type {any} */
63
47
  (0, _defineProperty2["default"])(this, "_timerId", void 0);
48
+ /** @type {() => boolean} */
64
49
  (0, _defineProperty2["default"])(this, "_getAuthenticationStatus", void 0);
65
50
  this._http = httpAdapter;
66
- this._refreshToken = refreshToken; // this._expiredAt = expiredAt == null ? null : new Date(expiredAt)
67
-
51
+ this._refreshToken = refreshToken;
52
+ // this._expiredAt = expiredAt == null ? null : new Date(expiredAt)
68
53
  this._userId = userId;
69
54
  this._onTokenRefreshed = onTokenRefreshed;
70
55
  this._getAuthenticationStatus = getAuthenticationStatus;
71
-
72
56
  if (this._refreshToken != null && this._refreshToken === '') {
73
57
  this._refreshToken = null;
74
58
  }
75
-
76
59
  if (expiredAt != null && expiredAt !== '') {
77
60
  this._expiredAt = new Date(expiredAt);
78
61
  }
62
+ this._isExpiredTokenEnabled = this._refreshToken != null && this._expiredAt != null;
79
63
 
80
- this._isExpiredTokenEnabled = this._refreshToken != null && this._expiredAt != null; // this._timerId = setInterval(this._checkToken, 1000)
81
-
64
+ // this._timerId = setInterval(this._checkToken, 1000)
82
65
  this._checkToken();
83
66
  }
84
-
85
- (0, _createClass2["default"])(ExpiredTokenAdapter, [{
67
+ return (0, _createClass2["default"])(ExpiredTokenAdapter, [{
86
68
  key: "_checkToken",
87
69
  value: function () {
88
- var _checkToken2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
70
+ var _checkToken2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
89
71
  var timeToSleep, now, diff;
90
- return _regenerator["default"].wrap(function _callee$(_context) {
91
- while (1) {
92
- switch (_context.prev = _context.next) {
93
- case 0:
94
- timeToSleep = 5000; // 5 seconds
95
-
96
- if (!(this._getAuthenticationStatus() == false || this._refreshToken == null)) {
97
- _context.next = 3;
98
- break;
99
- }
100
-
101
- return _context.abrupt("return");
102
-
103
- case 3:
104
- if (!(this._expiredAt != null && this._isExpiredTokenEnabled)) {
105
- _context.next = 9;
106
- break;
107
- }
108
-
109
- now = Date.now(); // @ts-ignore
110
-
111
- diff = Math.floor((this._expiredAt - now) / 1000); // console.log('diff', diff)
112
-
113
- if (!(diff < timeToSleep / 1000)) {
114
- _context.next = 9;
115
- break;
116
- }
117
-
118
- _context.next = 9;
119
- return this.refreshAuthToken();
120
-
121
- case 9:
122
- _context.next = 11;
123
- return (0, _util.sleep)(timeToSleep);
124
-
125
- case 11:
126
- this._checkToken();
127
-
128
- case 12:
129
- case "end":
130
- return _context.stop();
131
- }
72
+ return _regenerator["default"].wrap(function (_context) {
73
+ while (1) switch (_context.prev = _context.next) {
74
+ case 0:
75
+ timeToSleep = 5000; // 5 seconds
76
+ if (!(this._getAuthenticationStatus() == false || this._refreshToken == null)) {
77
+ _context.next = 1;
78
+ break;
79
+ }
80
+ return _context.abrupt("return");
81
+ case 1:
82
+ if (!(this._expiredAt != null && this._isExpiredTokenEnabled)) {
83
+ _context.next = 2;
84
+ break;
85
+ }
86
+ now = Date.now(); // @ts-ignore
87
+ diff = Math.floor((this._expiredAt - now) / 1000); // console.log('diff', diff)
88
+ if (!(diff < timeToSleep / 1000)) {
89
+ _context.next = 2;
90
+ break;
91
+ }
92
+ _context.next = 2;
93
+ return this.refreshAuthToken();
94
+ case 2:
95
+ _context.next = 3;
96
+ return (0, _util.sleep)(timeToSleep);
97
+ case 3:
98
+ this._checkToken();
99
+ case 4:
100
+ case "end":
101
+ return _context.stop();
132
102
  }
133
103
  }, _callee, this);
134
104
  }));
135
-
136
105
  function _checkToken() {
137
106
  return _checkToken2.apply(this, arguments);
138
107
  }
139
-
140
108
  return _checkToken;
141
109
  }()
142
110
  }, {
143
111
  key: "refreshAuthToken",
144
112
  value: function () {
145
- var _refreshAuthToken = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
113
+ var _refreshAuthToken = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
146
114
  var _this = this;
115
+ return _regenerator["default"].wrap(function (_context2) {
116
+ while (1) switch (_context2.prev = _context2.next) {
117
+ case 0:
118
+ return _context2.abrupt("return", this._http.post('api/v2/sdk/refresh_user_token', {
119
+ user_id: this._userId,
120
+ refresh_token: this._refreshToken
121
+ }).then(function (r) {
122
+ var _this$_onTokenRefresh;
123
+ var res = r.body.results;
124
+ var token = res.token;
125
+ _this._refreshToken = res.refresh_token;
126
+ _this._http.setToken(res.token);
127
+ if (res.token_expires_at != null) {
128
+ _this._expiredAt = new Date(res.token_expires_at);
129
+ }
147
130
 
148
- return _regenerator["default"].wrap(function _callee2$(_context2) {
149
- while (1) {
150
- switch (_context2.prev = _context2.next) {
151
- case 0:
152
- return _context2.abrupt("return", this._http.post('api/v2/sdk/refresh_user_token', {
153
- user_id: this._userId,
154
- refresh_token: this._refreshToken
155
- }).then(function (r) {
156
- var _this$_onTokenRefresh;
157
-
158
- var res = r.body.results;
159
- var token = res.token;
160
- _this._refreshToken = res.refresh_token;
161
-
162
- _this._http.setToken(res.token);
163
-
164
- if (res.token_expires_at != null) {
165
- _this._expiredAt = new Date(res.token_expires_at);
166
- } // @ts-ignore
167
-
168
-
169
- (_this$_onTokenRefresh = _this._onTokenRefreshed) === null || _this$_onTokenRefresh === void 0 ? void 0 : _this$_onTokenRefresh.call(_this, token, _this._refreshToken, _this._expiredAt);
170
- return res;
171
- }));
172
-
173
- case 1:
174
- case "end":
175
- return _context2.stop();
176
- }
131
+ // @ts-ignore
132
+ (_this$_onTokenRefresh = _this._onTokenRefreshed) === null || _this$_onTokenRefresh === void 0 || _this$_onTokenRefresh.call(_this, token, _this._refreshToken, _this._expiredAt);
133
+ return res;
134
+ }));
135
+ case 1:
136
+ case "end":
137
+ return _context2.stop();
177
138
  }
178
139
  }, _callee2, this);
179
140
  }));
180
-
181
141
  function refreshAuthToken() {
182
142
  return _refreshAuthToken.apply(this, arguments);
183
143
  }
184
-
185
144
  return refreshAuthToken;
186
145
  }()
187
146
  }, {
188
147
  key: "logout",
189
148
  value: function () {
190
- var _logout = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
191
- return _regenerator["default"].wrap(function _callee3$(_context3) {
192
- while (1) {
193
- switch (_context3.prev = _context3.next) {
194
- case 0:
195
- return _context3.abrupt("return", this._http.post('api/v2/sdk/logout', {
196
- user_id: this._userId,
197
- token: this._http.token
198
- }));
199
-
200
- case 1:
201
- case "end":
202
- return _context3.stop();
203
- }
149
+ var _logout = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
150
+ return _regenerator["default"].wrap(function (_context3) {
151
+ while (1) switch (_context3.prev = _context3.next) {
152
+ case 0:
153
+ return _context3.abrupt("return", this._http.post('api/v2/sdk/logout', {
154
+ user_id: this._userId,
155
+ token: this._http.token
156
+ }));
157
+ case 1:
158
+ case "end":
159
+ return _context3.stop();
204
160
  }
205
161
  }, _callee3, this);
206
162
  }));
207
-
208
163
  function logout() {
209
164
  return _logout.apply(this, arguments);
210
165
  }
211
-
212
166
  return logout;
213
167
  }()
214
168
  }]);
215
- return ExpiredTokenAdapter;
216
- }();
217
-
218
- exports.ExpiredTokenAdapter = ExpiredTokenAdapter;
169
+ }();
@@ -3,22 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.hookAdapterFactory = hookAdapterFactory;
7
6
  exports.Hooks = void 0;
8
- var Hooks = {
7
+ exports.hookAdapterFactory = hookAdapterFactory;
8
+ var Hooks = exports.Hooks = {
9
9
  MESSAGE_BEFORE_SENT: "message::before-sent",
10
10
  MESSAGE_BEFORE_RECEIVED: "message::before-received"
11
11
  };
12
- exports.Hooks = Hooks;
13
-
14
12
  function hookAdapterFactory() {
15
13
  var hooks = {};
16
-
17
14
  var get = function get(key) {
18
15
  if (!Array.isArray(hooks[key])) hooks[key] = [];
19
16
  return hooks[key];
20
17
  };
21
-
22
18
  function intercept(hook, callback) {
23
19
  get(hook).push(callback);
24
20
  var index = get(hook).length;
@@ -26,13 +22,11 @@ function hookAdapterFactory() {
26
22
  return get(hook).splice(index, 1);
27
23
  };
28
24
  }
29
-
30
25
  function trigger(hook, payload) {
31
26
  return get(hook).reduce(function (acc, fn) {
32
27
  return Promise.resolve(acc).then(fn);
33
28
  }, Promise.resolve(payload));
34
29
  }
35
-
36
30
  return {
37
31
  trigger: trigger,
38
32
  intercept: intercept