qiscus-sdk-core 2.11.1 → 2.12.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.min.js +6 -4
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +107 -65
- package/lib/lib/adapters/auth.js +38 -2
- package/lib/lib/adapters/http.js +68 -11
- package/lib/lib/adapters/mqtt.js +2 -1
- package/package.json +18 -19
package/lib/lib/adapters/http.js
CHANGED
|
@@ -47,7 +47,12 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
47
47
|
if (options && options.baseURL) req = _superagent["default"].get("".concat(options.baseURL, "/").concat(path));
|
|
48
48
|
req = _this.setupHeaders(req, headers);
|
|
49
49
|
req.end(function (err, res) {
|
|
50
|
-
if (err)
|
|
50
|
+
if (err) {
|
|
51
|
+
_this._rethrowIfExpiredToken(err);
|
|
52
|
+
|
|
53
|
+
return reject(err);
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
return resolve(res);
|
|
52
57
|
});
|
|
53
58
|
});
|
|
@@ -73,7 +78,12 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
73
78
|
|
|
74
79
|
req = _this2.setupHeaders(req, headers);
|
|
75
80
|
req.send(body).set("Content-Type", "application/x-www-form-urlencoded").end(function (err, res) {
|
|
76
|
-
if (err)
|
|
81
|
+
if (err) {
|
|
82
|
+
_this2._rethrowIfExpiredToken(err);
|
|
83
|
+
|
|
84
|
+
return reject(err);
|
|
85
|
+
}
|
|
86
|
+
|
|
77
87
|
return resolve(res);
|
|
78
88
|
});
|
|
79
89
|
});
|
|
@@ -91,7 +101,12 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
91
101
|
|
|
92
102
|
req = _this3.setupHeaders(req, headers);
|
|
93
103
|
req.send(body).set("Content-Type", "application/json").end(function (err, res) {
|
|
94
|
-
if (err)
|
|
104
|
+
if (err) {
|
|
105
|
+
_this3._rethrowIfExpiredToken(err);
|
|
106
|
+
|
|
107
|
+
return reject(err);
|
|
108
|
+
}
|
|
109
|
+
|
|
95
110
|
return resolve(res);
|
|
96
111
|
});
|
|
97
112
|
});
|
|
@@ -108,7 +123,12 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
108
123
|
|
|
109
124
|
req = _this4.setupHeaders(req, headers);
|
|
110
125
|
req.send(body).set("Content-Type", "application/x-www-form-urlencoded").end(function (err, res) {
|
|
111
|
-
if (err)
|
|
126
|
+
if (err) {
|
|
127
|
+
_this4._rethrowIfExpiredToken(err);
|
|
128
|
+
|
|
129
|
+
return reject(err);
|
|
130
|
+
}
|
|
131
|
+
|
|
112
132
|
return resolve(res);
|
|
113
133
|
});
|
|
114
134
|
});
|
|
@@ -125,7 +145,12 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
125
145
|
|
|
126
146
|
req = _this5.setupHeaders(req, headers);
|
|
127
147
|
req.send(body).set("Content-Type", "application/x-www-form-urlencoded").end(function (err, res) {
|
|
128
|
-
if (err)
|
|
148
|
+
if (err) {
|
|
149
|
+
_this5._rethrowIfExpiredToken(err);
|
|
150
|
+
|
|
151
|
+
return reject(err);
|
|
152
|
+
}
|
|
153
|
+
|
|
129
154
|
return resolve(res);
|
|
130
155
|
});
|
|
131
156
|
});
|
|
@@ -142,7 +167,12 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
142
167
|
|
|
143
168
|
req = _this6.setupHeaders(req, headers);
|
|
144
169
|
req.send(body).set("Content-Type", "application/json").end(function (err, res) {
|
|
145
|
-
if (err)
|
|
170
|
+
if (err) {
|
|
171
|
+
_this6._rethrowIfExpiredToken(err);
|
|
172
|
+
|
|
173
|
+
return reject(err);
|
|
174
|
+
}
|
|
175
|
+
|
|
146
176
|
return resolve(res);
|
|
147
177
|
});
|
|
148
178
|
});
|
|
@@ -151,14 +181,29 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
151
181
|
key: "setupHeaders",
|
|
152
182
|
value: function setupHeaders(req, headers) {
|
|
153
183
|
// let's give this default Authorization Header
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
184
|
+
if (this.AppId != null) {
|
|
185
|
+
req.set("QISCUS-SDK-APP-ID", "".concat(this.AppId));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (this.userId != null) {
|
|
189
|
+
req.set("QISCUS-SDK-USER-ID", "".concat(this.userId));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
console.log('this.token:', this.token);
|
|
193
|
+
|
|
194
|
+
if (this.token != null) {
|
|
195
|
+
req.set("QISCUS-SDK-TOKEN", "".concat(this.token));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (this.version != null) {
|
|
199
|
+
req.set("QISCUS-SDK-VERSION", "".concat(this.version));
|
|
200
|
+
}
|
|
158
201
|
|
|
159
202
|
if (this.getCustomHeader != null) {
|
|
160
203
|
var customHeaders = this.getCustomHeader();
|
|
161
|
-
Object.keys(customHeaders).
|
|
204
|
+
Object.keys(customHeaders).filter(function (key) {
|
|
205
|
+
return customHeaders[key] != null;
|
|
206
|
+
}).forEach(function (key) {
|
|
162
207
|
req.set(key, customHeaders[key]);
|
|
163
208
|
});
|
|
164
209
|
} // Return the req if no headers attached
|
|
@@ -172,6 +217,18 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
172
217
|
|
|
173
218
|
return req;
|
|
174
219
|
}
|
|
220
|
+
}, {
|
|
221
|
+
key: "_rethrowIfExpiredToken",
|
|
222
|
+
value: function _rethrowIfExpiredToken(err) {
|
|
223
|
+
var _err$response, _err$response2, _body$error, _body$error$message;
|
|
224
|
+
|
|
225
|
+
var status = (_err$response = err.response) === null || _err$response === void 0 ? void 0 : _err$response.status;
|
|
226
|
+
var body = (_err$response2 = err.response) === null || _err$response2 === void 0 ? void 0 : _err$response2.body;
|
|
227
|
+
|
|
228
|
+
if (status === 403 && ((_body$error = body.error) === null || _body$error === void 0 ? void 0 : (_body$error$message = _body$error.message) === null || _body$error$message === void 0 ? void 0 : _body$error$message.toLowerCase()) === 'unauthorized. token is expired') {
|
|
229
|
+
throw new Error('Token expired');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
175
232
|
}]);
|
|
176
233
|
return HttpAdapter;
|
|
177
234
|
}();
|
package/lib/lib/adapters/mqtt.js
CHANGED
|
@@ -587,7 +587,8 @@ var MqttAdapter = /*#__PURE__*/function () {
|
|
|
587
587
|
}, {
|
|
588
588
|
key: "disconnect",
|
|
589
589
|
value: function disconnect() {
|
|
590
|
-
this.publishPresence(this.core.userData.email, false)
|
|
590
|
+
this.publishPresence(this.core.userData.email, false);
|
|
591
|
+
this.unsubscribe(Object.keys(this.mqtt._resubscribeTopics));
|
|
591
592
|
}
|
|
592
593
|
}, {
|
|
593
594
|
key: "subscribeUserPresence",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qiscus-sdk-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Qiscus Web SDK Core",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "npm-run-all --parallel build:node build:web",
|
|
14
|
-
"build:dev": "npm-run-all --parallel build:node build:web:dev
|
|
14
|
+
"build:dev": "npm-run-all --parallel build:node build:web:dev",
|
|
15
15
|
"build:dev:watch": "npm-run-all --parallel build:web:watch serve",
|
|
16
16
|
"build:node": "babel -d lib src",
|
|
17
17
|
"build:node:watch": "babel -w -d lib src",
|
|
@@ -28,26 +28,25 @@
|
|
|
28
28
|
"serve": "http-server -p 1234 -c-1 dist"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/cli": "^7.
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
34
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
35
|
-
"@babel/polyfill": "^7.
|
|
36
|
-
"@babel/preset-env": "^7.
|
|
37
|
-
"@babel/register": "^7.
|
|
31
|
+
"@babel/cli": "^7.10.5",
|
|
32
|
+
"@babel/core": "^7.11.4",
|
|
33
|
+
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
|
34
|
+
"@babel/plugin-transform-runtime": "^7.11.0",
|
|
35
|
+
"@babel/polyfill": "^7.10.4",
|
|
36
|
+
"@babel/preset-env": "^7.11.0",
|
|
37
|
+
"@babel/register": "^7.10.5",
|
|
38
38
|
"@commitlint/cli": "^8.3.5",
|
|
39
39
|
"@commitlint/config-conventional": "^8.3.4",
|
|
40
|
-
"babel-eslint": "^8.
|
|
40
|
+
"babel-eslint": "^8.2.6",
|
|
41
41
|
"babel-loader": "^8.0.6",
|
|
42
|
-
"babel-minify-webpack-plugin": "^0.2.0",
|
|
43
42
|
"babel-plugin-add-module-exports": "^1.0.2",
|
|
44
43
|
"babel-plugin-date-fns": "^0.1.0",
|
|
45
|
-
"chai": "^4.
|
|
44
|
+
"chai": "^4.2.0",
|
|
46
45
|
"chai-spies": "^1.0.0",
|
|
47
|
-
"eslint": "
|
|
46
|
+
"eslint": "5.0.0",
|
|
48
47
|
"eslint-config-standard": "^12.0.0",
|
|
49
|
-
"eslint-loader": "^
|
|
50
|
-
"eslint-plugin-import": "^2.
|
|
48
|
+
"eslint-loader": "^2.2.1",
|
|
49
|
+
"eslint-plugin-import": "^2.22.0",
|
|
51
50
|
"eslint-plugin-node": "^8.0.1",
|
|
52
51
|
"eslint-plugin-promise": "^4.2.1",
|
|
53
52
|
"eslint-plugin-standard": "^4.0.1",
|
|
@@ -56,11 +55,11 @@
|
|
|
56
55
|
"npm-run-all": "^4.1.5",
|
|
57
56
|
"rimraf": "^2.7.1",
|
|
58
57
|
"serve": "^12.0.0",
|
|
59
|
-
"webpack": "^4.
|
|
60
|
-
"webpack-cli": "^3.3.
|
|
58
|
+
"webpack": "^4.44.1",
|
|
59
|
+
"webpack-cli": "^3.3.12"
|
|
61
60
|
},
|
|
62
61
|
"dependencies": {
|
|
63
|
-
"@babel/runtime": "^7.
|
|
62
|
+
"@babel/runtime": "^7.11.2",
|
|
64
63
|
"date-fns": "^1.30.1",
|
|
65
64
|
"is_js": "^0.9.0",
|
|
66
65
|
"lodash.debounce": "^4.0.8",
|
|
@@ -68,7 +67,7 @@
|
|
|
68
67
|
"mitt": "^1.2.0",
|
|
69
68
|
"mqtt": "^4.2.6",
|
|
70
69
|
"store": "^2.0.12",
|
|
71
|
-
"superagent": "^3.
|
|
70
|
+
"superagent": "^3.8.3"
|
|
72
71
|
},
|
|
73
72
|
"babel": {
|
|
74
73
|
"presets": [
|