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
@@ -1,29 +1,35 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
-
5
3
  var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
6
4
 
5
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
6
+
7
7
  _Object$defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
10
 
11
- exports.removeChannelMembers = exports.addChannelMembers = exports.deleteChannel = exports.updateChannel = exports.createChannel = void 0;
11
+ exports.updateChannel = exports.removeChannelMembers = exports.deleteChannel = exports.createChannel = exports.addChannelMembers = void 0;
12
12
 
13
- require("core-js/modules/es6.function.name");
13
+ require("core-js/modules/es6.function.name.js");
14
14
 
15
- var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
16
-
17
- var _iterator = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol/iterator"));
15
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
18
16
 
19
17
  var _symbol = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol"));
20
18
 
21
- var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
19
+ var _iterator = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol/iterator"));
22
20
 
23
21
  var _CoreManager = _interopRequireDefault(require("../CoreManager"));
24
22
 
25
- var _Util = require("../Util");
23
+ var _channel = require("../graphql/channel");
24
+
25
+ var _Network = require("../Network");
26
26
 
27
+ /**
28
+ * Copyright (c) NBASE CORP. and its affiliates.
29
+ *
30
+ * This source code is licensed under the MIT license found in the
31
+ * LICENSE file in the root directory of this source tree.
32
+ */
27
33
  var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
28
34
  function adopt(value) {
29
35
  return value instanceof P ? value : new P(function (resolve) {
@@ -167,108 +173,71 @@ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
167
173
  }
168
174
  };
169
175
 
176
+ /**
177
+ * Create a new channel.
178
+ *
179
+ * @async
180
+ * @function createChannel
181
+ * @param {ChannelInput} channel - Configuration options of the new channel.
182
+ * @returns {Promise<any>} The data of the newly created channel.
183
+ */
170
184
  var createChannel = function createChannel(channel) {
171
185
  return __awaiter(void 0, void 0, void 0, function () {
172
- var token, projectId, endpoint, query;
173
186
  return __generator(this, function (_a) {
174
- switch (_a.label) {
175
- case 0:
176
- token = _CoreManager["default"].get("TOKEN");
177
- projectId = _CoreManager["default"].get("PROJECT_ID");
178
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
179
- if (!channel.members) channel.members = [];
180
- query = "\n mutation (\n $id: String,\n $projectId: String!, \n $name: String!, \n $type: String!,\n $uniqueId: String,\n $translation: Boolean,\n $push: Boolean,\n $mutes: Boolean,\n $linkUrl: String,\n $imageUrl: String,\n $members: [String]\n ) {\n createChannel(\n input: { \n id: $id,\n projectId: $projectId, \n name: $name, \n type: $type,\n uniqueId: $uniqueId,\n translation:$translation,\n push:$push,\n mutes: $mutes,\n linkUrl:$linkUrl,\n imageUrl:$imageUrl\n members: $members,\n }\n ) {\n channel {\n id\n project_id\n name\n user_id { \n id\n name\n profile\n device_type\n language\n }\n last_message {\n message_id\n sort_id\n project_id\n channel_id\n message_type\n mentions\n mentions_everyone\n has\n sender {\n id\n name\n profile\n }\n admin {\n id\n name\n profile\n }\n content\n }\n unique_id\n type\n translation\n members\n push\n link_url\n image_url \n created_at\n updated_at\n }\n }\n } \n ";
181
- return [4
182
- /*yield*/
183
- , fetch(endpoint, {
184
- method: 'POST',
185
- headers: {
186
- 'Authorization': 'Bearer ' + token,
187
- 'X-PROJECT-ID': projectId,
188
- 'Content-Type': 'application/json',
189
- 'Accept': 'application/json'
190
- },
191
- body: (0, _stringify["default"])({
192
- query: query,
193
- variables: {
194
- projectId: projectId,
195
- name: channel.name,
196
- type: channel.type,
197
- uniqueId: channel.uniqueId,
198
- translation: channel.translation,
199
- push: channel.push,
200
- mutes: channel.mutes,
201
- linkUrl: channel.linkUrl,
202
- imageUrl: channel.imageUrl,
203
- disabled: channel.disabled,
204
- members: channel.members
205
- }
206
- })
207
- }).then(function (res) {
208
- return res.json();
209
- }).then(function (data) {
210
- if (data.errors) throw data.errors[0];
211
- if (data.code) throw data;
212
- if (data.data.createChannel.channel) data.data.createChannel.channel.id = (0, _Util.ObjectId)(data.data.createChannel.channel.id);
213
- return data.data.createChannel.channel;
214
- })];
215
-
216
- case 1:
217
- return [2
218
- /*return*/
219
- , _a.sent()];
220
- }
187
+ if (!channel.members) channel.members = [];
188
+ return [2
189
+ /*return*/
190
+ , (0, _Network.fetchData)("createChannel", _channel.createChannelQuery, {
191
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
192
+ name: channel.name,
193
+ type: channel.type,
194
+ uniqueId: channel.uniqueId,
195
+ translation: channel.translation,
196
+ push: channel.push,
197
+ mutes: channel.mutes,
198
+ customField: channel.customField,
199
+ linkUrl: channel.linkUrl,
200
+ imageUrl: channel.imageUrl,
201
+ disabled: channel.disabled,
202
+ members: channel.members
203
+ })];
221
204
  });
222
205
  });
223
206
  };
207
+ /**
208
+ * Update channel options.
209
+ *
210
+ * @async
211
+ * @function updateChannel
212
+ * @param {string} channelId - An id of the channel.
213
+ * @param {ChannelInput} channel - New options of the channel.
214
+ * @returns {Promise<any>} The data of the updated channel.
215
+ */
216
+
224
217
 
225
218
  exports.createChannel = createChannel;
226
219
 
227
220
  var updateChannel = function updateChannel(channelId, channel) {
228
221
  return __awaiter(void 0, void 0, void 0, function () {
229
- var token, projectId, endpoint, query;
230
222
  return __generator(this, function (_a) {
231
223
  switch (_a.label) {
232
224
  case 0:
233
- token = _CoreManager["default"].get("TOKEN");
234
- projectId = _CoreManager["default"].get("PROJECT_ID");
235
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
236
225
  if (!channel.members) channel.members = [];
237
- query = "\n mutation (\n $projectId: String!, \n $name: String!, \n $type: String!,\n $uniqueId: String,\n $translation: Boolean,\n $push: Boolean,\n $linkUrl: String,\n $imageUrl: String,\n $id: ID!,\n $members: [String]\n ) {\n updateChannel(\n input: { \n projectId: $projectId, \n name: $name, \n type: $type,\n id: $id,\n members: $members,\n uniqueId: $uniqueId,\n translation:$translation,\n push:$push,\n linkUrl:$linkUrl,\n imageUrl:$imageUrl\n }\n ) {\n channel {\n id\n project_id\n name\n user_id { \n id\n name\n profile\n device_type\n language\n }\n last_message {\n message_id\n sort_id\n project_id\n channel_id\n message_type\n mentions\n mentions_everyone\n has\n sender {\n id\n name\n profile\n }\n admin {\n id\n name\n profile\n }\n content\n }\n unique_id\n type\n translation\n members\n push\n link_url\n image_url \n created_at\n updated_at\n }\n }\n } \n ";
238
226
  return [4
239
227
  /*yield*/
240
- , fetch(endpoint, {
241
- method: 'POST',
242
- headers: {
243
- 'Authorization': 'Bearer ' + token,
244
- 'X-PROJECT-ID': projectId,
245
- 'Content-Type': 'application/json',
246
- 'Accept': 'application/json'
247
- },
248
- body: (0, _stringify["default"])({
249
- query: query,
250
- variables: {
251
- projectId: projectId,
252
- id: channelId,
253
- name: channel.name,
254
- type: channel.type,
255
- uniqueId: channel.uniqueId,
256
- translation: channel.translation,
257
- push: channel.push,
258
- mutes: channel.mutes,
259
- linkUrl: channel.linkUrl,
260
- imageUrl: channel.imageUrl,
261
- disabled: channel.disabled,
262
- members: channel.members
263
- }
264
- })
265
- }).then(function (res) {
266
- return res.json();
267
- }).then(function (data) {
268
- if (data.errors) throw data.errors[0];
269
- if (data.code) throw data;
270
- if (data.data.updateChannel.channel) data.data.updateChannel.channel.id = (0, _Util.ObjectId)(data.data.updateChannel.channel.id);
271
- return data.data.updateChannel.channel;
228
+ , (0, _Network.fetchData)("updateChannel", _channel.updateChannelQuery, {
229
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
230
+ id: channelId,
231
+ name: channel.name,
232
+ type: channel.type,
233
+ uniqueId: channel.uniqueId,
234
+ translation: channel.translation,
235
+ push: channel.push,
236
+ mutes: channel.mutes,
237
+ linkUrl: channel.linkUrl,
238
+ imageUrl: channel.imageUrl,
239
+ disabled: channel.disabled,
240
+ members: channel.members
272
241
  })];
273
242
 
274
243
  case 1:
@@ -279,43 +248,28 @@ var updateChannel = function updateChannel(channelId, channel) {
279
248
  });
280
249
  });
281
250
  };
251
+ /**
252
+ * Delete a channel.
253
+ *
254
+ * @async
255
+ * @function deleteChannel
256
+ * @param {string} channelId - An channel id.
257
+ * @returns {Promise<any>}
258
+ */
259
+
282
260
 
283
261
  exports.updateChannel = updateChannel;
284
262
 
285
263
  var deleteChannel = function deleteChannel(channelId) {
286
264
  return __awaiter(void 0, void 0, void 0, function () {
287
- var token, projectId, endpoint, query;
288
265
  return __generator(this, function (_a) {
289
266
  switch (_a.label) {
290
267
  case 0:
291
- token = _CoreManager["default"].get("TOKEN");
292
- projectId = _CoreManager["default"].get("PROJECT_ID");
293
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
294
- query = "\n mutation (\n $projectId: String!, \n $id: ID!\n ) {\n deleteChannel(\n input: { \n projectId: $projectId, \n id: $id,\n }\n ) {\n channel {\n id\n project_id\n name\n user_id { \n id\n name\n profile\n device_type\n language\n }\n last_message {\n message_id\n sort_id\n project_id\n channel_id\n message_type\n mentions\n mentions_everyone\n has\n sender {\n id\n name\n profile\n }\n admin {\n id\n name\n profile\n }\n content\n }\n unique_id\n type\n translation\n members\n push\n link_url\n image_url \n created_at\n updated_at\n }\n }\n } \n ";
295
268
  return [4
296
269
  /*yield*/
297
- , fetch(endpoint, {
298
- method: 'POST',
299
- headers: {
300
- 'Authorization': 'Bearer ' + token,
301
- 'X-PROJECT-ID': projectId,
302
- 'Content-Type': 'application/json',
303
- 'Accept': 'application/json'
304
- },
305
- body: (0, _stringify["default"])({
306
- query: query,
307
- variables: {
308
- projectId: projectId,
309
- id: channelId
310
- }
311
- })
312
- }).then(function (res) {
313
- return res.json();
314
- }).then(function (data) {
315
- if (data.errors) throw data.errors[0];
316
- if (data.code) throw data;
317
- if (data.data.deleteChannel.channel) data.data.deleteChannel.channel.id = (0, _Util.ObjectId)(data.data.deleteChannel.channel.id);
318
- return data.data.deleteChannel.channel;
270
+ , (0, _Network.fetchData)("deleteChannel", _channel.deleteChannelQuery, {
271
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
272
+ id: channelId
319
273
  })];
320
274
 
321
275
  case 1:
@@ -326,45 +280,32 @@ var deleteChannel = function deleteChannel(channelId) {
326
280
  });
327
281
  });
328
282
  };
283
+ /**
284
+ * Add members to the private channel.
285
+ *
286
+ * @async
287
+ * @function addChannelMembers
288
+ * @param {string} channelId - An private channel id.
289
+ * @param {string[]} memberIds - An array of member ids to be added.
290
+ * @param {any} options
291
+ * @returns {Promise<any>}
292
+ */
293
+
329
294
 
330
295
  exports.deleteChannel = deleteChannel;
331
296
 
332
297
  var addChannelMembers = function addChannelMembers(channelId, memberIds, options) {
333
298
  return __awaiter(void 0, void 0, void 0, function () {
334
- var token, projectId, endpoint, query;
335
299
  return __generator(this, function (_a) {
336
300
  switch (_a.label) {
337
301
  case 0:
338
- token = _CoreManager["default"].get("TOKEN");
339
- projectId = _CoreManager["default"].get("PROJECT_ID");
340
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
341
- query = "\n mutation ($projectId: String!, $channelId: String!, $memberIds: [String]!) {\n addChannelMembers(input: {projectId: $projectId, channelId: $channelId, memberIds:$memberIds }) {\n channel {\n id\n project_id\n name\n user_id { \n id\n name\n profile\n device_type\n language\n }\n unique_id\n type\n translation\n members\n push\n link_url\n image_url \n created_at\n updated_at\n }\n }\n }\n ";
342
302
  return [4
343
303
  /*yield*/
344
- , fetch(endpoint, {
345
- method: 'POST',
346
- headers: {
347
- 'Authorization': 'Bearer ' + token,
348
- 'X-PROJECT-ID': projectId,
349
- 'Content-Type': 'application/json',
350
- 'Accept': 'application/json'
351
- },
352
- body: (0, _stringify["default"])({
353
- query: query,
354
- variables: {
355
- projectId: projectId,
356
- channelId: channelId,
357
- memberIds: memberIds,
358
- options: options
359
- }
360
- })
361
- }).then(function (res) {
362
- return res.json();
363
- }).then(function (data) {
364
- if (data.errors) throw data.errors[0];
365
- if (data.code) throw data;
366
- if (data.data.addChannelMembers.channel) data.data.addChannelMembers.channel.id = (0, _Util.ObjectId)(data.data.addChannelMembers.channel.id);
367
- return data.data.addChannelMembers.channel;
304
+ , (0, _Network.fetchData)("addChannelMembers", _channel.addChannelMembersQuery, {
305
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
306
+ channelId: channelId,
307
+ memberIds: memberIds,
308
+ options: options
368
309
  })];
369
310
 
370
311
  case 1:
@@ -375,44 +316,30 @@ var addChannelMembers = function addChannelMembers(channelId, memberIds, options
375
316
  });
376
317
  });
377
318
  };
319
+ /**
320
+ * Remove members from the private channel.
321
+ *
322
+ * @async
323
+ * @function removeChannelMembers
324
+ * @param {string} channelId - An private channel id.
325
+ * @param {string[]} memberIds - An array of the member ids to be deleted.
326
+ * @returns {Promise<any>}
327
+ */
328
+
378
329
 
379
330
  exports.addChannelMembers = addChannelMembers;
380
331
 
381
332
  var removeChannelMembers = function removeChannelMembers(channelId, memberIds) {
382
333
  return __awaiter(void 0, void 0, void 0, function () {
383
- var token, projectId, endpoint, query;
384
334
  return __generator(this, function (_a) {
385
335
  switch (_a.label) {
386
336
  case 0:
387
- token = _CoreManager["default"].get("TOKEN");
388
- projectId = _CoreManager["default"].get("PROJECT_ID");
389
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
390
- query = "\n mutation ($projectId: String!, $channelId: String!, $memberIds: [String]!) {\n removeChannelMembers(input: {projectId: $projectId, channelId: $channelId, memberIds:$memberIds }) {\n channel {\n id\n project_id\n name\n user_id { \n id\n name\n profile\n device_type\n language\n }\n unique_id\n type\n translation\n members\n push\n link_url\n image_url \n created_at\n updated_at\n }\n }\n }\n ";
391
337
  return [4
392
338
  /*yield*/
393
- , fetch(endpoint, {
394
- method: 'POST',
395
- headers: {
396
- 'Authorization': 'Bearer ' + token,
397
- 'X-PROJECT-ID': projectId,
398
- 'Content-Type': 'application/json',
399
- 'Accept': 'application/json'
400
- },
401
- body: (0, _stringify["default"])({
402
- query: query,
403
- variables: {
404
- projectId: projectId,
405
- channelId: channelId,
406
- memberIds: memberIds
407
- }
408
- })
409
- }).then(function (res) {
410
- return res.json();
411
- }).then(function (data) {
412
- if (data.errors) throw data.errors[0];
413
- if (data.code) throw data;
414
- if (data.data.removeChannelMembers.channel) data.data.removeChannelMembers.channel.id = (0, _Util.ObjectId)(data.data.removeChannelMembers.channel.id);
415
- return data.data.removeChannelMembers.channel;
339
+ , (0, _Network.fetchData)("removeChannelMembers", _channel.removeChannelMembersQuery, {
340
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
341
+ channelId: channelId,
342
+ memberIds: memberIds
416
343
  })];
417
344
 
418
345
  case 1:
@@ -1,25 +1,33 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
-
5
3
  var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
6
4
 
5
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
6
+
7
7
  _Object$defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
10
 
11
- exports.removeFriend = exports.rejectFriend = exports.acceptFriend = exports.requestFriend = void 0;
12
-
13
- var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
11
+ exports.requestFriend = exports.removeFriend = exports.rejectFriend = exports.acceptFriend = void 0;
14
12
 
15
- var _iterator = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol/iterator"));
13
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
16
14
 
17
15
  var _symbol = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol"));
18
16
 
19
- var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
17
+ var _iterator = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol/iterator"));
20
18
 
21
19
  var _CoreManager = _interopRequireDefault(require("../CoreManager"));
22
20
 
21
+ var _friend = require("../graphql/friend");
22
+
23
+ var _Network = require("../Network");
24
+
25
+ /**
26
+ * Copyright (c) NBASE CORP. and its affiliates.
27
+ *
28
+ * This source code is licensed under the MIT license found in the
29
+ * LICENSE file in the root directory of this source tree.
30
+ */
23
31
  var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
24
32
  function adopt(value) {
25
33
  return value instanceof P ? value : new P(function (resolve) {
@@ -163,41 +171,24 @@ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
163
171
  }
164
172
  };
165
173
 
174
+ /**
175
+ * Request a friendship to a user.
176
+ *
177
+ * @async
178
+ * @function requestFriend
179
+ * @param {string} friendId - An id of the friend to request.
180
+ * @returns {Promise<any>}
181
+ */
166
182
  var requestFriend = function requestFriend(friendId) {
167
183
  return __awaiter(void 0, void 0, void 0, function () {
168
- var token, projectId, endpoint, query;
169
184
  return __generator(this, function (_a) {
170
185
  switch (_a.label) {
171
186
  case 0:
172
- token = _CoreManager["default"].get("TOKEN");
173
- projectId = _CoreManager["default"].get("PROJECT_ID");
174
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
175
- query = "\n mutation ($projectId: String!, $friendId: String!) {\n requestFriend(input: {projectId: $projectId, friendId: $friendId}) {\n friendship {\n project_id\n id\n status\n user {\n id\n name\n profile\n }\n friend {\n id\n name\n profile\n }\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n ";
176
187
  return [4
177
188
  /*yield*/
178
- , fetch(endpoint, {
179
- method: 'POST',
180
- headers: {
181
- 'Authorization': 'Bearer ' + token,
182
- 'X-PROJECT-ID': projectId,
183
- 'Content-Type': 'application/json',
184
- 'Accept': 'application/json'
185
- },
186
- body: (0, _stringify["default"])({
187
- query: query,
188
- variables: {
189
- projectId: projectId,
190
- friendId: friendId
191
- }
192
- })
193
- }).then(function (res) {
194
- return res.json();
195
- }).then(function (data) {
196
- if (data.errors) {
197
- throw data.errors[0];
198
- }
199
-
200
- return data.data.requestFriend.friendship;
189
+ , (0, _Network.fetchData)("requestFriend", _friend.requestFriendQuery, {
190
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
191
+ friendId: friendId
201
192
  })];
202
193
 
203
194
  case 1:
@@ -208,44 +199,28 @@ var requestFriend = function requestFriend(friendId) {
208
199
  });
209
200
  });
210
201
  };
202
+ /**
203
+ * Accept a friends request.
204
+ *
205
+ * @async
206
+ * @function acceptFriend
207
+ * @param {string} friendId - The id of the friend to accept the request.
208
+ * @returns {Promise<any>}
209
+ */
210
+
211
211
 
212
212
  exports.requestFriend = requestFriend;
213
213
 
214
214
  var acceptFriend = function acceptFriend(friendId) {
215
215
  return __awaiter(void 0, void 0, void 0, function () {
216
- var token, projectId, endpoint, query;
217
216
  return __generator(this, function (_a) {
218
217
  switch (_a.label) {
219
218
  case 0:
220
- token = _CoreManager["default"].get("TOKEN");
221
- projectId = _CoreManager["default"].get("PROJECT_ID");
222
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
223
- query = "\n mutation ($projectId: String!, $friendId: String!) {\n acceptFriend(input: {projectId: $projectId, friendId: $friendId}) {\n friendship {\n project_id\n id\n status\n user {\n id\n name\n profile\n }\n friend {\n id\n name\n profile\n }\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n ";
224
219
  return [4
225
220
  /*yield*/
226
- , fetch(endpoint, {
227
- method: 'POST',
228
- headers: {
229
- 'Authorization': 'Bearer ' + token,
230
- 'X-PROJECT-ID': projectId,
231
- 'Content-Type': 'application/json',
232
- 'Accept': 'application/json'
233
- },
234
- body: (0, _stringify["default"])({
235
- query: query,
236
- variables: {
237
- projectId: projectId,
238
- friendId: friendId
239
- }
240
- })
241
- }).then(function (res) {
242
- return res.json();
243
- }).then(function (data) {
244
- if (data.errors) {
245
- throw data.errors[0];
246
- }
247
-
248
- return data.data.acceptFriend.friendship;
221
+ , (0, _Network.fetchData)("acceptFriend", _friend.acceptFriendQuery, {
222
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
223
+ friendId: friendId
249
224
  })];
250
225
 
251
226
  case 1:
@@ -256,42 +231,28 @@ var acceptFriend = function acceptFriend(friendId) {
256
231
  });
257
232
  });
258
233
  };
234
+ /**
235
+ * Reject a friend request.
236
+ *
237
+ * @async
238
+ * @function rejectFriend
239
+ * @param {string} friendId - An id of the friend to be rejected.
240
+ * @returns {Promise<any>}
241
+ */
242
+
259
243
 
260
244
  exports.acceptFriend = acceptFriend;
261
245
 
262
246
  var rejectFriend = function rejectFriend(friendId) {
263
247
  return __awaiter(void 0, void 0, void 0, function () {
264
- var token, projectId, endpoint, query;
265
248
  return __generator(this, function (_a) {
266
249
  switch (_a.label) {
267
250
  case 0:
268
- token = _CoreManager["default"].get("TOKEN");
269
- projectId = _CoreManager["default"].get("PROJECT_ID");
270
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
271
- query = "\n mutation ($projectId: String!, $friendId: String!) {\n rejectFriend(input: {projectId: $projectId, friendId: $friendId}) {\n friendship {\n project_id\n id\n status\n user {\n id\n name\n profile\n }\n friend {\n id\n name\n profile\n }\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n ";
272
251
  return [4
273
252
  /*yield*/
274
- , fetch(endpoint, {
275
- method: 'POST',
276
- headers: {
277
- 'Authorization': 'Bearer ' + token,
278
- 'X-PROJECT-ID': projectId,
279
- 'Content-Type': 'application/json',
280
- 'Accept': 'application/json'
281
- },
282
- body: (0, _stringify["default"])({
283
- query: query,
284
- variables: {
285
- projectId: projectId,
286
- friendId: friendId
287
- }
288
- })
289
- }).then(function (res) {
290
- return res.json();
291
- }).then(function (data) {
292
- if (data.errors) throw data.errors[0];
293
- if (data.code) throw data;
294
- return data.data.rejectFriend.friendship;
253
+ , (0, _Network.fetchData)("rejectFriend", _friend.rejectFriendQuery, {
254
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
255
+ friendId: friendId
295
256
  })];
296
257
 
297
258
  case 1:
@@ -302,42 +263,28 @@ var rejectFriend = function rejectFriend(friendId) {
302
263
  });
303
264
  });
304
265
  };
266
+ /**
267
+ * Remove a friend.
268
+ *
269
+ * @async
270
+ * @function removeFriend
271
+ * @param {string} friendId - An id of the friend to be removed.
272
+ * @returns {Promise<any>}
273
+ */
274
+
305
275
 
306
276
  exports.rejectFriend = rejectFriend;
307
277
 
308
278
  var removeFriend = function removeFriend(friendId) {
309
279
  return __awaiter(void 0, void 0, void 0, function () {
310
- var token, projectId, endpoint, query;
311
280
  return __generator(this, function (_a) {
312
281
  switch (_a.label) {
313
282
  case 0:
314
- token = _CoreManager["default"].get("TOKEN");
315
- projectId = _CoreManager["default"].get("PROJECT_ID");
316
- endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
317
- query = "\n mutation ($projectId: String!, $friendId: String!) {\n removeFriend(input: {projectId: $projectId, friendId: $friendId}) {\n friendship {\n project_id\n id\n status\n user {\n id\n name\n profile\n }\n friend {\n id\n name\n profile\n }\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n ";
318
283
  return [4
319
284
  /*yield*/
320
- , fetch(endpoint, {
321
- method: 'POST',
322
- headers: {
323
- 'Authorization': 'Bearer ' + token,
324
- 'X-PROJECT-ID': projectId,
325
- 'Content-Type': 'application/json',
326
- 'Accept': 'application/json'
327
- },
328
- body: (0, _stringify["default"])({
329
- query: query,
330
- variables: {
331
- projectId: projectId,
332
- friendId: friendId
333
- }
334
- })
335
- }).then(function (res) {
336
- return res.json();
337
- }).then(function (data) {
338
- if (data.errors) throw data.errors[0];
339
- if (data.code) throw data;
340
- return data.data.removeFriend.friendship;
285
+ , (0, _Network.fetchData)("removeFriend", _friend.removeFriendQuery, {
286
+ projectId: _CoreManager["default"].get("PROJECT_ID"),
287
+ friendId: friendId
341
288
  })];
342
289
 
343
290
  case 1: