qiscus-sdk-core 2.16.0 → 2.16.1
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 +24475 -34766
- package/dist/qiscus-sdk-core.js.map +1 -1
- package/dist/qiscus-sdk-core.min.js +24 -8
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +1847 -2705
- package/lib/lib/Comment.js +89 -142
- package/lib/lib/Room.js +52 -94
- package/lib/lib/adapters/auth.js +42 -69
- package/lib/lib/adapters/custom-event.js +26 -35
- package/lib/lib/adapters/expired-token.js +86 -113
- package/lib/lib/adapters/hook.js +15 -19
- package/lib/lib/adapters/http.js +129 -253
- package/lib/lib/adapters/mqtt.js +422 -648
- package/lib/lib/adapters/room.js +121 -147
- package/lib/lib/adapters/sync.js +233 -421
- package/lib/lib/adapters/user.js +175 -210
- package/lib/lib/is.js +13 -47
- package/lib/lib/match.js +49 -92
- package/lib/lib/url-builder.js +7 -18
- package/lib/lib/util.js +6 -20
- package/lib/lib/utils.js +52 -97
- package/package.json +21 -55
package/lib/lib/adapters/user.js
CHANGED
|
@@ -1,226 +1,191 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
12
|
-
var _urlBuilder = _interopRequireDefault(require("../url-builder"));
|
|
13
|
-
var User = exports["default"] = /*#__PURE__*/function () {
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
const throttle = require("lodash.throttle");
|
|
6
|
+
const urlBuilder = require("../url-builder.js");
|
|
7
|
+
class User {
|
|
14
8
|
/**
|
|
15
9
|
* Params used in this class
|
|
16
10
|
* @method constructor
|
|
17
11
|
* @param {Object} HTTPAdapter [Qiscus HTTP adapter]
|
|
18
12
|
* @return {void} Returns nothing
|
|
19
13
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
constructor(HTTPAdapter) {
|
|
15
|
+
__publicField(this, "updateCommentStatus", throttle(
|
|
16
|
+
(roomId, lastReadCommentId, lastReceivedCommentId) => {
|
|
17
|
+
const body = {
|
|
18
|
+
room_id: roomId
|
|
19
|
+
};
|
|
20
|
+
if (lastReadCommentId) body.last_comment_read_id = lastReadCommentId;
|
|
21
|
+
if (lastReceivedCommentId) {
|
|
22
|
+
body.last_comment_received_id = lastReceivedCommentId;
|
|
23
|
+
}
|
|
24
|
+
return this.HTTPAdapter.post("api/v2/sdk/update_comment_status", body);
|
|
25
|
+
},
|
|
26
|
+
500
|
|
27
|
+
));
|
|
33
28
|
this.HTTPAdapter = HTTPAdapter;
|
|
34
29
|
this.token = HTTPAdapter.token;
|
|
35
30
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}, {
|
|
151
|
-
key: "getCommentReceiptStatus",
|
|
152
|
-
value: function getCommentReceiptStatus(id) {
|
|
153
|
-
return this.HTTPAdapter.get("api/v2/sdk/comment_receipt?comment_id=".concat(id)).then(function (res) {
|
|
154
|
-
return res.body;
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}, {
|
|
158
|
-
key: "getBlockedUser",
|
|
159
|
-
value: function getBlockedUser() {
|
|
160
|
-
var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
161
|
-
var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 20;
|
|
162
|
-
var url = "api/v2/sdk/get_blocked_users?page=".concat(page, "&limit=").concat(limit);
|
|
163
|
-
return this.HTTPAdapter.get(url).then(function (res) {
|
|
164
|
-
if (res.body.status !== 200) return Promise.reject(res);
|
|
165
|
-
return Promise.resolve(res.body.results.blocked_users);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}, {
|
|
169
|
-
key: "blockUser",
|
|
170
|
-
value: function blockUser(email) {
|
|
171
|
-
if (!email) throw new Error('email is required');
|
|
172
|
-
var params = {
|
|
173
|
-
user_email: email
|
|
174
|
-
};
|
|
175
|
-
return this.HTTPAdapter.post("api/v2/sdk/block_user", params).then(function (res) {
|
|
31
|
+
postComment(topicId, commentMessage, uniqueId, type, payload, extras) {
|
|
32
|
+
return this.HTTPAdapter.post_json(`api/v2/sdk/post_comment`, {
|
|
33
|
+
comment: commentMessage,
|
|
34
|
+
topic_id: topicId,
|
|
35
|
+
unique_temp_id: uniqueId,
|
|
36
|
+
type,
|
|
37
|
+
payload,
|
|
38
|
+
extras
|
|
39
|
+
}).then((res) => {
|
|
40
|
+
if (res.body.status !== 200) return Promise.reject(res);
|
|
41
|
+
return Promise.resolve(res.body.results.comment);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
loadRoomList(params = {}) {
|
|
45
|
+
var _a;
|
|
46
|
+
const url = urlBuilder("api/v2/sdk/user_rooms").param("page", params.page).param("show_participants", params.show_participants || true).param("limit", params.limit).param("show_empty", params.show_empty).param("room_type", (_a = params.room_type) != null ? _a : "default").build();
|
|
47
|
+
return this.HTTPAdapter.get(url).then((res) => {
|
|
48
|
+
if (res.body.status !== 200) return Promise.reject(res);
|
|
49
|
+
return Promise.resolve(res.body.results.rooms_info);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
searchMessages(params) {
|
|
53
|
+
const body = {
|
|
54
|
+
query: params.query || null,
|
|
55
|
+
room_id: params.room_id || null,
|
|
56
|
+
last_comment_id: params.last_comment_id || null
|
|
57
|
+
};
|
|
58
|
+
return this.HTTPAdapter.post("api/v2/sdk/search_messages", body).then(
|
|
59
|
+
(res) => res.body.results.comments
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
updateProfile(params) {
|
|
63
|
+
const body = {
|
|
64
|
+
name: params.name || null,
|
|
65
|
+
avatar_url: params.avatar_url || null,
|
|
66
|
+
extras: params.extras ? JSON.stringify(params.extras) : null
|
|
67
|
+
};
|
|
68
|
+
return this.HTTPAdapter.patch("api/v2/sdk/my_profile", body).then(
|
|
69
|
+
(res) => res.body.results.user
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
uploadFile(file) {
|
|
73
|
+
const body = {
|
|
74
|
+
file
|
|
75
|
+
};
|
|
76
|
+
return this.HTTPAdapter.post(`api/v2/sdk/upload`, body).then(
|
|
77
|
+
(res) => res.body
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
getRoomsInfo(opts) {
|
|
81
|
+
const body = {
|
|
82
|
+
show_participants: true,
|
|
83
|
+
show_removed: false
|
|
84
|
+
};
|
|
85
|
+
if (opts.room_ids) body.room_id = opts.room_ids;
|
|
86
|
+
if (opts.room_unique_ids) body.room_unique_id = opts.room_unique_ids;
|
|
87
|
+
if (opts.show_participants) body.show_participants = opts.show_participants;
|
|
88
|
+
if (opts.show_removed) body.show_removed = opts.show_removed;
|
|
89
|
+
return this.HTTPAdapter.post_json(`api/v2/sdk/rooms_info`, body).then(
|
|
90
|
+
(res) => res.body
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
loadComments(topicId, options) {
|
|
94
|
+
const url = urlBuilder("api/v2/sdk/load_comments").param("topic_id", topicId).param("last_comment_id", options.last_comment_id).param("timestamp", options.timestamp).param("after", options.after).param("limit", options.limit).build();
|
|
95
|
+
return this.HTTPAdapter.get(url).then((res) => {
|
|
96
|
+
if (res.status !== 200) return Promise.reject(res);
|
|
97
|
+
return Promise.resolve(res.body.results.comments);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
deleteComment(roomId, commentUniqueIds, isForEveryone = true, isHard = true) {
|
|
101
|
+
if (isForEveryone === false) {
|
|
102
|
+
console.warn(
|
|
103
|
+
"Deprecated: delete comment for me will be removed on next release"
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (isHard === false) {
|
|
107
|
+
console.warn("Deprecated: soft delete will be removed on next release");
|
|
108
|
+
}
|
|
109
|
+
const body = {
|
|
110
|
+
unique_ids: commentUniqueIds,
|
|
111
|
+
is_delete_for_everyone: isForEveryone,
|
|
112
|
+
is_hard_delete: isHard
|
|
113
|
+
};
|
|
114
|
+
return this.HTTPAdapter.del(`api/v2/sdk/delete_messages`, body).then(
|
|
115
|
+
(res) => res.body
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
clearRoomMessages(roomIds) {
|
|
119
|
+
const body = {
|
|
120
|
+
room_channel_ids: roomIds
|
|
121
|
+
};
|
|
122
|
+
return this.HTTPAdapter.del(`api/v2/sdk/clear_room_messages`, body).then(
|
|
123
|
+
(res) => res.body
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
getCommentReceiptStatus(id) {
|
|
127
|
+
return this.HTTPAdapter.get(
|
|
128
|
+
`api/v2/sdk/comment_receipt?comment_id=${id}`
|
|
129
|
+
).then((res) => res.body);
|
|
130
|
+
}
|
|
131
|
+
getBlockedUser(page = 1, limit = 20) {
|
|
132
|
+
const url = `api/v2/sdk/get_blocked_users?page=${page}&limit=${limit}`;
|
|
133
|
+
return this.HTTPAdapter.get(url).then((res) => {
|
|
134
|
+
if (res.body.status !== 200) return Promise.reject(res);
|
|
135
|
+
return Promise.resolve(res.body.results.blocked_users);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
blockUser(email) {
|
|
139
|
+
if (!email) throw new Error("email is required");
|
|
140
|
+
let params = {
|
|
141
|
+
user_email: email
|
|
142
|
+
};
|
|
143
|
+
return this.HTTPAdapter.post(`api/v2/sdk/block_user`, params).then(
|
|
144
|
+
(res) => {
|
|
176
145
|
if (res.body.status !== 200) return Promise.reject(res);
|
|
177
146
|
return Promise.resolve(res.body.results.user);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
unblockUser(email) {
|
|
151
|
+
if (!email) throw new Error("email is required");
|
|
152
|
+
const params = {
|
|
153
|
+
user_email: email
|
|
154
|
+
};
|
|
155
|
+
return this.HTTPAdapter.post(`api/v2/sdk/unblock_user`, params).then(
|
|
156
|
+
(res) => {
|
|
188
157
|
if (res.body.status !== 200) return Promise.reject(res);
|
|
189
158
|
return Promise.resolve(res.body.results.user);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
};
|
|
205
|
-
return this.HTTPAdapter.post_json("api/v2/sdk/users/status", params).then(function (res) {
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
getProfile() {
|
|
163
|
+
return this.HTTPAdapter.get(`api/v2/sdk/my_profile`).then(
|
|
164
|
+
(res) => res.body.results.user
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
getUserPresences(email) {
|
|
168
|
+
let params = {
|
|
169
|
+
user_ids: email
|
|
170
|
+
};
|
|
171
|
+
return this.HTTPAdapter.post_json(`api/v2/sdk/users/status`, params).then(
|
|
172
|
+
(res) => {
|
|
206
173
|
if (res.body.status !== 200) return Promise.reject(res);
|
|
207
174
|
return Promise.resolve(res.body.results.user_status);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}();
|
|
226
|
-
module.exports = exports.default;
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
updateMessage(message) {
|
|
179
|
+
const data = {
|
|
180
|
+
token: this.token,
|
|
181
|
+
comment: message.message,
|
|
182
|
+
unique_id: message.unique_id || message.unique_temp_id
|
|
183
|
+
};
|
|
184
|
+
if (message.extras != null) data["extras"] = message.extras;
|
|
185
|
+
if (message.payload != null) data["payload"] = message.payload;
|
|
186
|
+
return this.HTTPAdapter.post_json("api/v2/sdk/update_message", data).then(
|
|
187
|
+
(r) => r.body.results.comment
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
module.exports = User;
|
package/lib/lib/is.js
CHANGED
|
@@ -1,51 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
// Minimal internal replacement for the `is_js` package.
|
|
8
|
-
//
|
|
9
|
-
// We only port the handful of type predicates the SDK actually uses, with the
|
|
10
|
-
// exact same semantics as `is_js@0.9.0`. The prototype-pollution surface of
|
|
11
|
-
// is_js (CVE-2020-26302) lives in unused helpers (`propertyDefined`,
|
|
12
|
-
// `propertyCount`, the regex-namespace plumbing), which are intentionally not
|
|
13
|
-
// reimplemented here.
|
|
14
|
-
|
|
15
|
-
var toString = Object.prototype.toString;
|
|
16
|
-
var is = {};
|
|
2
|
+
const toString = Object.prototype.toString;
|
|
3
|
+
const is = {};
|
|
17
4
|
is.array = Array.isArray;
|
|
18
|
-
is.undefined =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
is
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
is.object = function (value) {
|
|
25
|
-
return Object(value) === value;
|
|
26
|
-
};
|
|
27
|
-
is['function'] = function (value) {
|
|
28
|
-
return toString.call(value) === '[object Function]' || typeof value === 'function';
|
|
29
|
-
};
|
|
30
|
-
is.json = function (value) {
|
|
31
|
-
return toString.call(value) === '[object Object]';
|
|
32
|
-
};
|
|
5
|
+
is.undefined = (value) => value === void 0;
|
|
6
|
+
is.string = (value) => toString.call(value) === "[object String]";
|
|
7
|
+
is.object = (value) => Object(value) === value;
|
|
8
|
+
is["function"] = (value) => toString.call(value) === "[object Function]" || typeof value === "function";
|
|
9
|
+
is.json = (value) => toString.call(value) === "[object Object]";
|
|
33
10
|
is.not = {
|
|
34
|
-
array:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
object: function object(value) {
|
|
41
|
-
return !is.object(value);
|
|
42
|
-
},
|
|
43
|
-
"function": function _function(value) {
|
|
44
|
-
return !is['function'](value);
|
|
45
|
-
},
|
|
46
|
-
json: function json(value) {
|
|
47
|
-
return !is.json(value);
|
|
48
|
-
}
|
|
11
|
+
array: (value) => !is.array(value),
|
|
12
|
+
string: (value) => !is.string(value),
|
|
13
|
+
object: (value) => !is.object(value),
|
|
14
|
+
function: (value) => !is["function"](value),
|
|
15
|
+
json: (value) => !is.json(value)
|
|
49
16
|
};
|
|
50
|
-
|
|
51
|
-
module.exports = exports.default;
|
|
17
|
+
module.exports = is;
|