ncloudchat 1.0.23 → 1.0.33

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.
Files changed (138) hide show
  1. package/LICENSE.md +1 -1
  2. package/deploy.sh +1 -1
  3. package/esm/CloudChat.d.ts +436 -11
  4. package/esm/CloudChat.js +978 -304
  5. package/esm/CloudChat.js.map +1 -1
  6. package/esm/CoreManager.d.ts +6 -0
  7. package/esm/CoreManager.js +13 -4
  8. package/esm/CoreManager.js.map +1 -1
  9. package/esm/Dispatcher.d.ts +16 -0
  10. package/esm/Dispatcher.js +19 -4
  11. package/esm/Dispatcher.js.map +1 -1
  12. package/esm/Network.d.ts +7 -0
  13. package/esm/Network.js +96 -0
  14. package/esm/Network.js.map +1 -0
  15. package/esm/Type.d.ts +43 -0
  16. package/esm/Type.js +16 -0
  17. package/esm/Type.js.map +1 -1
  18. package/esm/Util.d.ts +13 -0
  19. package/esm/Util.js +13 -0
  20. package/esm/Util.js.map +1 -1
  21. package/esm/graphql/channel.d.ts +13 -0
  22. package/esm/graphql/channel.js +16 -0
  23. package/esm/graphql/channel.js.map +1 -0
  24. package/esm/graphql/friend.d.ts +11 -0
  25. package/esm/graphql/friend.js +13 -0
  26. package/esm/graphql/friend.js.map +1 -0
  27. package/esm/graphql/invite.d.ts +7 -0
  28. package/esm/graphql/invite.js +8 -0
  29. package/esm/graphql/invite.js.map +1 -0
  30. package/esm/graphql/member.d.ts +11 -0
  31. package/esm/graphql/member.js +13 -0
  32. package/esm/graphql/member.js.map +1 -0
  33. package/esm/graphql/message.d.ts +11 -0
  34. package/esm/graphql/message.js +13 -0
  35. package/esm/graphql/message.js.map +1 -0
  36. package/esm/graphql/pin.d.ts +10 -0
  37. package/esm/graphql/pin.js +12 -0
  38. package/esm/graphql/pin.js.map +1 -0
  39. package/esm/graphql/project.d.ts +6 -0
  40. package/esm/graphql/project.js +8 -0
  41. package/esm/graphql/project.js.map +1 -0
  42. package/esm/graphql/subscription.d.ts +11 -0
  43. package/esm/graphql/subscription.js +13 -0
  44. package/esm/graphql/subscription.js.map +1 -0
  45. package/esm/index.d.ts +6 -0
  46. package/esm/index.js +6 -0
  47. package/esm/index.js.map +1 -1
  48. package/esm/logger.d.ts +9 -3
  49. package/esm/logger.js +6 -0
  50. package/esm/logger.js.map +1 -1
  51. package/esm/mutations/channel.d.ts +50 -0
  52. package/esm/mutations/channel.js +97 -187
  53. package/esm/mutations/channel.js.map +1 -1
  54. package/esm/mutations/friend.d.ts +38 -0
  55. package/esm/mutations/friend.js +57 -119
  56. package/esm/mutations/friend.js.map +1 -1
  57. package/esm/mutations/index.d.ts +5 -3
  58. package/esm/mutations/index.js +5 -3
  59. package/esm/mutations/index.js.map +1 -1
  60. package/esm/mutations/invite.d.ts +15 -0
  61. package/esm/mutations/invite.js +23 -32
  62. package/esm/mutations/invite.js.map +1 -1
  63. package/esm/mutations/member.d.ts +39 -2
  64. package/esm/mutations/member.js +64 -111
  65. package/esm/mutations/member.js.map +1 -1
  66. package/esm/mutations/message.d.ts +35 -0
  67. package/esm/mutations/message.js +68 -45
  68. package/esm/mutations/message.js.map +1 -1
  69. package/esm/mutations/pin.d.ts +28 -0
  70. package/esm/mutations/pin.js +88 -0
  71. package/esm/mutations/pin.js.map +1 -0
  72. package/esm/mutations/subscription.d.ts +33 -1
  73. package/esm/mutations/subscription.js +51 -93
  74. package/esm/mutations/subscription.js.map +1 -1
  75. package/esm/queries/channel.d.ts +24 -0
  76. package/esm/queries/channel.js +37 -79
  77. package/esm/queries/channel.js.map +1 -1
  78. package/esm/queries/friend.d.ts +16 -0
  79. package/esm/queries/friend.js +25 -40
  80. package/esm/queries/friend.js.map +1 -1
  81. package/esm/queries/index.d.ts +7 -0
  82. package/esm/queries/index.js +7 -0
  83. package/esm/queries/index.js.map +1 -1
  84. package/esm/queries/member.d.ts +16 -0
  85. package/esm/queries/member.js +25 -40
  86. package/esm/queries/member.js.map +1 -1
  87. package/esm/queries/memberblocks.d.ts +16 -0
  88. package/esm/queries/memberblocks.js +25 -40
  89. package/esm/queries/memberblocks.js.map +1 -1
  90. package/esm/queries/message.d.ts +33 -0
  91. package/esm/queries/message.js +50 -111
  92. package/esm/queries/message.js.map +1 -1
  93. package/esm/queries/pin.d.ts +28 -0
  94. package/esm/queries/pin.js +92 -0
  95. package/esm/queries/pin.js.map +1 -0
  96. package/esm/queries/project.d.ts +14 -1
  97. package/esm/queries/project.js +21 -74
  98. package/esm/queries/project.js.map +1 -1
  99. package/esm/queries/subscription.d.ts +25 -0
  100. package/esm/queries/subscription.js +39 -76
  101. package/esm/queries/subscription.js.map +1 -1
  102. package/lib/CloudChat.js +1215 -364
  103. package/lib/CoreManager.js +13 -3
  104. package/lib/Dispatcher.js +25 -9
  105. package/lib/Network.js +229 -0
  106. package/lib/Type.js +19 -0
  107. package/lib/Util.js +15 -1
  108. package/lib/graphql/channel.js +32 -0
  109. package/lib/graphql/friend.js +27 -0
  110. package/lib/graphql/invite.js +18 -0
  111. package/lib/graphql/member.js +27 -0
  112. package/lib/graphql/message.js +27 -0
  113. package/lib/graphql/pin.js +25 -0
  114. package/lib/graphql/project.js +7 -0
  115. package/lib/graphql/subscription.js +27 -0
  116. package/lib/index.js +2 -2
  117. package/lib/logger.js +6 -0
  118. package/lib/mutations/channel.js +105 -178
  119. package/lib/mutations/friend.js +62 -115
  120. package/lib/mutations/index.js +23 -3
  121. package/lib/mutations/invite.js +27 -33
  122. package/lib/mutations/member.js +73 -100
  123. package/lib/mutations/message.js +88 -48
  124. package/lib/mutations/pin.js +229 -0
  125. package/lib/mutations/subscription.js +56 -95
  126. package/lib/queries/channel.js +40 -84
  127. package/lib/queries/friend.js +29 -45
  128. package/lib/queries/index.js +24 -3
  129. package/lib/queries/member.js +29 -45
  130. package/lib/queries/memberblocks.js +28 -44
  131. package/lib/queries/message.js +56 -109
  132. package/lib/queries/pin.js +243 -0
  133. package/lib/queries/project.js +1 -212
  134. package/lib/queries/subscription.js +42 -78
  135. package/package.json +20 -45
  136. package/tsconfig.json +1 -0
  137. package//353/260/260/355/217/254/354/210/234/354/204/234.md +8 -0
  138. package/package copy.json +0 -74
package/esm/CloudChat.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Copyright (c) NBASE CORP. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
1
7
  var __assign = (this && this.__assign) || function () {
2
8
  __assign = Object.assign || function(t) {
3
9
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -45,40 +51,88 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
51
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
52
  }
47
53
  };
54
+ var __values = (this && this.__values) || function(o) {
55
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
56
+ if (m) return m.call(o);
57
+ if (o && typeof o.length === "number") return {
58
+ next: function () {
59
+ if (o && i >= o.length) o = void 0;
60
+ return { value: o && o[i++], done: !o };
61
+ }
62
+ };
63
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
64
+ };
65
+ var __read = (this && this.__read) || function (o, n) {
66
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
67
+ if (!m) return o;
68
+ var i = m.call(o), r, ar = [], e;
69
+ try {
70
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
71
+ }
72
+ catch (error) { e = { error: error }; }
73
+ finally {
74
+ try {
75
+ if (r && !r.done && (m = i["return"])) m.call(i);
76
+ }
77
+ finally { if (e) throw e.error; }
78
+ }
79
+ return ar;
80
+ };
48
81
  import { io } from "socket.io-client";
49
82
  import CoreManager from "./CoreManager";
50
83
  import Dispatcher from "./Dispatcher";
51
84
  import { info } from "./logger";
52
- import { getChannel, getChannels, getMessage, getMessages, getSubscription, getSubscriptions, getMembers, getMemberBlocks, getFriendships, unreadCount, } from "./queries";
53
- import { login, createChannel, updateChannel, deleteChannel, translate, upload, createSubscription, deleteSubscription, updateSubscription, addChannelMembers, removeChannelMembers, requestFriend, acceptFriend, rejectFriend, removeFriend, createMemberBlock, deleteMemberBlock, } from "./mutations";
85
+ import { getChannel, getChannels, getMessage, getMessages, getSubscription, getSubscriptions, getMembers, getMemberBlocks, getFriendships, unreadCount, getPin, getPins } from "./queries";
86
+ import { login, createChannel, updateChannel, deleteChannel, translate, message, upload, createSubscription, deleteSubscription, updateSubscription, addChannelMembers, removeChannelMembers, requestFriend, acceptFriend, rejectFriend, removeFriend, createMemberBlock, deleteMemberBlock, createPin, updatePin } from "./mutations";
87
+ /**
88
+ * Class NCloudChat holds all the NCloudChat functionalities.
89
+ *
90
+ * @class
91
+ */
54
92
  var NCloudChat = /** @class */ (function () {
55
- function NCloudChat() {
93
+ /**
94
+ * Create a `NCloudChat` instance and a Dispatcher.
95
+ *
96
+ * @constructs
97
+ */
98
+ function NCloudChat(debug) {
99
+ if (debug === void 0) { debug = false; }
56
100
  this.socket = null;
57
101
  this.connected = false;
58
102
  this.connectedCount = 0;
59
103
  this.dp = new Dispatcher();
104
+ if (!debug)
105
+ console.log = function () { };
60
106
  }
61
107
  NCloudChat.prototype.clear = function () { };
108
+ /**
109
+ * Initialize a new `NCloudChat` instance of project and user.
110
+ *
111
+ * @function initialize
112
+ * @param {string} projectId - The id of a project.
113
+ */
62
114
  NCloudChat.prototype.initialize = function (projectId) {
63
- CoreManager.set("PROJECT_ID", projectId);
64
- CoreManager.set("USER", {
65
- id: "",
66
- name: "",
67
- image: ""
68
- });
115
+ this.setProjectId(projectId);
116
+ this.setLang(navigator.language);
69
117
  };
70
118
  NCloudChat.prototype.getLang = function () {
71
- return navigator.language;
119
+ return CoreManager.get("LANGUAGE");
120
+ };
121
+ NCloudChat.prototype.setLang = function (lang) {
122
+ return CoreManager.set("LANGUAGE", lang);
72
123
  };
73
124
  NCloudChat.prototype.getUser = function () {
74
125
  return CoreManager.get("USER");
75
126
  };
127
+ NCloudChat.prototype.getProjectId = function () {
128
+ return CoreManager.get("PROJECT_ID");
129
+ };
76
130
  NCloudChat.prototype.setServerUrl = function (url) {
77
131
  if (!/^[hHtTpP]{4}(s)?(:\/\/)[a-zA-Z0-9\.\/-:]+/.test(url)) {
78
132
  throw Error("invalied url : (ex)http://domain.com, https://domain.com");
79
133
  return;
80
134
  }
81
- if (url.length > 1 && url.substring(url.length - 1) === '/') {
135
+ if (url.length > 1 && url.substring(url.length - 1) === "/") {
82
136
  url = url.substring(0, url.length - 1);
83
137
  }
84
138
  return CoreManager.set("SERVER_URL", url);
@@ -95,10 +149,39 @@ var NCloudChat = /** @class */ (function () {
95
149
  NCloudChat.prototype.setUser = function (user) {
96
150
  CoreManager.set("USER", user);
97
151
  };
152
+ NCloudChat.prototype.inputValidation = function (inputs) {
153
+ var e_1, _a;
154
+ try {
155
+ // if (!this.isConnected()) throw Error(`You are not connected.`);
156
+ for (var _b = __values(Object.entries(inputs)), _c = _b.next(); !_c.done; _c = _b.next()) {
157
+ var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
158
+ if (!value) {
159
+ var result = key.replace(/([A-Z])/g, " $1");
160
+ var word = result.charAt(0).toUpperCase() + result.slice(1);
161
+ throw Error("You need a(n) ".concat(word, "."));
162
+ }
163
+ }
164
+ }
165
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
166
+ finally {
167
+ try {
168
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
169
+ }
170
+ finally { if (e_1) throw e_1.error; }
171
+ }
172
+ };
173
+ /**
174
+ * Create a connection between a socket and a client.
175
+ *
176
+ * @async connect
177
+ * @param {any} user
178
+ * @param {string} userToken
179
+ * @returns
180
+ */
98
181
  NCloudChat.prototype.connect = function (user, userToken) {
99
182
  if (userToken === void 0) { userToken = ""; }
100
183
  return __awaiter(this, void 0, void 0, function () {
101
- var url, project_id, image, name, lang, e_1, options;
184
+ var url, image, name, lang, customField, response, e_2, options;
102
185
  var _this = this;
103
186
  return __generator(this, function (_a) {
104
187
  switch (_a.label) {
@@ -109,33 +192,31 @@ var NCloudChat = /** @class */ (function () {
109
192
  _a.sent();
110
193
  _a.label = 2;
111
194
  case 2:
112
- url = CoreManager.get("SOCKET_URL") + '/cloudchat';
113
- project_id = CoreManager.get("PROJECT_ID");
114
- if (!project_id) {
115
- throw Error("Project ID not found");
116
- }
117
- // const user = CoreManager.get("USER");
118
- // if (!user.id && user.id) user_id = user.id;
119
- if (!user.id) {
195
+ url = CoreManager.get("SOCKET_URL") + "/cloudchat";
196
+ if (!user.id)
120
197
  throw Error("UserID not found");
121
- }
122
198
  image = user.profile;
123
199
  name = user.name;
124
200
  lang = this.getLang();
201
+ customField = user.customField;
125
202
  _a.label = 3;
126
203
  case 3:
127
204
  _a.trys.push([3, 5, , 6]);
128
- return [4 /*yield*/, login(user.id, name, image, userToken)];
205
+ return [4 /*yield*/, login(user.id, name, image, userToken, customField)];
129
206
  case 4:
130
- userToken = _a.sent();
207
+ response = _a.sent();
208
+ this.setUser({
209
+ id: user.id,
210
+ name: name,
211
+ image: image,
212
+ customField: customField
213
+ });
214
+ userToken = response["token"]; // parse token object
131
215
  return [3 /*break*/, 6];
132
216
  case 5:
133
- e_1 = _a.sent();
134
- throw e_1;
217
+ e_2 = _a.sent();
218
+ throw e_2;
135
219
  case 6:
136
- if (!userToken) {
137
- throw Error("Token is not found");
138
- }
139
220
  CoreManager.set("TOKEN", userToken);
140
221
  options = {
141
222
  transports: ["websocket"],
@@ -145,11 +226,12 @@ var NCloudChat = /** @class */ (function () {
145
226
  reconnectionDelayMax: 2000 * 100,
146
227
  randomizationFactor: 0.5,
147
228
  query: {
148
- project_id: project_id,
229
+ project_id: this.getProjectId(),
149
230
  user_id: user.id,
150
231
  lang: lang,
151
232
  image: image,
152
233
  name: name,
234
+ customField: customField,
153
235
  token: userToken
154
236
  }
155
237
  };
@@ -157,13 +239,13 @@ var NCloudChat = /** @class */ (function () {
157
239
  this.socket.on("connect", function (data) {
158
240
  _this.connectedCount++;
159
241
  _this.connected = true;
160
- info("Connected to " + url + " with id: " + _this.socket.id);
242
+ info("Connected to ".concat(url, " with id: ").concat(_this.socket.id));
161
243
  _this.dp.dispatch("onConnected", data);
162
244
  });
163
245
  this.socket.on("unauthorized", function (data) { });
164
246
  this.socket.on("disconnect", function (reason) {
165
247
  _this.connected = false;
166
- info("Disconnected to " + url + " with id: " + _this.socket.id);
248
+ info("Disconnected to ".concat(url, " with id: ").concat(_this.socket.id));
167
249
  _this.dp.dispatch("onDisconnected", reason);
168
250
  });
169
251
  this.socket.on("message", function (payload) {
@@ -182,13 +264,13 @@ var NCloudChat = /** @class */ (function () {
182
264
  var data = JSON.parse(payload);
183
265
  _this.dp.dispatch("onStopTyping", data);
184
266
  });
185
- this.socket.on("member added", function (payload) {
267
+ this.socket.on("member joined", function (payload) {
186
268
  var data = JSON.parse(payload);
187
- _this.dp.dispatch("onMemberAdded", data);
269
+ _this.dp.dispatch("onMemberJoined", data);
188
270
  });
189
- this.socket.on("member removed", function (payload) {
271
+ this.socket.on("member leaved", function (payload) {
190
272
  var data = JSON.parse(payload);
191
- _this.dp.dispatch("onMemberRemoved", data);
273
+ _this.dp.dispatch("onMemberLeaved", data);
192
274
  });
193
275
  this.socket.on("member updated", function (payload) {
194
276
  var data = JSON.parse(payload);
@@ -227,173 +309,259 @@ var NCloudChat = /** @class */ (function () {
227
309
  });
228
310
  });
229
311
  };
312
+ /**
313
+ * Mute channel notifications.
314
+ *
315
+ * @async
316
+ * @function mute
317
+ * @param {string} channel
318
+ * @returns {Promise<any>}
319
+ */
230
320
  NCloudChat.prototype.mute = function (channel) {
231
321
  return __awaiter(this, void 0, void 0, function () {
232
- var subscription, e_2;
322
+ var subscription, e_3;
233
323
  return __generator(this, function (_a) {
234
324
  switch (_a.label) {
235
325
  case 0:
236
- if (!this.isConnected()) {
237
- throw Error("You are not connected.");
238
- }
326
+ this.inputValidation({ channelId: channel });
239
327
  _a.label = 1;
240
328
  case 1:
241
329
  _a.trys.push([1, 3, , 4]);
242
330
  return [4 /*yield*/, updateSubscription(channel, null, JSON.stringify({ mute: true }))];
243
331
  case 2:
244
332
  subscription = _a.sent();
245
- if (subscription)
246
- subscription.id = this.ObjectId(subscription.id);
247
- return [2 /*return*/, subscription];
333
+ if (subscription["subscription"])
334
+ subscription["subscription"]["id"] = this.ObjectId(subscription["subscription"]["id"]);
335
+ return [2 /*return*/, subscription["subscription"]];
248
336
  case 3:
249
- e_2 = _a.sent();
250
- throw e_2;
251
- case 4: return [2 /*return*/, null];
337
+ e_3 = _a.sent();
338
+ throw e_3;
339
+ case 4: return [2 /*return*/];
252
340
  }
253
341
  });
254
342
  });
255
343
  };
344
+ /**
345
+ * Unmute channel notifications.
346
+ *
347
+ * @async
348
+ * @function unmute
349
+ * @param {string} channel
350
+ * @returns {Promise<any>}
351
+ */
256
352
  NCloudChat.prototype.unmute = function (channel) {
257
353
  return __awaiter(this, void 0, void 0, function () {
258
- var subscription, e_3;
354
+ var subscription, e_4;
259
355
  return __generator(this, function (_a) {
260
356
  switch (_a.label) {
261
357
  case 0:
262
- if (!this.isConnected()) {
263
- throw Error("You are not connected.");
264
- }
358
+ this.inputValidation({ channelId: channel });
265
359
  _a.label = 1;
266
360
  case 1:
267
361
  _a.trys.push([1, 3, , 4]);
268
362
  return [4 /*yield*/, updateSubscription(channel, null, JSON.stringify({ mute: false }))];
269
363
  case 2:
270
364
  subscription = _a.sent();
271
- if (subscription)
272
- subscription.id = this.ObjectId(subscription.id);
273
- return [2 /*return*/, subscription];
365
+ if (subscription["subscription"])
366
+ subscription["subscription"]["id"] = this.ObjectId(subscription["subscription"]["id"]);
367
+ return [2 /*return*/, subscription["subscription"]];
274
368
  case 3:
275
- e_3 = _a.sent();
276
- throw e_3;
277
- case 4: return [2 /*return*/, null];
369
+ e_4 = _a.sent();
370
+ throw e_4;
371
+ case 4: return [2 /*return*/];
278
372
  }
279
373
  });
280
374
  });
281
375
  };
376
+ /**
377
+ * Subscribe a channel.
378
+ *
379
+ * @async
380
+ * @function subscibe
381
+ * @param {string} channel - The id of a channel.
382
+ * @param {any} option
383
+ * @returns
384
+ */
282
385
  NCloudChat.prototype.subscribe = function (channel, option) {
283
386
  if (option === void 0) { option = null; }
284
387
  return __awaiter(this, void 0, void 0, function () {
285
- var subscription, e_4;
388
+ var subscription, e_5;
286
389
  return __generator(this, function (_a) {
287
390
  switch (_a.label) {
288
391
  case 0:
289
- if (!this.isConnected()) {
290
- throw Error("You are not connected.");
291
- }
392
+ this.inputValidation({ channelId: channel });
292
393
  _a.label = 1;
293
394
  case 1:
294
395
  _a.trys.push([1, 3, , 4]);
295
396
  return [4 /*yield*/, createSubscription(channel, JSON.stringify(option))];
296
397
  case 2:
297
398
  subscription = _a.sent();
298
- if (subscription)
299
- subscription.id = this.ObjectId(subscription.id);
300
- return [2 /*return*/, subscription];
399
+ if (subscription["subscription"])
400
+ subscription["subscription"]["id"] = this.ObjectId(subscription["subscription"]["id"]);
401
+ return [2 /*return*/, subscription["subscription"]];
301
402
  case 3:
302
- e_4 = _a.sent();
303
- throw e_4;
304
- case 4: return [2 /*return*/, null];
403
+ e_5 = _a.sent();
404
+ throw e_5;
405
+ case 4: return [2 /*return*/];
305
406
  }
306
407
  });
307
408
  });
308
409
  };
410
+ /**
411
+ * Unsubscribe from a channel.
412
+ *
413
+ * @async
414
+ * @function unsubscribe
415
+ * @param {string} channel - The id of a chennel
416
+ * @returns {Promise<any>}
417
+ */
309
418
  NCloudChat.prototype.unsubscribe = function (channel) {
310
419
  return __awaiter(this, void 0, void 0, function () {
311
- var subscription, e_5;
420
+ var subscription, e_6;
312
421
  return __generator(this, function (_a) {
313
422
  switch (_a.label) {
314
423
  case 0:
315
- if (!this.isConnected()) {
316
- throw Error("You are not connected.");
317
- }
424
+ this.inputValidation({ channelId: channel });
318
425
  _a.label = 1;
319
426
  case 1:
320
427
  _a.trys.push([1, 3, , 4]);
321
428
  return [4 /*yield*/, deleteSubscription(channel)];
322
429
  case 2:
323
430
  subscription = _a.sent();
324
- return [2 /*return*/, subscription];
431
+ if (subscription["subscription"])
432
+ subscription["subscription"]["id"] = this.ObjectId(subscription["subscription"]["id"]);
433
+ return [2 /*return*/, subscription["subscription"]];
325
434
  case 3:
326
- e_5 = _a.sent();
327
- throw e_5;
328
- case 4: return [2 /*return*/, null];
435
+ e_6 = _a.sent();
436
+ throw e_6;
437
+ case 4: return [2 /*return*/];
329
438
  }
330
439
  });
331
440
  });
332
441
  };
442
+ /**
443
+ * Translate a message from a souce language to a target language.
444
+ *
445
+ * @async
446
+ * @function translateMessage
447
+ * @param {string} channelId - The id of a channel.
448
+ * @param {string} source - A source language.
449
+ * @param {string} target - A target language.
450
+ * @param {string} message - An message to be translated.
451
+ * @returns {Promise<any>}
452
+ */
333
453
  NCloudChat.prototype.translateMessage = function (channelId, source, target, message) {
334
454
  return __awaiter(this, void 0, void 0, function () {
335
- var user, result, e_6;
455
+ var result, e_7;
336
456
  return __generator(this, function (_a) {
337
457
  switch (_a.label) {
338
458
  case 0:
339
- if (!this.isConnected()) {
340
- throw Error("You are not connected.");
341
- }
459
+ this.inputValidation({
460
+ channelId: channelId,
461
+ sourceLanguage: source,
462
+ targetLanguage: target
463
+ });
342
464
  _a.label = 1;
343
465
  case 1:
344
466
  _a.trys.push([1, 3, , 4]);
345
- user = CoreManager.get("USER");
346
467
  return [4 /*yield*/, translate(channelId, source, target, message)];
347
468
  case 2:
348
469
  result = _a.sent();
349
- return [2 /*return*/, result];
470
+ return [2 /*return*/, result["translation"]];
350
471
  case 3:
351
- e_6 = _a.sent();
352
- throw Error(e_6.message);
353
- case 4: return [2 /*return*/, null];
472
+ e_7 = _a.sent();
473
+ if (e_7 instanceof Error) {
474
+ throw Error(e_7.message);
475
+ }
476
+ return [3 /*break*/, 4];
477
+ case 4: return [2 /*return*/];
354
478
  }
355
479
  });
356
480
  });
357
481
  };
482
+ /**
483
+ * Send a message to a channel.
484
+ *
485
+ * @async
486
+ * @function sendMessage
487
+ * @param {string} channel - The id of a channel.
488
+ * @param {any} opt
489
+ * @returns {Promise<any>}
490
+ */
358
491
  NCloudChat.prototype.sendMessage = function (channel, opt) {
492
+ return __awaiter(this, void 0, void 0, function () {
493
+ var data, result, e_8;
494
+ return __generator(this, function (_a) {
495
+ switch (_a.label) {
496
+ case 0:
497
+ this.inputValidation({ channelId: channel, message: opt.message });
498
+ if (!opt.type)
499
+ opt.type = "text";
500
+ _a.label = 1;
501
+ case 1:
502
+ _a.trys.push([1, 3, , 4]);
503
+ data = __assign({ channelId: channel }, opt);
504
+ return [4 /*yield*/, message(data)];
505
+ case 2:
506
+ result = _a.sent();
507
+ return [2 /*return*/, result["message"]];
508
+ case 3:
509
+ e_8 = _a.sent();
510
+ throw e_8;
511
+ case 4: return [2 /*return*/];
512
+ }
513
+ });
514
+ });
515
+ };
516
+ /**
517
+ * Send an express message to a channel.
518
+ *
519
+ * @async
520
+ * @function sendExpressMessage
521
+ * @param {string} channel - The id of a channel.
522
+ * @param {any} opt
523
+ * @returns {Promise<any>}
524
+ */
525
+ NCloudChat.prototype.sendExpressMessage = function (channel, opt) {
359
526
  return __awaiter(this, void 0, void 0, function () {
360
527
  var user, data;
361
528
  return __generator(this, function (_a) {
362
- if (!this.isConnected()) {
529
+ if (!this.isConnected())
363
530
  throw Error("You are not connected.");
364
- }
365
- // 채널 아이디가 존재하지 않을 경우 오류
366
- if (!channel) {
367
- throw Error("Channel ID is not found");
368
- }
531
+ this.inputValidation({ channelId: channel, message: opt.message });
369
532
  if (!opt.type)
370
533
  opt.type = "text";
371
- if (!opt.message) {
372
- throw Error("Message is NULL");
373
- }
374
534
  user = CoreManager.get("USER");
535
+ if (!user)
536
+ throw Error('user is null');
375
537
  try {
376
538
  data = __assign({ channelId: channel, user: user }, opt);
377
- this.socket.emit("message", data);
539
+ this.socket.emit("express message", data);
378
540
  return [2 /*return*/, data];
379
541
  }
380
542
  catch (e) {
381
- return [2 /*return*/, false];
543
+ throw e;
382
544
  }
383
545
  return [2 /*return*/];
384
546
  });
385
547
  });
386
548
  };
549
+ /**
550
+ * Send an image to a channel. Only supports png, jpg, jpeg file types.
551
+ *
552
+ * @async
553
+ * @function sendImage
554
+ * @param {string} channelId - The id of a channel.
555
+ * @param {any} file - An image file.
556
+ * @returns {Promise<any>}
557
+ */
387
558
  NCloudChat.prototype.sendImage = function (channelId, file) {
388
559
  return __awaiter(this, void 0, void 0, function () {
389
- var user, result;
560
+ var result;
390
561
  return __generator(this, function (_a) {
391
562
  switch (_a.label) {
392
563
  case 0:
393
- if (!this.isConnected()) {
394
- throw Error("You are not connected.");
395
- }
396
- user = CoreManager.get("USER");
564
+ this.inputValidation({ channelId: channelId });
397
565
  return [4 /*yield*/, upload(channelId, file)];
398
566
  case 1:
399
567
  result = _a.sent();
@@ -404,45 +572,103 @@ var NCloudChat = /** @class */ (function () {
404
572
  });
405
573
  });
406
574
  };
575
+ /**
576
+ * Update a message.
577
+ *
578
+ * @todo
579
+ * @async
580
+ * @function updateMessage
581
+ * @param {string} channel
582
+ * @param {string} message_id
583
+ * @param {string} message
584
+ */
407
585
  NCloudChat.prototype.updateMessage = function (channel, message_id, message) {
408
586
  return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
409
587
  return [2 /*return*/];
410
588
  }); });
411
589
  };
590
+ /**
591
+ * Delete a message.
592
+ * @async
593
+ * @function deleteMessage
594
+ * @param {string} channel
595
+ * @param {string} message_id
596
+ */
412
597
  NCloudChat.prototype.deleteMessage = function (channel, message_id) {
413
598
  return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
414
599
  return [2 /*return*/];
415
600
  }); });
416
601
  };
602
+ /**
603
+ * Disconnect from a socket.
604
+ *
605
+ * @async
606
+ * @function disconnect
607
+ * @returns
608
+ */
417
609
  NCloudChat.prototype.disconnect = function () {
418
610
  return __awaiter(this, void 0, void 0, function () {
419
611
  return __generator(this, function (_a) {
420
612
  if (!this.isConnected())
421
613
  return [2 /*return*/];
422
614
  this.socket.disconnect();
615
+ CoreManager.set("TOKEN", "");
423
616
  return [2 /*return*/];
424
617
  });
425
618
  });
426
619
  };
620
+ /**
621
+ * Check if a client is connected to a socket.
622
+ *
623
+ * @function isConnected
624
+ * @returns {boolean}
625
+ */
427
626
  NCloudChat.prototype.isConnected = function () {
627
+ var token = CoreManager.get("TOKEN");
628
+ if (token)
629
+ return true;
630
+ return false;
631
+ };
632
+ NCloudChat.prototype.isSocketConnected = function () {
428
633
  return this.connected ? true : false;
429
634
  };
635
+ /**
636
+ * Bind fn event handlers.
637
+ *
638
+ * @async
639
+ * @function bind
640
+ * @param {string} id
641
+ * @param {any} fn
642
+ */
430
643
  NCloudChat.prototype.bind = function (id, fn) {
431
644
  return __awaiter(this, void 0, void 0, function () {
432
645
  return __generator(this, function (_a) {
646
+ this.dp.off(id);
433
647
  this.dp.on(id, fn);
434
648
  return [2 /*return*/];
435
649
  });
436
650
  });
437
651
  };
438
- NCloudChat.prototype.unbind = function (id, fn) {
652
+ /**
653
+ * Unbind fn event handlers.
654
+ *
655
+ * @async
656
+ * @function unbind
657
+ * @param {string} id
658
+ * @param {any} fn
659
+ */
660
+ NCloudChat.prototype.unbind = function (id) {
439
661
  return __awaiter(this, void 0, void 0, function () {
440
662
  return __generator(this, function (_a) {
441
- this.dp.off(id, fn);
663
+ this.dp.off(id);
442
664
  return [2 /*return*/];
443
665
  });
444
666
  });
445
667
  };
668
+ /**
669
+ * Unbind all event handlers.
670
+ * @param id
671
+ */
446
672
  NCloudChat.prototype.unbindall = function (id) {
447
673
  return __awaiter(this, void 0, void 0, function () {
448
674
  return __generator(this, function (_a) {
@@ -451,22 +677,38 @@ var NCloudChat = /** @class */ (function () {
451
677
  });
452
678
  });
453
679
  };
680
+ /**
681
+ * Decodes a base-64 encoded string.
682
+ *
683
+ * @function ObjectId
684
+ * @param {string} id - An encoded string to be decoded.
685
+ * @returns {string} decoded string.
686
+ */
454
687
  NCloudChat.prototype.ObjectId = function (id) {
455
688
  if (!id)
456
689
  return "";
457
690
  return atob(id).split(":")[1];
458
691
  };
692
+ /**
693
+ * Get current friends list of all status.
694
+ *
695
+ * @async
696
+ * @function getFriendships
697
+ * @param {string} filter - Field value for filter.
698
+ * @param {string} sort - Field value for sorting.
699
+ * @param {string} option - Optional option: ex) offset, per_page.
700
+ * @returns {Promise<any>}
701
+ */
459
702
  NCloudChat.prototype.getFriendships = function (filter, sort, option) {
460
703
  if (sort === void 0) { sort = {}; }
461
704
  if (option === void 0) { option = {}; }
462
705
  return __awaiter(this, void 0, void 0, function () {
463
- var entries, friends, e_7;
706
+ var entries, friends, e_9;
707
+ var _this = this;
464
708
  return __generator(this, function (_a) {
465
709
  switch (_a.label) {
466
710
  case 0:
467
- if (!this.isConnected()) {
468
- throw Error("You are not connected.");
469
- }
711
+ this.inputValidation({});
470
712
  _a.label = 1;
471
713
  case 1:
472
714
  _a.trys.push([1, 3, , 4]);
@@ -474,65 +716,83 @@ var NCloudChat = /** @class */ (function () {
474
716
  case 2:
475
717
  entries = _a.sent();
476
718
  if (entries) {
477
- friends = entries.map(function (item) {
478
- return __assign(__assign({}, item.node), { id: (item.node.id) });
719
+ friends = entries["edges"].map(function (item) {
720
+ item.node.friend.id = _this.ObjectId(item.node.friend.id);
721
+ item.node.user.id = _this.ObjectId(item.node.user.id);
722
+ return __assign(__assign({}, item.node), { id: item.node.id });
479
723
  });
480
724
  return [2 /*return*/, friends];
481
725
  }
482
- return [2 /*return*/, entries];
726
+ return [2 /*return*/, entries["edges"]];
483
727
  case 3:
484
- e_7 = _a.sent();
485
- throw e_7;
728
+ e_9 = _a.sent();
729
+ throw e_9;
486
730
  case 4: return [2 /*return*/];
487
731
  }
488
732
  });
489
733
  });
490
734
  };
491
- NCloudChat.prototype.getMemberBlocks = function (filter, sort, option) {
735
+ /**
736
+ * Get member blocks.
737
+ *
738
+ * @async
739
+ * @function getBannedUsers
740
+ * @param {string} filter - Field value for filter.
741
+ * @param {string} sort - Field value for sorting.
742
+ * @param {string} option - Optional option: ex) offset, per_page.
743
+ * @returns {Promise<any>}
744
+ */
745
+ NCloudChat.prototype.getBannedUsers = function (filter, sort, option) {
492
746
  if (sort === void 0) { sort = {}; }
493
747
  if (option === void 0) { option = {}; }
494
748
  return __awaiter(this, void 0, void 0, function () {
495
- var entries, members, e_8;
749
+ var entries, members, e_10;
496
750
  var _this = this;
497
751
  return __generator(this, function (_a) {
498
752
  switch (_a.label) {
499
753
  case 0:
500
- if (!this.isConnected()) {
501
- throw Error("You are not connected.");
502
- }
754
+ this.inputValidation({});
503
755
  _a.label = 1;
504
756
  case 1:
505
757
  _a.trys.push([1, 3, , 4]);
506
758
  return [4 /*yield*/, getMemberBlocks(JSON.stringify(filter), JSON.stringify(sort), JSON.stringify(option))];
507
759
  case 2:
508
760
  entries = _a.sent();
509
- if (entries) {
510
- members = entries.map(function (item) {
761
+ if (entries["edges"]) {
762
+ members = entries["edges"].map(function (item) {
511
763
  return __assign(__assign({}, item.node), { id: _this.ObjectId(item.node.id) });
512
764
  });
513
765
  return [2 /*return*/, members];
514
766
  }
515
- return [2 /*return*/, entries];
767
+ return [2 /*return*/, entries["edges"]];
516
768
  case 3:
517
- e_8 = _a.sent();
518
- throw e_8;
769
+ e_10 = _a.sent();
770
+ throw e_10;
519
771
  case 4: return [2 /*return*/];
520
772
  }
521
773
  });
522
774
  });
523
775
  };
524
- NCloudChat.prototype.getMembers = function (filter, sort, option) {
776
+ /**
777
+ * Get information data of the member.
778
+ *
779
+ * @async
780
+ * @function getUsers
781
+ * @param {string} filter - Field value for filter.
782
+ * @param {string} sort - Field value for sorting.
783
+ * @param {string} option - Optional option: ex) offset, per_page.
784
+ * @returns {Promise<any>}
785
+ */
786
+ NCloudChat.prototype.getUsers = function (filter, sort, option) {
525
787
  if (sort === void 0) { sort = {}; }
526
788
  if (option === void 0) { option = {}; }
527
789
  return __awaiter(this, void 0, void 0, function () {
528
- var entries, members, e_9;
790
+ var entries, members, e_11;
529
791
  var _this = this;
530
792
  return __generator(this, function (_a) {
531
793
  switch (_a.label) {
532
794
  case 0:
533
- if (!this.isConnected()) {
534
- throw Error("You are not connected.");
535
- }
795
+ this.inputValidation({});
536
796
  _a.label = 1;
537
797
  case 1:
538
798
  _a.trys.push([1, 3, , 4]);
@@ -540,216 +800,307 @@ var NCloudChat = /** @class */ (function () {
540
800
  case 2:
541
801
  entries = _a.sent();
542
802
  if (entries) {
543
- members = entries.map(function (item) {
803
+ members = entries['edges'].map(function (item) {
544
804
  return __assign(__assign({}, item.node), { id: _this.ObjectId(item.node.id) });
545
805
  });
546
806
  return [2 /*return*/, members];
547
807
  }
548
- return [2 /*return*/, entries];
808
+ return [3 /*break*/, 4];
549
809
  case 3:
550
- e_9 = _a.sent();
551
- throw e_9;
810
+ e_11 = _a.sent();
811
+ throw e_11;
552
812
  case 4: return [2 /*return*/];
553
813
  }
554
814
  });
555
815
  });
556
816
  };
557
- NCloudChat.prototype.getChannels = function (filter, sort, option) {
558
- if (sort === void 0) { sort = {}; }
559
- if (option === void 0) { option = {}; }
817
+ /**
818
+ * Request a friendship to a user.
819
+ *
820
+ * @async
821
+ * @function requestFriend
822
+ * @param {string} friendId - An id of the friend to request.
823
+ * @returns {Promise<any>}
824
+ */
825
+ NCloudChat.prototype.requestFriend = function (friendId) {
560
826
  return __awaiter(this, void 0, void 0, function () {
561
- var entries, channels, e_10;
562
- var _this = this;
827
+ var result, e_12;
563
828
  return __generator(this, function (_a) {
564
829
  switch (_a.label) {
565
830
  case 0:
566
- if (!this.isConnected()) {
567
- throw Error("You are not connected.");
568
- }
831
+ this.inputValidation({ friendId: friendId });
569
832
  _a.label = 1;
570
833
  case 1:
571
834
  _a.trys.push([1, 3, , 4]);
572
- return [4 /*yield*/, getChannels(JSON.stringify(filter), JSON.stringify(sort), JSON.stringify(option))];
835
+ return [4 /*yield*/, requestFriend(friendId)];
573
836
  case 2:
574
- entries = _a.sent();
575
- if (entries) {
576
- channels = entries.map(function (item) {
577
- return __assign(__assign({}, item.node), { id: _this.ObjectId(item.node.id) });
578
- });
579
- return [2 /*return*/, channels];
837
+ result = _a.sent();
838
+ if (result["friendship"]) {
839
+ result["friendship"]["user"]["id"] = this.ObjectId(result["friendship"]["user"]["id"]);
840
+ result["friendship"]["friend"]["id"] = this.ObjectId(result["friendship"]["friend"]["id"]);
580
841
  }
581
- return [2 /*return*/, entries];
842
+ return [2 /*return*/, result["friendship"]];
582
843
  case 3:
583
- e_10 = _a.sent();
584
- throw e_10;
844
+ e_12 = _a.sent();
845
+ throw e_12;
585
846
  case 4: return [2 /*return*/];
586
847
  }
587
848
  });
588
849
  });
589
850
  };
590
- NCloudChat.prototype.requestFriend = function (friendId) {
851
+ /**
852
+ * Accept a friends request.
853
+ *
854
+ * @async
855
+ * @function acceptFriend
856
+ * @param {string} friendId - The id of the friend to accept the request.
857
+ * @returns {Promise<any>}
858
+ */
859
+ NCloudChat.prototype.acceptFriend = function (friendId) {
591
860
  return __awaiter(this, void 0, void 0, function () {
592
- var e_11;
861
+ var result, e_13;
593
862
  return __generator(this, function (_a) {
594
863
  switch (_a.label) {
595
864
  case 0:
596
- if (!this.isConnected()) {
597
- throw Error("You are not connected.");
598
- }
865
+ this.inputValidation({ friendId: friendId });
599
866
  _a.label = 1;
600
867
  case 1:
601
868
  _a.trys.push([1, 3, , 4]);
602
- return [4 /*yield*/, requestFriend(friendId)];
603
- case 2: return [2 /*return*/, _a.sent()];
869
+ return [4 /*yield*/, acceptFriend(friendId)];
870
+ case 2:
871
+ result = _a.sent();
872
+ if (result["friendship"]) {
873
+ result["friendship"]["user"]["id"] = this.ObjectId(result["friendship"]["user"]["id"]);
874
+ result["friendship"]["friend"]["id"] = this.ObjectId(result["friendship"]["friend"]["id"]);
875
+ }
876
+ return [2 /*return*/, result["friendship"]];
604
877
  case 3:
605
- e_11 = _a.sent();
606
- throw e_11;
878
+ e_13 = _a.sent();
879
+ throw e_13;
607
880
  case 4: return [2 /*return*/];
608
881
  }
609
882
  });
610
883
  });
611
884
  };
612
- NCloudChat.prototype.acceptFriend = function (friendId) {
885
+ /**
886
+ * Reject a friend request.
887
+ *
888
+ * @async
889
+ * @function rejectFriend
890
+ * @param {string} friendId - An id of the friend to be rejected.
891
+ * @returns {Promise<any>}
892
+ */
893
+ NCloudChat.prototype.rejectFriend = function (friendId) {
613
894
  return __awaiter(this, void 0, void 0, function () {
614
- var e_12;
895
+ var result, e_14;
615
896
  return __generator(this, function (_a) {
616
897
  switch (_a.label) {
617
898
  case 0:
618
- if (!this.isConnected()) {
619
- throw Error("You are not connected.");
620
- }
899
+ this.inputValidation({ friendId: friendId });
621
900
  _a.label = 1;
622
901
  case 1:
623
902
  _a.trys.push([1, 3, , 4]);
624
- return [4 /*yield*/, acceptFriend(friendId)];
625
- case 2: return [2 /*return*/, _a.sent()];
903
+ return [4 /*yield*/, rejectFriend(friendId)];
904
+ case 2:
905
+ result = _a.sent();
906
+ if (result["friendship"]) {
907
+ result["friendship"]["user"]["id"] = this.ObjectId(result["friendship"]["user"]["id"]);
908
+ result["friendship"]["friend"]["id"] = this.ObjectId(result["friendship"]["friend"]["id"]);
909
+ }
910
+ return [2 /*return*/, result["friendship"]];
626
911
  case 3:
627
- e_12 = _a.sent();
628
- throw e_12;
912
+ e_14 = _a.sent();
913
+ throw e_14;
629
914
  case 4: return [2 /*return*/];
630
915
  }
631
916
  });
632
917
  });
633
918
  };
634
- NCloudChat.prototype.rejectFriend = function (friendId) {
919
+ /**
920
+ * Remove a friend.
921
+ *
922
+ * @async
923
+ * @function removeFriend
924
+ * @param {string} friendId - An id of the friend to be removed.
925
+ * @returns {Promise<any>}
926
+ */
927
+ NCloudChat.prototype.removeFriend = function (friendId) {
635
928
  return __awaiter(this, void 0, void 0, function () {
636
- var e_13;
929
+ var result, e_15;
637
930
  return __generator(this, function (_a) {
638
931
  switch (_a.label) {
639
932
  case 0:
640
- if (!this.isConnected()) {
641
- throw Error("You are not connected.");
642
- }
933
+ this.inputValidation({ friendId: friendId });
643
934
  _a.label = 1;
644
935
  case 1:
645
936
  _a.trys.push([1, 3, , 4]);
646
- return [4 /*yield*/, rejectFriend(friendId)];
647
- case 2: return [2 /*return*/, _a.sent()];
937
+ return [4 /*yield*/, removeFriend(friendId)];
938
+ case 2:
939
+ result = _a.sent();
940
+ if (result["friendship"]) {
941
+ result["friendship"]["user"]["id"] = this.ObjectId(result["friendship"]["user"]["id"]);
942
+ result["friendship"]["friend"]["id"] = this.ObjectId(result["friendship"]["friend"]["id"]);
943
+ }
944
+ return [2 /*return*/, result["friendship"]];
648
945
  case 3:
649
- e_13 = _a.sent();
650
- throw e_13;
946
+ e_15 = _a.sent();
947
+ throw e_15;
651
948
  case 4: return [2 /*return*/];
652
949
  }
653
950
  });
654
951
  });
655
952
  };
656
- NCloudChat.prototype.removeFriend = function (friendId) {
953
+ /**
954
+ * Get a count of unread messages of a channel.
955
+ *
956
+ * @async
957
+ * @function countUnread
958
+ * @param {string} channelId - The id of a channel.
959
+ * @returns {Promise<any>}
960
+ */
961
+ NCloudChat.prototype.countUnread = function (channelId) {
657
962
  return __awaiter(this, void 0, void 0, function () {
658
- var e_14;
963
+ var e_16;
659
964
  return __generator(this, function (_a) {
660
965
  switch (_a.label) {
661
966
  case 0:
662
- if (!this.isConnected()) {
663
- throw Error("You are not connected.");
664
- }
967
+ this.inputValidation({ channelId: channelId });
665
968
  _a.label = 1;
666
969
  case 1:
667
970
  _a.trys.push([1, 3, , 4]);
668
- return [4 /*yield*/, removeFriend(friendId)];
971
+ return [4 /*yield*/, unreadCount(channelId)];
669
972
  case 2: return [2 /*return*/, _a.sent()];
670
973
  case 3:
671
- e_14 = _a.sent();
672
- throw e_14;
974
+ e_16 = _a.sent();
975
+ throw e_16;
673
976
  case 4: return [2 /*return*/];
674
977
  }
675
978
  });
676
979
  });
677
980
  };
678
- NCloudChat.prototype.countUnread = function (channelId) {
981
+ /**
982
+ * Get subscription data of the user.
983
+ *
984
+ * @async
985
+ * @function getSubscription
986
+ * @param {string} channelId - The id of a channel.
987
+ * @param {string} id
988
+ * @returns {Promise<any>}
989
+ */
990
+ NCloudChat.prototype.getSubscription = function (channelId, id) {
679
991
  return __awaiter(this, void 0, void 0, function () {
680
- var e_15;
992
+ var subscription, e_17;
681
993
  return __generator(this, function (_a) {
682
994
  switch (_a.label) {
683
995
  case 0:
684
- if (!this.isConnected()) {
685
- throw Error("You are not connected.");
686
- }
996
+ this.inputValidation({ channelId: channelId, subscriptionId: id });
687
997
  _a.label = 1;
688
998
  case 1:
689
999
  _a.trys.push([1, 3, , 4]);
690
- return [4 /*yield*/, unreadCount(channelId)];
691
- case 2: return [2 /*return*/, _a.sent()];
1000
+ return [4 /*yield*/, getSubscription(channelId, id)];
1001
+ case 2:
1002
+ subscription = _a.sent();
1003
+ if (subscription)
1004
+ subscription["id"] = this.ObjectId(subscription["id"]);
1005
+ return [2 /*return*/, subscription];
692
1006
  case 3:
693
- e_15 = _a.sent();
694
- throw e_15;
1007
+ e_17 = _a.sent();
1008
+ throw e_17;
695
1009
  case 4: return [2 /*return*/];
696
1010
  }
697
1011
  });
698
1012
  });
699
1013
  };
700
- NCloudChat.prototype.getSubscription = function (channelId, id) {
1014
+ /**
1015
+ * Get data of a single channel from the endpoint.
1016
+ *
1017
+ * @async
1018
+ * @function getChannel
1019
+ * @param {string} channelId - An id of the channel.
1020
+ * @returns {Promise<any>} The data of the channel.
1021
+ */
1022
+ NCloudChat.prototype.getChannel = function (channelId) {
701
1023
  return __awaiter(this, void 0, void 0, function () {
702
- var e_16;
1024
+ var result, e_18;
703
1025
  return __generator(this, function (_a) {
704
1026
  switch (_a.label) {
705
1027
  case 0:
706
- if (!this.isConnected()) {
707
- throw Error("You are not connected.");
708
- }
1028
+ this.inputValidation({ channelId: channelId });
709
1029
  _a.label = 1;
710
1030
  case 1:
711
1031
  _a.trys.push([1, 3, , 4]);
712
- return [4 /*yield*/, getSubscription(channelId, id)];
713
- case 2: return [2 /*return*/, _a.sent()];
1032
+ return [4 /*yield*/, getChannel(channelId)];
1033
+ case 2:
1034
+ result = _a.sent();
1035
+ if (result) {
1036
+ result.id = this.ObjectId(result.id);
1037
+ result["user_id"]["id"] = this.ObjectId(result["user_id"]["id"]);
1038
+ }
1039
+ return [2 /*return*/, result];
714
1040
  case 3:
715
- e_16 = _a.sent();
716
- throw e_16;
717
- case 4: return [2 /*return*/, null];
1041
+ e_18 = _a.sent();
1042
+ throw e_18;
1043
+ case 4: return [2 /*return*/];
718
1044
  }
719
1045
  });
720
1046
  });
721
1047
  };
722
- NCloudChat.prototype.getChannel = function (channelId) {
1048
+ /**
1049
+ * Get data of multiple channels.
1050
+ *
1051
+ * @async
1052
+ * @function getChannels
1053
+ * @param {string} filter - Field value for filter.
1054
+ * @param {string} sort - Field value for sorting.
1055
+ * @param {string} option - Optional option: ex) offset, per_page.
1056
+ * @returns {Promise<any[]>} An array of data of all channels.
1057
+ */
1058
+ NCloudChat.prototype.getChannels = function (filter, sort, option) {
1059
+ if (sort === void 0) { sort = {}; }
1060
+ if (option === void 0) { option = {}; }
723
1061
  return __awaiter(this, void 0, void 0, function () {
724
- var e_17;
1062
+ var entries, channels, e_19;
1063
+ var _this = this;
725
1064
  return __generator(this, function (_a) {
726
1065
  switch (_a.label) {
727
1066
  case 0:
728
- if (!this.isConnected()) {
729
- throw Error("You are not connected.");
730
- }
1067
+ this.inputValidation({});
731
1068
  _a.label = 1;
732
1069
  case 1:
733
1070
  _a.trys.push([1, 3, , 4]);
734
- return [4 /*yield*/, getChannel(channelId)];
735
- case 2: return [2 /*return*/, _a.sent()];
1071
+ return [4 /*yield*/, getChannels(JSON.stringify(filter), JSON.stringify(sort), JSON.stringify(option))];
1072
+ case 2:
1073
+ entries = _a.sent();
1074
+ if (entries["edges"]) {
1075
+ channels = entries["edges"].map(function (item) {
1076
+ item.node.user_id.id = _this.ObjectId(item.node.user_id.id);
1077
+ return __assign(__assign({}, item.node), { id: _this.ObjectId(item.node.id) });
1078
+ });
1079
+ return [2 /*return*/, channels];
1080
+ }
1081
+ return [2 /*return*/, entries["edges"]];
736
1082
  case 3:
737
- e_17 = _a.sent();
738
- throw e_17;
739
- case 4: return [2 /*return*/, null];
1083
+ e_19 = _a.sent();
1084
+ throw e_19;
1085
+ case 4: return [2 /*return*/];
740
1086
  }
741
1087
  });
742
1088
  });
743
1089
  };
1090
+ /**
1091
+ * @async
1092
+ * @function getMessage
1093
+ * @param {string} channelId - The id of a channel.
1094
+ * @param {string} messageId - The id of a message.
1095
+ * @returns {Promise<any>}
1096
+ */
744
1097
  NCloudChat.prototype.getMessage = function (channelId, messageId) {
745
1098
  return __awaiter(this, void 0, void 0, function () {
746
- var entry, e_18;
1099
+ var entry, e_20;
747
1100
  return __generator(this, function (_a) {
748
1101
  switch (_a.label) {
749
1102
  case 0:
750
- if (!this.isConnected()) {
751
- throw Error("You are not connected.");
752
- }
1103
+ this.inputValidation({ channelId: channelId, messageId: messageId });
753
1104
  _a.label = 1;
754
1105
  case 1:
755
1106
  _a.trys.push([1, 3, , 4]);
@@ -760,227 +1111,343 @@ var NCloudChat = /** @class */ (function () {
760
1111
  entry.id = this.ObjectId(entry.id);
761
1112
  return [2 /*return*/, entry];
762
1113
  }
763
- return [2 /*return*/, null];
1114
+ return [2 /*return*/, entry];
764
1115
  case 3:
765
- e_18 = _a.sent();
766
- throw e_18;
1116
+ e_20 = _a.sent();
1117
+ throw e_20;
767
1118
  case 4: return [2 /*return*/];
768
1119
  }
769
1120
  });
770
1121
  });
771
1122
  };
1123
+ /**
1124
+ * Get data of the all messages.
1125
+ *
1126
+ * @async
1127
+ * @function getMessages
1128
+ * @param {string} filter - Field value for filter.
1129
+ * @param {string} sort - Field value for sorting.
1130
+ * @param {string} option - Optional option: ex) offset, per_page.
1131
+ * @returns {Promise<any>}
1132
+ */
772
1133
  NCloudChat.prototype.getMessages = function (filter, sort, option) {
773
1134
  return __awaiter(this, void 0, void 0, function () {
774
- var entries, messages, e_19;
1135
+ var entries, messages, e_21;
775
1136
  var _this = this;
776
1137
  return __generator(this, function (_a) {
777
1138
  switch (_a.label) {
778
1139
  case 0:
779
- if (!this.isConnected()) {
780
- throw Error("You are not connected.");
781
- }
1140
+ this.inputValidation({});
782
1141
  _a.label = 1;
783
1142
  case 1:
784
1143
  _a.trys.push([1, 3, , 4]);
785
1144
  return [4 /*yield*/, getMessages(JSON.stringify(filter), JSON.stringify(sort), JSON.stringify(option))];
786
1145
  case 2:
787
1146
  entries = _a.sent();
788
- if (entries) {
789
- messages = entries.map(function (item) {
1147
+ if (entries["edges"]) {
1148
+ messages = entries["edges"].map(function (item) {
790
1149
  return __assign(__assign({}, item.node), { id: _this.ObjectId(item.node.id) });
791
1150
  });
792
1151
  return [2 /*return*/, messages];
793
1152
  }
794
- return [2 /*return*/, entries];
1153
+ return [2 /*return*/, entries["edges"]];
795
1154
  case 3:
796
- e_19 = _a.sent();
797
- throw e_19;
1155
+ e_21 = _a.sent();
1156
+ throw e_21;
798
1157
  case 4: return [2 /*return*/];
799
1158
  }
800
1159
  });
801
1160
  });
802
1161
  };
1162
+ /**
1163
+ * Get a list of subscibed member of the channel.
1164
+ * @param {string} filter - Field value for filter.
1165
+ * @param {string} sort - Field value for sorting.
1166
+ * @param {string} option - Optional option: ex) offset, per_page.
1167
+ * @returns {Promise<any>}
1168
+ */
803
1169
  NCloudChat.prototype.getSubscriptions = function (filter, sort, option) {
804
1170
  return __awaiter(this, void 0, void 0, function () {
805
- var entries, subscribes, e_20;
1171
+ var entries, subscribes, e_22;
806
1172
  var _this = this;
807
1173
  return __generator(this, function (_a) {
808
1174
  switch (_a.label) {
809
1175
  case 0:
810
- if (!this.isConnected()) {
811
- throw Error("You are not connected.");
812
- }
1176
+ this.inputValidation({});
813
1177
  _a.label = 1;
814
1178
  case 1:
815
1179
  _a.trys.push([1, 3, , 4]);
816
1180
  return [4 /*yield*/, getSubscriptions(JSON.stringify(filter), JSON.stringify(sort), JSON.stringify(option))];
817
1181
  case 2:
818
1182
  entries = _a.sent();
819
- if (entries) {
820
- subscribes = entries.map(function (item) {
1183
+ if (entries["edges"]) {
1184
+ subscribes = entries["edges"].map(function (item) {
821
1185
  return __assign(__assign({}, item.node), { id: _this.ObjectId(item.node.id) });
822
1186
  });
823
1187
  return [2 /*return*/, subscribes];
824
1188
  }
825
- return [2 /*return*/, entries];
1189
+ return [2 /*return*/, entries["edges"]];
826
1190
  case 3:
827
- e_20 = _a.sent();
828
- throw e_20;
1191
+ e_22 = _a.sent();
1192
+ throw e_22;
829
1193
  case 4: return [2 /*return*/];
830
1194
  }
831
1195
  });
832
1196
  });
833
1197
  };
1198
+ /**
1199
+ * Create a new channel.
1200
+ *
1201
+ * @async
1202
+ * @function createChannel
1203
+ * @param {ChannelInput} channel - Configuration options of the new channel.
1204
+ * @returns {Promise<any>} The data of the newly created channel.
1205
+ */
834
1206
  NCloudChat.prototype.createChannel = function (channel) {
835
1207
  return __awaiter(this, void 0, void 0, function () {
836
- var e_21;
1208
+ var result, e_23;
837
1209
  return __generator(this, function (_a) {
838
1210
  switch (_a.label) {
839
1211
  case 0:
840
- if (!this.isConnected()) {
841
- throw Error("You are not connected.");
842
- }
1212
+ this.inputValidation({
1213
+ channelType: channel.type,
1214
+ channelName: channel.name
1215
+ });
843
1216
  _a.label = 1;
844
1217
  case 1:
845
1218
  _a.trys.push([1, 3, , 4]);
846
1219
  return [4 /*yield*/, createChannel(channel)];
847
- case 2: return [2 /*return*/, _a.sent()];
1220
+ case 2:
1221
+ result = _a.sent();
1222
+ if (result["channel"]) {
1223
+ result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
1224
+ result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
1225
+ }
1226
+ return [2 /*return*/, result["channel"]];
848
1227
  case 3:
849
- e_21 = _a.sent();
850
- throw e_21;
1228
+ e_23 = _a.sent();
1229
+ throw e_23;
851
1230
  case 4: return [2 /*return*/];
852
1231
  }
853
1232
  });
854
1233
  });
855
1234
  };
1235
+ /**
1236
+ * Update channel options.
1237
+ *
1238
+ * @async
1239
+ * @function updateChannel
1240
+ * @param {string} channelId - An id of the channel.
1241
+ * @param {ChannelInput} channel - New options of the channel.
1242
+ * @returns {Promise<any>} The data of the updated channel.
1243
+ */
856
1244
  NCloudChat.prototype.updateChannel = function (channelId, channel) {
857
1245
  return __awaiter(this, void 0, void 0, function () {
858
- var e_22;
1246
+ var result, e_24;
859
1247
  return __generator(this, function (_a) {
860
1248
  switch (_a.label) {
861
1249
  case 0:
862
- if (!this.isConnected()) {
863
- throw Error("You are not connected.");
864
- }
1250
+ this.inputValidation({
1251
+ channelId: channelId
1252
+ });
1253
+ if (!channel.name)
1254
+ throw Error("You need at least a channel name or a type.");
865
1255
  _a.label = 1;
866
1256
  case 1:
867
1257
  _a.trys.push([1, 3, , 4]);
868
1258
  return [4 /*yield*/, updateChannel(channelId, channel)];
869
- case 2: return [2 /*return*/, _a.sent()];
1259
+ case 2:
1260
+ result = _a.sent();
1261
+ if (result["channel"]) {
1262
+ result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
1263
+ result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
1264
+ }
1265
+ return [2 /*return*/, result["channel"]];
870
1266
  case 3:
871
- e_22 = _a.sent();
872
- throw e_22;
1267
+ e_24 = _a.sent();
1268
+ throw e_24;
873
1269
  case 4: return [2 /*return*/];
874
1270
  }
875
1271
  });
876
1272
  });
877
1273
  };
1274
+ /**
1275
+ * Delete a channel.
1276
+ *
1277
+ * @async
1278
+ * @function deleteChannel
1279
+ * @param {string} channelId - An channel id.
1280
+ * @returns {Promise<any>}
1281
+ */
878
1282
  NCloudChat.prototype.deleteChannel = function (channelId) {
879
1283
  return __awaiter(this, void 0, void 0, function () {
880
- var e_23;
1284
+ var result, e_25;
881
1285
  return __generator(this, function (_a) {
882
1286
  switch (_a.label) {
883
1287
  case 0:
884
- if (!this.isConnected()) {
885
- throw Error("You are not connected.");
886
- }
1288
+ this.inputValidation({ channelId: channelId });
887
1289
  _a.label = 1;
888
1290
  case 1:
889
1291
  _a.trys.push([1, 3, , 4]);
890
1292
  return [4 /*yield*/, deleteChannel(channelId)];
891
- case 2: return [2 /*return*/, _a.sent()];
1293
+ case 2:
1294
+ result = _a.sent();
1295
+ if (result["channel"]) {
1296
+ result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
1297
+ result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
1298
+ }
1299
+ return [2 /*return*/, result["channel"]];
892
1300
  case 3:
893
- e_23 = _a.sent();
894
- throw e_23;
1301
+ e_25 = _a.sent();
1302
+ throw e_25;
895
1303
  case 4: return [2 /*return*/];
896
1304
  }
897
1305
  });
898
1306
  });
899
1307
  };
1308
+ /**
1309
+ * Update a subscription information, such as marking message read.
1310
+ *
1311
+ * @async
1312
+ * @function markRead
1313
+ * @param {string} channelId - The id of a channel.
1314
+ * @param {MarkInput} mark
1315
+ * @param {string} option
1316
+ * @returns {Promise<any>}
1317
+ */
900
1318
  NCloudChat.prototype.markRead = function (channelId, mark, option) {
901
1319
  if (option === void 0) { option = null; }
902
1320
  return __awaiter(this, void 0, void 0, function () {
903
- var e_24;
1321
+ var result, e_26;
904
1322
  return __generator(this, function (_a) {
905
1323
  switch (_a.label) {
906
1324
  case 0:
907
- if (!this.isConnected()) {
908
- throw Error("You are not connected.");
909
- }
1325
+ this.inputValidation({
1326
+ channelId: channelId,
1327
+ userId: mark.userId,
1328
+ messageId: mark.messageId,
1329
+ sortId: mark.sortId
1330
+ });
910
1331
  _a.label = 1;
911
1332
  case 1:
912
1333
  _a.trys.push([1, 3, , 4]);
913
1334
  return [4 /*yield*/, updateSubscription(channelId, mark, JSON.stringify(option))];
914
- case 2: return [2 /*return*/, _a.sent()];
1335
+ case 2:
1336
+ result = _a.sent();
1337
+ return [2 /*return*/, result["subscription"]];
915
1338
  case 3:
916
- e_24 = _a.sent();
917
- throw e_24;
1339
+ e_26 = _a.sent();
1340
+ throw e_26;
918
1341
  case 4: return [2 /*return*/];
919
1342
  }
920
1343
  });
921
1344
  });
922
1345
  };
923
- NCloudChat.prototype.addMembers = function (channelId, memberIds, options) {
1346
+ /**
1347
+ * Add members to the private channel.
1348
+ *
1349
+ * @async
1350
+ * @function addUsers
1351
+ * @param {string} channelId - An private channel id.
1352
+ * @param {string[]} userIds - An array of member ids to be added.
1353
+ * @param {any} options
1354
+ * @returns {Promise<any>}
1355
+ */
1356
+ NCloudChat.prototype.addUsers = function (channelId, userIds, options) {
924
1357
  return __awaiter(this, void 0, void 0, function () {
925
- var input, e_25;
1358
+ var result, e_27;
926
1359
  return __generator(this, function (_a) {
927
1360
  switch (_a.label) {
928
1361
  case 0:
929
- if (!this.isConnected()) {
930
- throw Error("You are not connected.");
931
- }
1362
+ this.inputValidation({
1363
+ channelId: channelId,
1364
+ userIds: userIds
1365
+ });
932
1366
  _a.label = 1;
933
1367
  case 1:
934
1368
  _a.trys.push([1, 3, , 4]);
935
- input = {
936
- members: memberIds
937
- };
938
- return [4 /*yield*/, addChannelMembers(channelId, memberIds, options)];
939
- case 2: return [2 /*return*/, _a.sent()];
1369
+ return [4 /*yield*/, addChannelMembers(channelId, userIds, options)];
1370
+ case 2:
1371
+ result = _a.sent();
1372
+ if (result["channel"]) {
1373
+ result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
1374
+ result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
1375
+ }
1376
+ return [2 /*return*/, result["channel"]];
940
1377
  case 3:
941
- e_25 = _a.sent();
942
- throw e_25;
1378
+ e_27 = _a.sent();
1379
+ throw e_27;
943
1380
  case 4: return [2 /*return*/];
944
1381
  }
945
1382
  });
946
1383
  });
947
1384
  };
948
- NCloudChat.prototype.removeMembers = function (channelId, memberIds, options) {
1385
+ /**
1386
+ * Remove members from the private channel.
1387
+ *
1388
+ * @async
1389
+ * @function removeUsers
1390
+ * @param {string} channelId - An private channel id.
1391
+ * @param {string[]} userIds - An array of the member ids to be deleted.
1392
+ * @param {any} options
1393
+ * @returns {Promise<any>}
1394
+ */
1395
+ NCloudChat.prototype.removeUsers = function (channelId, userIds, options) {
949
1396
  return __awaiter(this, void 0, void 0, function () {
950
- var e_26;
1397
+ var result, e_28;
951
1398
  return __generator(this, function (_a) {
952
1399
  switch (_a.label) {
953
1400
  case 0:
954
- if (!this.isConnected()) {
955
- throw Error("You are not connected.");
956
- }
1401
+ this.inputValidation({
1402
+ channelId: channelId,
1403
+ userIds: userIds
1404
+ });
957
1405
  _a.label = 1;
958
1406
  case 1:
959
1407
  _a.trys.push([1, 3, , 4]);
960
- return [4 /*yield*/, removeChannelMembers(channelId, memberIds)];
961
- case 2: return [2 /*return*/, _a.sent()];
1408
+ return [4 /*yield*/, removeChannelMembers(channelId, userIds)];
1409
+ case 2:
1410
+ result = _a.sent();
1411
+ if (result["channel"]) {
1412
+ result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
1413
+ result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
1414
+ }
1415
+ return [2 /*return*/, result["channel"]];
962
1416
  case 3:
963
- e_26 = _a.sent();
964
- throw e_26;
1417
+ e_28 = _a.sent();
1418
+ throw e_28;
965
1419
  case 4: return [2 /*return*/];
966
1420
  }
967
1421
  });
968
1422
  });
969
1423
  };
1424
+ /**
1425
+ * Emit "start typing" to a conneted socket.
1426
+ *
1427
+ * @async
1428
+ * @function startTyping
1429
+ * @param {string} channelId - The id of a channel that the typing is happening.
1430
+ * @param {string} threadId - The id of a thread that the typing is happening.
1431
+ * @returns {Promise<any>}
1432
+ */
970
1433
  NCloudChat.prototype.startTyping = function (channelId, threadId) {
971
1434
  if (threadId === void 0) { threadId = ""; }
972
1435
  return __awaiter(this, void 0, void 0, function () {
973
1436
  var data;
974
1437
  return __generator(this, function (_a) {
975
- if (!this.isConnected()) {
1438
+ if (!this.isConnected())
976
1439
  throw Error("You are not connected.");
977
- }
1440
+ this.inputValidation({
1441
+ channelId: channelId,
1442
+ threadId: threadId
1443
+ });
978
1444
  try {
979
1445
  data = {
980
1446
  channelId: channelId,
981
1447
  threadId: threadId
982
1448
  };
983
- return [2 /*return*/, this.socket.emit("start typing", data)];
1449
+ this.socket.emit("start typing", data);
1450
+ return [2 /*return*/, data];
984
1451
  }
985
1452
  catch (e) {
986
1453
  throw e;
@@ -989,20 +1456,33 @@ var NCloudChat = /** @class */ (function () {
989
1456
  });
990
1457
  });
991
1458
  };
1459
+ /**
1460
+ * Emit "stop typing" to a connected socket.
1461
+ *
1462
+ * @async
1463
+ * @function
1464
+ * @param {string} channelId - The id of a channel that the typing is stopped.
1465
+ * @param {string} threadId - The id of a thread that the typing is stopped.
1466
+ * @returns {Promise<any>}
1467
+ */
992
1468
  NCloudChat.prototype.stopTyping = function (channelId, threadId) {
993
1469
  if (threadId === void 0) { threadId = ""; }
994
1470
  return __awaiter(this, void 0, void 0, function () {
995
1471
  var data;
996
1472
  return __generator(this, function (_a) {
997
- if (!this.isConnected()) {
1473
+ if (!this.isConnected())
998
1474
  throw Error("You are not connected.");
999
- }
1475
+ this.inputValidation({
1476
+ channelId: channelId,
1477
+ threadId: threadId
1478
+ });
1000
1479
  try {
1001
1480
  data = {
1002
1481
  channelId: channelId,
1003
1482
  threadId: threadId
1004
1483
  };
1005
- return [2 /*return*/, this.socket.emit("stop typing", data)];
1484
+ this.socket.emit("stop typing", data);
1485
+ return [2 /*return*/, data];
1006
1486
  }
1007
1487
  catch (e) {
1008
1488
  throw e;
@@ -1011,51 +1491,245 @@ var NCloudChat = /** @class */ (function () {
1011
1491
  });
1012
1492
  });
1013
1493
  };
1494
+ /**
1495
+ * Ban a member from a channel.
1496
+ *
1497
+ * @async
1498
+ * @function banUser
1499
+ * @param {string} channelId - The id of a channel.
1500
+ * @param {string} memberId - The id of a member.
1501
+ * @param {any} options
1502
+ * @returns {Promise<any>}
1503
+ */
1014
1504
  NCloudChat.prototype.banUser = function (channelId, memberId, options) {
1015
1505
  if (options === void 0) { options = {}; }
1016
1506
  return __awaiter(this, void 0, void 0, function () {
1017
- var e_27;
1507
+ var memberBlock, e_29;
1018
1508
  return __generator(this, function (_a) {
1019
1509
  switch (_a.label) {
1020
1510
  case 0:
1021
- if (!this.isConnected()) {
1022
- throw Error("You are not connected.");
1023
- }
1511
+ this.inputValidation({
1512
+ channelId: channelId,
1513
+ memberId: memberId
1514
+ });
1024
1515
  _a.label = 1;
1025
1516
  case 1:
1026
1517
  _a.trys.push([1, 3, , 4]);
1027
1518
  return [4 /*yield*/, createMemberBlock(channelId, memberId, JSON.stringify(options))];
1028
- case 2: return [2 /*return*/, _a.sent()];
1519
+ case 2:
1520
+ memberBlock = _a.sent();
1521
+ if (memberBlock["memberBlock"])
1522
+ memberBlock["memberBlock"]["id"] = this.ObjectId(memberBlock["memberBlock"]["id"]);
1523
+ return [2 /*return*/, memberBlock["memberBlock"]];
1029
1524
  case 3:
1030
- e_27 = _a.sent();
1031
- throw e_27;
1525
+ e_29 = _a.sent();
1526
+ throw e_29;
1032
1527
  case 4: return [2 /*return*/];
1033
1528
  }
1034
1529
  });
1035
1530
  });
1036
1531
  };
1532
+ /**
1533
+ * Unban a member from a channel.
1534
+ *
1535
+ * @async
1536
+ * @function unbanUser
1537
+ * @param {string} channelId - The id of a channel.
1538
+ * @param {string} memberId - The id of a member.
1539
+ * @returns {Promise<any>}
1540
+ */
1037
1541
  NCloudChat.prototype.unbanUser = function (channelId, memberId) {
1038
1542
  return __awaiter(this, void 0, void 0, function () {
1039
- var e_28;
1543
+ var memberBlock, e_30;
1040
1544
  return __generator(this, function (_a) {
1041
1545
  switch (_a.label) {
1042
1546
  case 0:
1043
- if (!this.isConnected()) {
1044
- throw Error("You are not connected.");
1045
- }
1547
+ this.inputValidation({
1548
+ channelId: channelId,
1549
+ memberId: memberId
1550
+ });
1046
1551
  _a.label = 1;
1047
1552
  case 1:
1048
1553
  _a.trys.push([1, 3, , 4]);
1049
1554
  return [4 /*yield*/, deleteMemberBlock(channelId, memberId)];
1050
- case 2: return [2 /*return*/, _a.sent()];
1555
+ case 2:
1556
+ memberBlock = _a.sent();
1557
+ if (memberBlock["memberBlock"])
1558
+ memberBlock["memberBlock"]["id"] = this.ObjectId(memberBlock["memberBlock"]["id"]);
1559
+ return [2 /*return*/, memberBlock["memberBlock"]];
1051
1560
  case 3:
1052
- e_28 = _a.sent();
1053
- throw e_28;
1561
+ e_30 = _a.sent();
1562
+ throw e_30;
1563
+ case 4: return [2 /*return*/];
1564
+ }
1565
+ });
1566
+ });
1567
+ };
1568
+ /**
1569
+ * Get data of a single pin from the endpoint.
1570
+ *
1571
+ * @async
1572
+ * @function getPin
1573
+ * @param {string} channelId - An id of the channel.
1574
+ * @param {string} id - An id of the pin.
1575
+ * @returns {Promise<any>} The data of the pin.
1576
+ */
1577
+ NCloudChat.prototype.getPin = function (channelId, id) {
1578
+ return __awaiter(this, void 0, void 0, function () {
1579
+ var result, e_31;
1580
+ return __generator(this, function (_a) {
1581
+ switch (_a.label) {
1582
+ case 0:
1583
+ this.inputValidation({ channelId: channelId, pinId: id });
1584
+ _a.label = 1;
1585
+ case 1:
1586
+ _a.trys.push([1, 3, , 4]);
1587
+ return [4 /*yield*/, getPin(channelId, id)];
1588
+ case 2:
1589
+ result = _a.sent();
1590
+ if (result) {
1591
+ result.id = this.ObjectId(result.id);
1592
+ if (result["user_id"]) {
1593
+ result["user_id"]["id"] = this.ObjectId(result["user_id"]["id"]);
1594
+ }
1595
+ }
1596
+ return [2 /*return*/, result];
1597
+ case 3:
1598
+ e_31 = _a.sent();
1599
+ throw e_31;
1600
+ case 4: return [2 /*return*/];
1601
+ }
1602
+ });
1603
+ });
1604
+ };
1605
+ /**
1606
+ * Get data of multiple pins.
1607
+ *
1608
+ * @async
1609
+ * @function getPins
1610
+ * @param {string} channelId - An id of the channel.
1611
+ * @param {string} filter - Field value for filter.
1612
+ * @param {string} sort - Field value for sorting.
1613
+ * @param {string} option - Optional option: ex) offset, per_page.
1614
+ * @returns {Promise<any[]>} An array of data of all channels.
1615
+ */
1616
+ NCloudChat.prototype.getPins = function (channelId, filter, sort, option) {
1617
+ if (sort === void 0) { sort = {}; }
1618
+ if (option === void 0) { option = {}; }
1619
+ return __awaiter(this, void 0, void 0, function () {
1620
+ var entries, channels, e_32;
1621
+ var _this = this;
1622
+ return __generator(this, function (_a) {
1623
+ switch (_a.label) {
1624
+ case 0:
1625
+ this.inputValidation({});
1626
+ _a.label = 1;
1627
+ case 1:
1628
+ _a.trys.push([1, 3, , 4]);
1629
+ return [4 /*yield*/, getPins(channelId, JSON.stringify(filter), JSON.stringify(sort), JSON.stringify(option))];
1630
+ case 2:
1631
+ entries = _a.sent();
1632
+ if (entries["edges"]) {
1633
+ channels = entries["edges"].map(function (item) {
1634
+ var _a, _b;
1635
+ if (item.node.user_id)
1636
+ item.node.user_id.id = _this.ObjectId((_b = (_a = item.node) === null || _a === void 0 ? void 0 : _a.user_id) === null || _b === void 0 ? void 0 : _b.id);
1637
+ return __assign(__assign({}, item.node), { id: _this.ObjectId(item.node.id) });
1638
+ });
1639
+ return [2 /*return*/, channels];
1640
+ }
1641
+ return [2 /*return*/, entries["edges"]];
1642
+ case 3:
1643
+ e_32 = _a.sent();
1644
+ throw e_32;
1054
1645
  case 4: return [2 /*return*/];
1055
1646
  }
1056
1647
  });
1057
1648
  });
1058
1649
  };
1650
+ /**
1651
+ * Create a new pin.
1652
+ *
1653
+ * @async
1654
+ * @function createPin
1655
+ * @param {string} channelId - An id of the channel.
1656
+ * @param {PinInput} pin - Configuration options of the new pin.
1657
+ * @returns {Promise<any>} The data of the newly created pin.
1658
+ */
1659
+ NCloudChat.prototype.createPin = function (channelId, pin) {
1660
+ return __awaiter(this, void 0, void 0, function () {
1661
+ var result, e_33;
1662
+ return __generator(this, function (_a) {
1663
+ switch (_a.label) {
1664
+ case 0:
1665
+ this.inputValidation({
1666
+ channelId: channelId,
1667
+ pinned: pin.pinned
1668
+ });
1669
+ _a.label = 1;
1670
+ case 1:
1671
+ _a.trys.push([1, 3, , 4]);
1672
+ return [4 /*yield*/, createPin(channelId, pin)];
1673
+ case 2:
1674
+ result = _a.sent();
1675
+ if (result["pin"]) {
1676
+ result["pin"]["id"] = this.ObjectId(result["pin"]["id"]);
1677
+ result["pin"]["user_id"]["id"] = this.ObjectId(result["pin"]["user_id"]["id"]);
1678
+ }
1679
+ return [2 /*return*/, result["pin"]];
1680
+ case 3:
1681
+ e_33 = _a.sent();
1682
+ throw e_33;
1683
+ case 4: return [2 /*return*/];
1684
+ }
1685
+ });
1686
+ });
1687
+ };
1688
+ /**
1689
+ * Update pin options.
1690
+ *
1691
+ * @async
1692
+ * @function updatePin
1693
+ * @param {string} channelId - An id of the channel.
1694
+ * @param {PinInput} pin - New options of the pin.
1695
+ * @returns {Promise<any>} The data of the updated pin.
1696
+ */
1697
+ NCloudChat.prototype.updatePin = function (pinId, channelId, pin) {
1698
+ return __awaiter(this, void 0, void 0, function () {
1699
+ var result, e_34;
1700
+ return __generator(this, function (_a) {
1701
+ switch (_a.label) {
1702
+ case 0:
1703
+ this.inputValidation({
1704
+ channelId: channelId,
1705
+ pinned: pin.pinned
1706
+ });
1707
+ _a.label = 1;
1708
+ case 1:
1709
+ _a.trys.push([1, 3, , 4]);
1710
+ return [4 /*yield*/, updatePin(pinId, channelId, pin)];
1711
+ case 2:
1712
+ result = _a.sent();
1713
+ if (result["pin"]) {
1714
+ result["pin"]["id"] = this.ObjectId(result["pin"]["id"]);
1715
+ result["pin"]["user_id"]["id"] = this.ObjectId(result["pin"]["user_id"]["id"]);
1716
+ }
1717
+ return [2 /*return*/, result["pin"]];
1718
+ case 3:
1719
+ e_34 = _a.sent();
1720
+ throw e_34;
1721
+ case 4: return [2 /*return*/];
1722
+ }
1723
+ });
1724
+ });
1725
+ };
1726
+ NCloudChat.prototype.getServerUrl = function () {
1727
+ return __awaiter(this, void 0, void 0, function () {
1728
+ return __generator(this, function (_a) {
1729
+ return [2 /*return*/, CoreManager.get("SERVER_URL")];
1730
+ });
1731
+ });
1732
+ };
1059
1733
  return NCloudChat;
1060
1734
  }());
1061
1735
  export default NCloudChat;