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.
@@ -1,226 +1,191 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
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
- function User(HTTPAdapter) {
21
- var _this = this;
22
- (0, _classCallCheck2["default"])(this, User);
23
- (0, _defineProperty2["default"])(this, "updateCommentStatus", (0, _lodash["default"])(function (roomId, lastReadCommentId, lastReceivedCommentId) {
24
- var body = {
25
- room_id: roomId
26
- };
27
- if (lastReadCommentId) body.last_comment_read_id = lastReadCommentId;
28
- if (lastReceivedCommentId) {
29
- body.last_comment_received_id = lastReceivedCommentId;
30
- }
31
- return _this.HTTPAdapter.post('api/v2/sdk/update_comment_status', body);
32
- }, 500));
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
- return (0, _createClass2["default"])(User, [{
37
- key: "postComment",
38
- value: function postComment(topicId, commentMessage, uniqueId, type, payload, extras) {
39
- return this.HTTPAdapter.post_json("api/v2/sdk/post_comment", {
40
- comment: commentMessage,
41
- topic_id: topicId,
42
- unique_temp_id: uniqueId,
43
- type: type,
44
- payload: payload,
45
- extras: extras
46
- }).then(function (res) {
47
- if (res.body.status !== 200) return Promise.reject(res);
48
- return Promise.resolve(res.body.results.comment);
49
- });
50
- }
51
- }, {
52
- key: "loadRoomList",
53
- value: function loadRoomList() {
54
- var _params$room_type;
55
- var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
56
- var url = (0, _urlBuilder["default"])('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', (_params$room_type = params.room_type) !== null && _params$room_type !== void 0 ? _params$room_type : 'default').build();
57
- return this.HTTPAdapter.get(url).then(function (res) {
58
- if (res.body.status !== 200) return Promise.reject(res);
59
- return Promise.resolve(res.body.results.rooms_info);
60
- });
61
- }
62
- }, {
63
- key: "searchMessages",
64
- value: function searchMessages(params) {
65
- var body = {
66
- query: params.query || null,
67
- room_id: params.room_id || null,
68
- last_comment_id: params.last_comment_id || null
69
- };
70
- return this.HTTPAdapter.post('api/v2/sdk/search_messages', body).then(function (res) {
71
- return res.body.results.comments;
72
- });
73
- }
74
- }, {
75
- key: "updateProfile",
76
- value: function updateProfile(params) {
77
- var body = {
78
- name: params.name || null,
79
- avatar_url: params.avatar_url || null,
80
- extras: params.extras ? JSON.stringify(params.extras) : null
81
- };
82
- return this.HTTPAdapter.patch('api/v2/sdk/my_profile', body).then(function (res) {
83
- return res.body.results.user;
84
- });
85
- }
86
- }, {
87
- key: "uploadFile",
88
- value: function uploadFile(file) {
89
- var body = {
90
- file: file
91
- };
92
- return this.HTTPAdapter.post("api/v2/sdk/upload", body).then(function (res) {
93
- return res.body;
94
- });
95
- }
96
- }, {
97
- key: "getRoomsInfo",
98
- value: function getRoomsInfo(opts) {
99
- var body = {
100
- show_participants: true,
101
- show_removed: false
102
- };
103
- if (opts.room_ids) body.room_id = opts.room_ids;
104
- if (opts.room_unique_ids) body.room_unique_id = opts.room_unique_ids;
105
- if (opts.show_participants) body.show_participants = opts.show_participants;
106
- if (opts.show_removed) body.show_removed = opts.show_removed;
107
- return this.HTTPAdapter.post_json("api/v2/sdk/rooms_info", body).then(function (res) {
108
- return res.body;
109
- });
110
- }
111
- }, {
112
- key: "loadComments",
113
- value: function loadComments(topicId, options) {
114
- var url = (0, _urlBuilder["default"])('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();
115
- return this.HTTPAdapter.get(url).then(function (res) {
116
- if (res.status !== 200) return Promise.reject(res);
117
- return Promise.resolve(res.body.results.comments);
118
- });
119
- }
120
- }, {
121
- key: "deleteComment",
122
- value: function deleteComment(roomId, commentUniqueIds) {
123
- var isForEveryone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
124
- var isHard = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
125
- if (isForEveryone === false) {
126
- console.warn('Deprecated: delete comment for me will be removed on next release');
127
- }
128
- if (isHard === false) {
129
- console.warn('Deprecated: soft delete will be removed on next release');
130
- }
131
- var body = {
132
- unique_ids: commentUniqueIds,
133
- is_delete_for_everyone: isForEveryone,
134
- is_hard_delete: isHard
135
- };
136
- return this.HTTPAdapter.del("api/v2/sdk/delete_messages", body).then(function (res) {
137
- return res.body;
138
- });
139
- }
140
- }, {
141
- key: "clearRoomMessages",
142
- value: function clearRoomMessages(roomIds) {
143
- var body = {
144
- room_channel_ids: roomIds
145
- };
146
- return this.HTTPAdapter.del("api/v2/sdk/clear_room_messages", body).then(function (res) {
147
- return res.body;
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
- key: "unblockUser",
182
- value: function unblockUser(email) {
183
- if (!email) throw new Error('email is required');
184
- var params = {
185
- user_email: email
186
- };
187
- return this.HTTPAdapter.post("api/v2/sdk/unblock_user", params).then(function (res) {
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
- key: "getProfile",
194
- value: function getProfile() {
195
- return this.HTTPAdapter.get("api/v2/sdk/my_profile").then(function (res) {
196
- return res.body.results.user;
197
- });
198
- }
199
- }, {
200
- key: "getUserPresences",
201
- value: function getUserPresences(email) {
202
- var params = {
203
- user_ids: email
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
- key: "updateMessage",
212
- value: function updateMessage(message) {
213
- var data = {
214
- token: this.token,
215
- comment: message.message,
216
- unique_id: message.unique_id || message.unique_temp_id
217
- };
218
- if (message.extras != null) data['extras'] = message.extras;
219
- if (message.payload != null) data['payload'] = message.payload;
220
- return this.HTTPAdapter.post_json('api/v2/sdk/update_message', data).then(function (r) {
221
- return r.body.results.comment;
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
- Object.defineProperty(exports, "__esModule", {
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 = function (value) {
19
- return value === undefined;
20
- };
21
- is.string = function (value) {
22
- return toString.call(value) === '[object String]';
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: function array(value) {
35
- return !is.array(value);
36
- },
37
- string: function string(value) {
38
- return !is.string(value);
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
- var _default = exports["default"] = is;
51
- module.exports = exports.default;
17
+ module.exports = is;