ncloudchat 0.0.22-beta → 0.0.25-beta

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.
@@ -8,7 +8,7 @@ _Object$defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
10
 
11
- exports.deleteFriend = exports.updateFriend = exports.rejectFriend = exports.acceptFriend = exports.createFriend = void 0;
11
+ exports.removeFriend = exports.rejectFriend = exports.acceptFriend = exports.requestFriend = void 0;
12
12
 
13
13
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
14
14
 
@@ -163,7 +163,7 @@ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
163
163
  }
164
164
  };
165
165
 
166
- var createFriend = function createFriend(channelId, friendIds) {
166
+ var requestFriend = function requestFriend(friendId) {
167
167
  return __awaiter(void 0, void 0, void 0, function () {
168
168
  var token, projectId, endpoint, query;
169
169
  return __generator(this, function (_a) {
@@ -172,7 +172,7 @@ var createFriend = function createFriend(channelId, friendIds) {
172
172
  token = _CoreManager["default"].get("TOKEN");
173
173
  projectId = _CoreManager["default"].get("PROJECT_ID");
174
174
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
175
- query = "\n mutation (\n $projectId: String!, \n $channelId: String!,\n $friendIds: String!\n ) {\n requestFriend(\n input: {\n projectId: $projectId, \n channelId: $channelId,\n friendIds: $friendIds\n }\n ) {\n friendship {\n id\n }\n }\n }\n ";
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 nickname\n profile\n }\n friend {\n id\n nickname\n profile\n }\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n ";
176
176
  return [4
177
177
  /*yield*/
178
178
  , fetch(endpoint, {
@@ -186,14 +186,17 @@ var createFriend = function createFriend(channelId, friendIds) {
186
186
  query: query,
187
187
  variables: {
188
188
  projectId: projectId,
189
- channelId: channelId,
190
- friendIds: friendIds
189
+ friendId: friendId
191
190
  }
192
191
  })
193
192
  }).then(function (res) {
194
193
  return res.json();
195
194
  }).then(function (data) {
196
- return data.data.createFriend.friendship;
195
+ if (data.errors) {
196
+ throw data.errors[0];
197
+ }
198
+
199
+ return data.data.requestFriend.friendship;
197
200
  })];
198
201
 
199
202
  case 1:
@@ -205,7 +208,7 @@ var createFriend = function createFriend(channelId, friendIds) {
205
208
  });
206
209
  };
207
210
 
208
- exports.createFriend = createFriend;
211
+ exports.requestFriend = requestFriend;
209
212
 
210
213
  var acceptFriend = function acceptFriend(friendId) {
211
214
  return __awaiter(void 0, void 0, void 0, function () {
@@ -216,7 +219,7 @@ var acceptFriend = function acceptFriend(friendId) {
216
219
  token = _CoreManager["default"].get("TOKEN");
217
220
  projectId = _CoreManager["default"].get("PROJECT_ID");
218
221
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
219
- query = "\n mutation (\n $projectId: String!, \n $friendId: String!\n ) {\n requestFriend(\n input: {\n projectId: $projectId, \n friendId: $friendId\n }\n ) {\n friendship {\n id\n }\n }\n }\n ";
222
+ 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 nickname\n profile\n }\n friend {\n id\n nickname\n profile\n }\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n ";
220
223
  return [4
221
224
  /*yield*/
222
225
  , fetch(endpoint, {
@@ -236,7 +239,11 @@ var acceptFriend = function acceptFriend(friendId) {
236
239
  }).then(function (res) {
237
240
  return res.json();
238
241
  }).then(function (data) {
239
- return data.data.createFriend.friendship;
242
+ if (data.errors) {
243
+ throw data.errors[0];
244
+ }
245
+
246
+ return data.data.acceptFriend.friendship;
240
247
  })];
241
248
 
242
249
  case 1:
@@ -250,7 +257,7 @@ var acceptFriend = function acceptFriend(friendId) {
250
257
 
251
258
  exports.acceptFriend = acceptFriend;
252
259
 
253
- var rejectFriend = function rejectFriend(channelId, friendIds) {
260
+ var rejectFriend = function rejectFriend(friendId) {
254
261
  return __awaiter(void 0, void 0, void 0, function () {
255
262
  var token, projectId, endpoint, query;
256
263
  return __generator(this, function (_a) {
@@ -259,7 +266,7 @@ var rejectFriend = function rejectFriend(channelId, friendIds) {
259
266
  token = _CoreManager["default"].get("TOKEN");
260
267
  projectId = _CoreManager["default"].get("PROJECT_ID");
261
268
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
262
- query = "\n mutation (\n $projectId: String!, \n $channelId: String!,\n $friendIds: String!\n ) {\n requestFriend(\n input: {\n projectId: $projectId, \n channelId: $channelId,\n friendIds: $friendIds\n }\n ) {\n friendship {\n id\n }\n }\n }\n ";
269
+ 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 nickname\n profile\n }\n friend {\n id\n nickname\n profile\n }\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n ";
263
270
  return [4
264
271
  /*yield*/
265
272
  , fetch(endpoint, {
@@ -273,14 +280,17 @@ var rejectFriend = function rejectFriend(channelId, friendIds) {
273
280
  query: query,
274
281
  variables: {
275
282
  projectId: projectId,
276
- channelId: channelId,
277
- friendIds: friendIds
283
+ friendId: friendId
278
284
  }
279
285
  })
280
286
  }).then(function (res) {
281
287
  return res.json();
282
288
  }).then(function (data) {
283
- return data.data.createFriend.friendship;
289
+ if (data.errors) {
290
+ throw data.errors[0];
291
+ }
292
+
293
+ return data.data.rejectFriend.friendship;
284
294
  })];
285
295
 
286
296
  case 1:
@@ -294,26 +304,49 @@ var rejectFriend = function rejectFriend(channelId, friendIds) {
294
304
 
295
305
  exports.rejectFriend = rejectFriend;
296
306
 
297
- var updateFriend = function updateFriend() {
307
+ var removeFriend = function removeFriend(friendId) {
298
308
  return __awaiter(void 0, void 0, void 0, function () {
309
+ var token, projectId, endpoint, query;
299
310
  return __generator(this, function (_a) {
300
- return [2
301
- /*return*/
302
- ];
303
- });
304
- });
305
- };
311
+ switch (_a.label) {
312
+ case 0:
313
+ token = _CoreManager["default"].get("TOKEN");
314
+ projectId = _CoreManager["default"].get("PROJECT_ID");
315
+ endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
316
+ 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 nickname\n profile\n }\n friend {\n id\n nickname\n profile\n }\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n ";
317
+ return [4
318
+ /*yield*/
319
+ , fetch(endpoint, {
320
+ method: 'POST',
321
+ headers: {
322
+ 'Authorization': 'Bearer ' + token,
323
+ 'Content-Type': 'application/json',
324
+ 'Accept': 'application/json'
325
+ },
326
+ body: (0, _stringify["default"])({
327
+ query: query,
328
+ variables: {
329
+ projectId: projectId,
330
+ friendId: friendId
331
+ }
332
+ })
333
+ }).then(function (res) {
334
+ return res.json();
335
+ }).then(function (data) {
336
+ if (data.errors) {
337
+ throw data.errors[0];
338
+ }
306
339
 
307
- exports.updateFriend = updateFriend;
340
+ return data.data.removeFriend.friendship;
341
+ })];
308
342
 
309
- var deleteFriend = function deleteFriend() {
310
- return __awaiter(void 0, void 0, void 0, function () {
311
- return __generator(this, function (_a) {
312
- return [2
313
- /*return*/
314
- ];
343
+ case 1:
344
+ return [2
345
+ /*return*/
346
+ , _a.sent()];
347
+ }
315
348
  });
316
349
  });
317
350
  };
318
351
 
319
- exports.deleteFriend = deleteFriend;
352
+ exports.removeFriend = removeFriend;
@@ -163,7 +163,7 @@ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
163
163
  }
164
164
  };
165
165
 
166
- var translate = function translate(source, target, message) {
166
+ var translate = function translate(channelId, srcLang, targetLang, text) {
167
167
  return __awaiter(void 0, void 0, void 0, function () {
168
168
  var token, projectId, endpoint, query;
169
169
  return __generator(this, function (_a) {
@@ -172,7 +172,7 @@ var translate = function translate(source, target, message) {
172
172
  token = _CoreManager["default"].get("TOKEN");
173
173
  projectId = _CoreManager["default"].get("PROJECT_ID");
174
174
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
175
- query = "\n mutation ($projectId: String!, $source: String, $target: String, $text: String!)) {\n translation(input: {projectId: $projectId, source: $source,\xA0target: $target,\xA0text: $text }) {\n result {\n status\n message\n }\n }\n }\n ";
175
+ query = "\n mutation ($projectId: String!, $channelId: String!, $srcLang: String!, $text: String!, $targetLang:String!) {\n translation(input: {projectId:$projectId, channelId:$channelId,srcLang:$srcLang,targetLang:$targetLang, text:$text }) {\n result\n {\n status\n message\n lang\n }\n }\n }\n ";
176
176
  return [4
177
177
  /*yield*/
178
178
  , fetch(endpoint, {
@@ -186,14 +186,19 @@ var translate = function translate(source, target, message) {
186
186
  query: query,
187
187
  variables: {
188
188
  projectId: projectId,
189
- source: source,
190
- target: target,
191
- message: message
189
+ channelId: channelId,
190
+ srcLang: srcLang,
191
+ targetLang: targetLang,
192
+ text: text
192
193
  }
193
194
  })
194
195
  }).then(function (res) {
195
- return console.log(res);
196
+ return res.json();
196
197
  }).then(function (data) {
198
+ if (data.errors) {
199
+ throw data.errors[0];
200
+ }
201
+
197
202
  return data;
198
203
  })];
199
204
 
@@ -240,6 +240,10 @@ var deleteSubscription = function deleteSubscription(channelId) {
240
240
  }).then(function (res) {
241
241
  return res.json();
242
242
  }).then(function (data) {
243
+ if (data.errors) {
244
+ throw data.errors[0];
245
+ }
246
+
243
247
  return data.data.deleteSubscription.subscription;
244
248
  })];
245
249
 
@@ -263,7 +267,7 @@ var updateSubscription = function updateSubscription(channelId, mark) {
263
267
  token = _CoreManager["default"].get("TOKEN");
264
268
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
265
269
  projectId = _CoreManager["default"].get('PROJECT_ID');
266
- query = "\n mutation ($projectId: String!, $channelId: String!, $mark: MarkInput) {\n updateSubscription(input: {projectId: $projectId,channelId: $channelId, mark: $mark}) {\n subscription {\n id\n channel_id\n user_id\n language\n push\n online\n uniquekey\n created_at\n updated_at\n }\n }\n }\n ";
270
+ query = "\n mutation ($projectId: String!, $channelId: String!, $mark: MarkInput) {\n updateSubscription(input: {projectId: $projectId,channelId: $channelId, mark: $mark}) {\n subscription {\n id\n channel_id\n user_id\n language\n push\n online\n uniquekey\n mark {\n user_id\n message_id\n sort_id\n unread\n }\n created_at\n updated_at\n }\n }\n }\n ";
267
271
  return [4
268
272
  /*yield*/
269
273
  , fetch(endpoint, {
@@ -284,7 +288,13 @@ var updateSubscription = function updateSubscription(channelId, mark) {
284
288
  }).then(function (res) {
285
289
  return res.json();
286
290
  }).then(function (data) {
287
- return data.data.deleteSubscription.subscription;
291
+ console.log(data);
292
+
293
+ if (data.errors) {
294
+ throw data.errors[0];
295
+ }
296
+
297
+ return data.data.updateSubscription.subscription;
288
298
  })];
289
299
 
290
300
  case 1:
@@ -163,7 +163,19 @@ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
163
163
  }
164
164
  };
165
165
 
166
- var login = function login(user_id) {
166
+ var login = function login(user_id, name, profile, token) {
167
+ if (name === void 0) {
168
+ name = '';
169
+ }
170
+
171
+ if (profile === void 0) {
172
+ profile = '';
173
+ }
174
+
175
+ if (token === void 0) {
176
+ token = '';
177
+ }
178
+
167
179
  return __awaiter(void 0, void 0, void 0, function () {
168
180
  var projectId, endpoint, mutation;
169
181
  return __generator(this, function (_a) {
@@ -171,12 +183,13 @@ var login = function login(user_id) {
171
183
  case 0:
172
184
  projectId = _CoreManager["default"].get("PROJECT_ID");
173
185
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
174
- mutation = "mutation login ($projectId: String!, $userId: String!) {\n login(input :{ projectId: $projectId, userId:$userId}) {\n token\n }\n }";
186
+ mutation = "mutation login ($projectId: String!, $userId: String!, $name: String, $profile: String, $token: String) {\n login(input :{ projectId: $projectId, userId:$userId, name:$name, profile:$profile, token:$token}) {\n token\n }\n }";
175
187
  return [4
176
188
  /*yield*/
177
189
  , fetch(endpoint, {
178
190
  method: 'POST',
179
191
  headers: {
192
+ 'Authorization': 'Bearer ' + token,
180
193
  'Content-Type': 'application/json',
181
194
  'Accept': 'application/json'
182
195
  },
@@ -184,7 +197,10 @@ var login = function login(user_id) {
184
197
  query: mutation,
185
198
  variables: {
186
199
  projectId: projectId,
187
- userId: user_id
200
+ userId: user_id,
201
+ name: name,
202
+ profile: profile,
203
+ token: token
188
204
  }
189
205
  })
190
206
  }).then(function (res) {
@@ -180,7 +180,7 @@ var getChannel = function getChannel(id) {
180
180
  /*return*/
181
181
  , null];
182
182
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
183
- query = "\n query channel ($projectId: String!, $id: String!) {\n channel(projectId: $projectId, id:$id) {\n id\n project_id\n name\n user_id\n unique_id\n is_private\n translation\n members\n push\n link_url\n image_url \n created_at\n updated_at\n }\n }\n ";
183
+ query = "\n query channel ($projectId: String!, $id: String!) {\n channel(projectId: $projectId, id:$id) {\n id\n project_id\n name\n user_id\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 ";
184
184
  return [4
185
185
  /*yield*/
186
186
  , fetch(endpoint, {
@@ -234,7 +234,7 @@ var getChannels = function getChannels(filter, sort, option) {
234
234
  /*return*/
235
235
  , null];
236
236
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
237
- query = "\n query channels ($projectId: String!, $filter: String!, $sort: String, $option:String) {\n channels(projectId: $projectId, filter:$filter, sort:$sort, option:$option) {\n totalCount\n edges {\n node {\n id\n project_id\n name\n user_id\n unique_id\n is_private\n translation\n members\n push\n link_url\n image_url \n created_at\n updated_at\n }\n }\n }\n }\n ";
237
+ query = "\n query channels ($projectId: String!, $filter: String!, $sort: String, $option:String) {\n channels(projectId: $projectId, filter:$filter, sort:$sort, option:$option) {\n totalCount\n edges {\n node {\n id\n project_id\n name\n user_id\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 }\n ";
238
238
  return [4
239
239
  /*yield*/
240
240
  , fetch(endpoint, {
@@ -8,7 +8,7 @@ _Object$defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
10
 
11
- exports.getFriends = void 0;
11
+ exports.getFriendships = void 0;
12
12
 
13
13
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
14
14
 
@@ -163,7 +163,7 @@ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
163
163
  }
164
164
  };
165
165
 
166
- var getFriends = function getFriends(offset, per_page, search, query) {
166
+ var getFriendships = function getFriendships(filter, sort, option) {
167
167
  return __awaiter(void 0, void 0, void 0, function () {
168
168
  var token, projectId, endpoint, lquery;
169
169
  return __generator(this, function (_a) {
@@ -178,7 +178,7 @@ var getFriends = function getFriends(offset, per_page, search, query) {
178
178
  /*return*/
179
179
  , null];
180
180
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
181
- lquery = "\n query friends ($projectId: String!, $offset: Int!, $per_page: Int!, $search:String, $query:String) {\n friends(projectId: $projectId, offset:$offset, per_page:$per_page, search:$search, query:$query) {\n totalCount\n edges {\n node {\n project_id\n id\n created_at\n updated_at\n }\n }\n }\n }\n ";
181
+ lquery = "\n query friendships ($projectId: String!, $filter: String!, $sort: String, $option: String) {\n friendships(projectId: $projectId, filter:$filter, sort:$sort, option: $option) {\n totalCount\n edges {\n node {\n project_id\n id\n status\n user {\n id\n nickname\n profile\n }\n friend {\n id\n nickname\n profile\n }\n user_id\n friend_id\n created_at\n updated_at\n requested_at\n }\n }\n }\n }\n ";
182
182
  return [4
183
183
  /*yield*/
184
184
  , fetch(endpoint, {
@@ -192,17 +192,16 @@ var getFriends = function getFriends(offset, per_page, search, query) {
192
192
  query: lquery,
193
193
  variables: {
194
194
  projectId: projectId,
195
- offset: offset,
196
- per_page: per_page,
197
- search: search === "" ? undefined : search,
198
- query: query === "" ? undefined : query
195
+ filter: filter,
196
+ sort: sort,
197
+ option: option
199
198
  }
200
199
  })
201
200
  }).then(function (res) {
202
201
  return res.json();
203
202
  }).then(function (data) {
204
- if (data.data.channels) {
205
- return data.data.channels.edges;
203
+ if (data.data.friendships) {
204
+ return data.data.friendships.edges;
206
205
  }
207
206
 
208
207
  return [];
@@ -217,4 +216,4 @@ var getFriends = function getFriends(offset, per_page, search, query) {
217
216
  });
218
217
  };
219
218
 
220
- exports.getFriends = getFriends;
219
+ exports.getFriendships = getFriendships;
@@ -180,7 +180,7 @@ var getSubscription = function getSubscription(channelId, id) {
180
180
  /*return*/
181
181
  , null];
182
182
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
183
- query = "\n query subscription ($projectId: String!,$channelId: String!, $id: String!) {\n subscription(projectId: $projectId, channelId: $channelUd, id:$id) {\n id\n user {\n nickname\n profile_url\n country\n }\n mark {\n user_id\n message_id\n sort_id\n }\n channel_id\n user_id\n online\n push\n created_at\n }\n }\n ";
183
+ query = "\n query subscription ($projectId: String!,$channelId: String!, $id: String!) {\n subscription(projectId: $projectId, channelId: $channelUd, id:$id) {\n id\n user {\n nickname\n profile\n country\n }\n mark {\n user_id\n message_id\n sort_id\n }\n channel_id\n user_id\n online\n push\n created_at\n }\n }\n ";
184
184
  return [4
185
185
  /*yield*/
186
186
  , fetch(endpoint, {
@@ -230,7 +230,7 @@ var getSubscriptions = function getSubscriptions(filter, sort, option) {
230
230
  /*return*/
231
231
  , null];
232
232
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
233
- query = "\n query subscriptions ($projectId: String!, $option: String!, $filter: String!, $sort: String ) {\n subscriptions (projectId: $projectId, option:$option, filter:$filter, sort:$sort) {\n totalCount\n edges {\n node {\n id\n user {\n nickname\n profile_url\n country\n }\n channel_id\n user_id\n online\n push\n created_at\n }\n }\n }\n }\n ";
233
+ query = "\n query subscriptions ($projectId: String!, $option: String!, $filter: String!, $sort: String ) {\n subscriptions (projectId: $projectId, option:$option, filter:$filter, sort:$sort) {\n totalCount\n edges {\n node {\n id\n user {\n nickname\n profile\n country\n }\n channel_id\n user_id\n online\n push\n created_at\n }\n }\n }\n }\n ";
234
234
  return [4
235
235
  /*yield*/
236
236
  , fetch(endpoint, {
@@ -26,12 +26,11 @@ chat.initialize(projectId);
26
26
  - 초기화가 완료되면 사용자명, 이름, 프로필 이미지주소(옵션) 을 입력 후에 접속해야 합니다.
27
27
 
28
28
  ```javascript
29
- chat.setUser({
29
+ const user = await chat.connect({
30
30
  id: USERNAME,
31
31
  name: NAME,
32
32
  profile: PROFILE_URL
33
- });
34
- const user = await chat.connect(user_id);
33
+ }, TOKEN);
35
34
  ```
36
35
 
37
36
  | ID | type | desc |
@@ -39,7 +38,7 @@ const user = await chat.connect(user_id);
39
38
  | USERNAME | string | 아이디 |
40
39
  | NAME | string | 이름 |
41
40
  | PROFILE_URL | string | 프로필 주소 |
42
-
41
+ | TOKEN | string | 토큰 값 |
43
42
 
44
43
 
45
44
  ### 3. Disconnect from NCloud Chat Server
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ncloudchat",
3
3
  "jsName": "ncloudchat",
4
- "version": "0.0.22-beta",
4
+ "version": "0.0.25-beta",
5
5
  "private": false,
6
6
  "description": "",
7
7
  "keywords": [
@@ -22,7 +22,8 @@
22
22
  "start": "npm run lint && webpack-dev-server --open --config webpack.dev.js",
23
23
  "lint": "tsc --noEmit && eslint --ext .ts",
24
24
  "server": "node test/server.js",
25
- "publish-dev": "aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp dist/ncloudchat.min.js s3://ncloudchat/dev/ --acl public-read"
25
+ "publish-dev": "aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp dist/ncloudchat.min.js s3://ncloudchat/dev/ --acl public-read",
26
+ "publish": "aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp dist/ncloudchat.min.js s3://ncloudchat/ --acl public-read"
26
27
  },
27
28
  "repository": {
28
29
  "type": "git"