ncloudchat 0.0.24-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 login = function login(user_id, name, profile) {
166
+ var login = function login(user_id, name, profile, token) {
167
167
  if (name === void 0) {
168
168
  name = '';
169
169
  }
@@ -172,6 +172,10 @@ var login = function login(user_id, name, profile) {
172
172
  profile = '';
173
173
  }
174
174
 
175
+ if (token === void 0) {
176
+ token = '';
177
+ }
178
+
175
179
  return __awaiter(void 0, void 0, void 0, function () {
176
180
  var projectId, endpoint, mutation;
177
181
  return __generator(this, function (_a) {
@@ -179,12 +183,13 @@ var login = function login(user_id, name, profile) {
179
183
  case 0:
180
184
  projectId = _CoreManager["default"].get("PROJECT_ID");
181
185
  endpoint = _CoreManager["default"].get('SERVER_URL') + '/graphql';
182
- mutation = "mutation login ($projectId: String!, $userId: String!, $name: String, $profile: String) {\n login(input :{ projectId: $projectId, userId:$userId, name:$name, profile:$profile}) {\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 }";
183
187
  return [4
184
188
  /*yield*/
185
189
  , fetch(endpoint, {
186
190
  method: 'POST',
187
191
  headers: {
192
+ 'Authorization': 'Bearer ' + token,
188
193
  'Content-Type': 'application/json',
189
194
  'Accept': 'application/json'
190
195
  },
@@ -194,7 +199,8 @@ var login = function login(user_id, name, profile) {
194
199
  projectId: projectId,
195
200
  userId: user_id,
196
201
  name: name,
197
- profile: profile
202
+ profile: profile,
203
+ token: token
198
204
  }
199
205
  })
200
206
  }).then(function (res) {
@@ -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;
@@ -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.24-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"