ncloudchat 1.0.23 → 1.0.31

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