@webex/internal-plugin-team 3.0.0-beta.9 → 3.0.0-beta.91

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webex/internal-plugin-team",
3
- "version": "3.0.0-beta.9",
3
+ "version": "3.0.0-beta.91",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "Josh Dykstra <jodykstr@cisco.com>",
@@ -21,19 +21,19 @@
21
21
  ]
22
22
  },
23
23
  "devDependencies": {
24
- "@webex/test-helper-chai": "3.0.0-beta.9",
25
- "@webex/test-helper-mocha": "3.0.0-beta.9",
26
- "@webex/test-helper-mock-webex": "3.0.0-beta.9",
27
- "@webex/test-helper-test-users": "3.0.0-beta.9",
24
+ "@webex/test-helper-chai": "3.0.0-beta.91",
25
+ "@webex/test-helper-mocha": "3.0.0-beta.91",
26
+ "@webex/test-helper-mock-webex": "3.0.0-beta.91",
27
+ "@webex/test-helper-test-users": "3.0.0-beta.91",
28
28
  "sinon": "^9.2.4"
29
29
  },
30
30
  "dependencies": {
31
- "@webex/internal-plugin-conversation": "3.0.0-beta.9",
32
- "@webex/internal-plugin-device": "3.0.0-beta.9",
33
- "@webex/internal-plugin-encryption": "3.0.0-beta.9",
34
- "@webex/internal-plugin-team": "3.0.0-beta.9",
35
- "@webex/internal-plugin-user": "3.0.0-beta.9",
36
- "@webex/webex-core": "3.0.0-beta.9",
31
+ "@webex/internal-plugin-conversation": "3.0.0-beta.91",
32
+ "@webex/internal-plugin-device": "3.0.0-beta.91",
33
+ "@webex/internal-plugin-encryption": "3.0.0-beta.91",
34
+ "@webex/internal-plugin-team": "3.0.0-beta.91",
35
+ "@webex/internal-plugin-user": "3.0.0-beta.91",
36
+ "@webex/webex-core": "3.0.0-beta.91",
37
37
  "lodash": "^4.17.21",
38
38
  "uuid": "^3.3.2"
39
39
  }
package/src/config.js CHANGED
@@ -3,5 +3,5 @@
3
3
  */
4
4
 
5
5
  export default {
6
- team: {}
6
+ team: {},
7
7
  };
package/src/index.js CHANGED
@@ -18,12 +18,15 @@ registerInternalPlugin('team', Team, {
18
18
  name: 'decryptTeamRoomStatus',
19
19
  direction: 'inbound',
20
20
  test(ctx, optionsOrResponse) {
21
- return Promise.resolve(has(optionsOrResponse, 'activity.object.activityEvent') && get(optionsOrResponse, 'activity.object.objectType') === 'teamRoomStatus');
21
+ return Promise.resolve(
22
+ has(optionsOrResponse, 'activity.object.activityEvent') &&
23
+ get(optionsOrResponse, 'activity.object.objectType') === 'teamRoomStatus'
24
+ );
22
25
  },
23
26
  extract(optionsOrResponse) {
24
27
  return Promise.resolve(optionsOrResponse.activity.object);
25
- }
26
- }
28
+ },
29
+ },
27
30
  ],
28
31
  transforms: [
29
32
  {
@@ -33,7 +36,11 @@ registerInternalPlugin('team', Team, {
33
36
  const promises = [];
34
37
 
35
38
  if (team.conversations.items) {
36
- promises.push(Promise.all(team.conversations.items.map((item) => ctx.transform('decryptObject', null, item))));
39
+ promises.push(
40
+ Promise.all(
41
+ team.conversations.items.map((item) => ctx.transform('decryptObject', null, item))
42
+ )
43
+ );
37
44
  }
38
45
 
39
46
  const usableKey = team.encryptionKeyUrl || key;
@@ -44,7 +51,7 @@ registerInternalPlugin('team', Team, {
44
51
  }
45
52
 
46
53
  return Promise.all(promises);
47
- }
54
+ },
48
55
  },
49
56
  {
50
57
  name: 'decryptTeamRoomStatus',
@@ -53,14 +60,14 @@ registerInternalPlugin('team', Team, {
53
60
  const keyUrl = get(teamRoomStatus, 'activityEvent.encryptionKeyUrl');
54
61
 
55
62
  return ctx.transform('decryptObject', keyUrl, teamRoomStatus.activityEvent);
56
- }
63
+ },
57
64
  },
58
65
  {
59
66
  name: 'decryptPropSummary',
60
67
  direction: 'inbound',
61
68
  fn(ctx, key, team) {
62
69
  return ctx.transform('decryptTextProp', 'summary', key, team);
63
- }
70
+ },
64
71
  },
65
72
  {
66
73
  name: 'encryptTeam',
@@ -70,36 +77,41 @@ registerInternalPlugin('team', Team, {
70
77
  return Promise.resolve();
71
78
  }
72
79
 
73
- return Promise.resolve(key || ctx.webex.internal.encryption.kms.createUnboundKeys({count: 1}))
74
- .then((keys) => {
75
- const k = isArray(keys) ? keys[0] : keys;
80
+ return Promise.resolve(
81
+ key || ctx.webex.internal.encryption.kms.createUnboundKeys({count: 1})
82
+ ).then((keys) => {
83
+ const k = isArray(keys) ? keys[0] : keys;
76
84
 
77
- if (team.kmsMessage && team.kmsMessage.keyUris && !team.kmsMessage.keyUris.includes(k.uri)) {
78
- team.kmsMessage.keyUris.push(k.uri);
79
- }
85
+ if (
86
+ team.kmsMessage &&
87
+ team.kmsMessage.keyUris &&
88
+ !team.kmsMessage.keyUris.includes(k.uri)
89
+ ) {
90
+ team.kmsMessage.keyUris.push(k.uri);
91
+ }
80
92
 
81
- return Promise.all([
82
- ctx.transform('encryptPropDisplayName', k, team),
83
- ctx.transform('encryptPropSummary', k, team)
84
- ])
85
- .then(() => {
86
- team.encryptionKeyUrl = k.uri || k;
93
+ return Promise.all([
94
+ ctx.transform('encryptPropDisplayName', k, team),
95
+ ctx.transform('encryptPropSummary', k, team),
96
+ ]).then(() => {
97
+ team.encryptionKeyUrl = k.uri || k;
87
98
 
88
- // we only want to set the defaultActivityEncryptionKeyUrl if we've
89
- // bound a new key
90
- if (!key) {
91
- team.defaultActivityEncryptionKeyUrl = team.defaultActivityEncryptionKeyUrl || k.uri || k;
92
- }
93
- });
99
+ // we only want to set the defaultActivityEncryptionKeyUrl if we've
100
+ // bound a new key
101
+ if (!key) {
102
+ team.defaultActivityEncryptionKeyUrl =
103
+ team.defaultActivityEncryptionKeyUrl || k.uri || k;
104
+ }
94
105
  });
95
- }
106
+ });
107
+ },
96
108
  },
97
109
  {
98
110
  name: 'encryptPropSummary',
99
111
  direction: 'outbound',
100
112
  fn(ctx, key, team) {
101
113
  return ctx.transform('encryptTextProp', 'summary', key, team);
102
- }
114
+ },
103
115
  },
104
116
  {
105
117
  name: 'normalizeTeam',
@@ -110,14 +122,18 @@ registerInternalPlugin('team', Team, {
110
122
  team.teamMembers.items = team.teamMembers.items || [];
111
123
 
112
124
  return Promise.all([
113
- Promise.all(team.conversations.items.map((item) => ctx.transform('normalizeObject', item))),
114
- Promise.all(team.teamMembers.items.map((item) => ctx.transform('normalizeObject', item)))
125
+ Promise.all(
126
+ team.conversations.items.map((item) => ctx.transform('normalizeObject', item))
127
+ ),
128
+ Promise.all(
129
+ team.teamMembers.items.map((item) => ctx.transform('normalizeObject', item))
130
+ ),
115
131
  ]);
116
- }
117
- }
118
- ]
132
+ },
133
+ },
134
+ ],
119
135
  },
120
- config
136
+ config,
121
137
  });
122
138
 
123
139
  export {default} from './team';
package/src/team.js CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  import querystring from 'querystring';
6
6
 
7
+ import uuid from 'uuid';
7
8
  import {find, pick, uniq} from 'lodash';
8
9
  import {WebexPlugin} from '@webex/webex-core';
9
10
 
@@ -21,20 +22,22 @@ const Team = WebexPlugin.extend({
21
22
  */
22
23
  addConversation(team, conversation, activity) {
23
24
  return this._ensureGeneralConversation(team)
24
- .then((generalConversation) => this.webex.internal.conversation.prepare(activity, {
25
- verb: 'add',
26
- target: this.webex.internal.conversation.prepareConversation(generalConversation),
27
- object: {
28
- id: conversation.id,
29
- objectType: 'conversation'
30
- },
31
- kmsMessage: {
32
- method: 'create',
33
- uri: '/authorizations',
34
- resourceUri: conversation.kmsResourceObjectUrl,
35
- userIds: [generalConversation.kmsResourceObjectUrl]
36
- }
37
- }))
25
+ .then((generalConversation) =>
26
+ this.webex.internal.conversation.prepare(activity, {
27
+ verb: 'add',
28
+ target: this.webex.internal.conversation.prepareConversation(generalConversation),
29
+ object: {
30
+ id: conversation.id,
31
+ objectType: 'conversation',
32
+ },
33
+ kmsMessage: {
34
+ method: 'create',
35
+ uri: '/authorizations',
36
+ resourceUri: conversation.kmsResourceObjectUrl,
37
+ userIds: [generalConversation.kmsResourceObjectUrl],
38
+ },
39
+ })
40
+ )
38
41
  .then((a) => this.webex.internal.conversation.submit(a));
39
42
  },
40
43
 
@@ -48,8 +51,9 @@ const Team = WebexPlugin.extend({
48
51
  * @returns {Promise} Resolves with activity that was posted
49
52
  */
50
53
  addMember(team, participant, activity) {
51
- return this._ensureGeneralConversation(team)
52
- .then((generalConversation) => this.webex.internal.conversation.add(generalConversation, participant, activity));
54
+ return this._ensureGeneralConversation(team).then((generalConversation) =>
55
+ this.webex.internal.conversation.add(generalConversation, participant, activity)
56
+ );
53
57
  },
54
58
 
55
59
  /**
@@ -69,18 +73,24 @@ const Team = WebexPlugin.extend({
69
73
  return Promise.reject(new Error('`params.participants` is required'));
70
74
  }
71
75
 
72
- return Promise.all(params.participants.map((participant) => this.webex.internal.user.asUUID(participant, {create: true})))
76
+ return Promise.all(
77
+ params.participants.map((participant) =>
78
+ this.webex.internal.user.asUUID(participant, {create: true})
79
+ )
80
+ )
73
81
  .then((participants) => {
74
82
  participants.unshift(this.webex.internal.device.userId);
75
83
  params.participants = uniq(participants);
76
84
  })
77
85
  .then(() => this._prepareTeam(params))
78
- .then((payload) => this.webex.request({
79
- method: 'POST',
80
- service: 'conversation',
81
- resource: 'teams',
82
- body: payload
83
- }))
86
+ .then((payload) =>
87
+ this.webex.request({
88
+ method: 'POST',
89
+ service: 'conversation',
90
+ resource: 'teams',
91
+ body: payload,
92
+ })
93
+ )
84
94
  .then((res) => res.body);
85
95
  },
86
96
 
@@ -106,18 +116,26 @@ const Team = WebexPlugin.extend({
106
116
  }
107
117
 
108
118
  return this._ensureGeneralConversation(team)
109
- .then((generalConversation) => Promise.all(params.participants.map((participant) => this.webex.internal.user.asUUID(participant, {create: true})))
110
- .then((participants) => {
111
- participants.unshift(this.webex.internal.device.userId);
112
- params.participants = uniq(participants);
119
+ .then((generalConversation) =>
120
+ Promise.all(
121
+ params.participants.map((participant) =>
122
+ this.webex.internal.user.asUUID(participant, {create: true})
123
+ )
124
+ )
125
+ .then((participants) => {
126
+ participants.unshift(this.webex.internal.device.userId);
127
+ params.participants = uniq(participants);
128
+ })
129
+ .then(() => this._prepareTeamConversation(generalConversation, params))
130
+ )
131
+ .then((payload) =>
132
+ this.webex.request({
133
+ method: 'POST',
134
+ uri: `${team.url}/conversations`,
135
+ qs: pick(options, 'includeAllTeamMembers'),
136
+ body: payload,
113
137
  })
114
- .then(() => this._prepareTeamConversation(generalConversation, params)))
115
- .then((payload) => this.webex.request({
116
- method: 'POST',
117
- uri: `${team.url}/conversations`,
118
- qs: pick(options, 'includeAllTeamMembers'),
119
- body: payload
120
- }))
138
+ )
121
139
  .then((res) => res.body);
122
140
  },
123
141
 
@@ -134,17 +152,18 @@ const Team = WebexPlugin.extend({
134
152
  if (!url) {
135
153
  return Promise.reject(new Error('`team.url` is required'));
136
154
  }
137
- const params = Object.assign({
155
+ const params = {
138
156
  includeTeamConversations: false,
139
- includeTeamMembers: false
140
- }, options);
141
-
142
- return this.webex.request({
143
- uri: url,
144
- qs: params
145
- })
146
- .then((res) => this._recordUUIDs(res.body)
147
- .then(() => res.body));
157
+ includeTeamMembers: false,
158
+ ...options,
159
+ };
160
+
161
+ return this.webex
162
+ .request({
163
+ uri: url,
164
+ qs: params,
165
+ })
166
+ .then((res) => this._recordUUIDs(res.body).then(() => res.body));
148
167
  },
149
168
 
150
169
  /**
@@ -158,9 +177,10 @@ const Team = WebexPlugin.extend({
158
177
  return Promise.reject(new Error('`team.url` is required'));
159
178
  }
160
179
 
161
- return this.webex.request({
162
- uri: `${url}/conversations`
163
- })
180
+ return this.webex
181
+ .request({
182
+ uri: `${url}/conversations`,
183
+ })
164
184
  .then((res) => res.body.items);
165
185
  },
166
186
 
@@ -168,13 +188,37 @@ const Team = WebexPlugin.extend({
168
188
  * Join a team conversation
169
189
  * @param {TeamObject} team
170
190
  * @param {ConversationObject} conversation
191
+ * @param {userId} userId
171
192
  * @returns {Promise} Resolves with the conversation
172
193
  */
173
- joinConversation(team, conversation) {
174
- return this.webex.request({
175
- method: 'POST',
176
- uri: `${team.url}/conversations/${conversation.id}/participants`
177
- })
194
+ joinConversation(team, conversation, userId) {
195
+ if (!userId) {
196
+ return Promise.reject(new Error('`userId` is required'));
197
+ }
198
+
199
+ const body = {
200
+ kmsMessage: {
201
+ client: {
202
+ clientId: this.webex.internal.device.url,
203
+ credential: {
204
+ bearer: this.webex.credentials.supertoken.access_token,
205
+ userId,
206
+ },
207
+ },
208
+ method: 'create',
209
+ requestId: uuid.v4(),
210
+ resourceUri: conversation.kmsResourceObjectUrl,
211
+ uri: '/authorizations',
212
+ userIds: [userId],
213
+ },
214
+ };
215
+
216
+ return this.webex
217
+ .request({
218
+ method: 'POST',
219
+ uri: `${team.url}/conversations/${conversation.id}/participants`,
220
+ body,
221
+ })
178
222
  .then((res) => res.body);
179
223
  },
180
224
 
@@ -186,16 +230,17 @@ const Team = WebexPlugin.extend({
186
230
  * @returns {Promise} Resolves with the requested teams
187
231
  */
188
232
  async list(options = {}) {
189
- const params = Object.assign({
233
+ const params = {
190
234
  includeTeamConversations: false,
191
- includeTeamMembers: false
192
- }, options);
235
+ includeTeamMembers: false,
236
+ ...options,
237
+ };
193
238
  const resource = 'teams';
194
239
 
195
240
  const res = await this.webex.request({
196
241
  api: 'conversation',
197
242
  resource,
198
- qs: params
243
+ qs: params,
199
244
  });
200
245
 
201
246
  let list = res.body.items.slice(0);
@@ -207,7 +252,7 @@ const Team = WebexPlugin.extend({
207
252
 
208
253
  return this.webex.request({
209
254
  uri,
210
- qs: params
255
+ qs: params,
211
256
  });
212
257
  })
213
258
  );
@@ -234,8 +279,9 @@ const Team = WebexPlugin.extend({
234
279
  * @returns {Promise} Resolves with activity that was posted
235
280
  */
236
281
  removeMember(team, participant, activity) {
237
- return this._ensureGeneralConversation(team)
238
- .then((generalConversation) => this.webex.internal.conversation.leave(generalConversation, participant, activity));
282
+ return this._ensureGeneralConversation(team).then((generalConversation) =>
283
+ this.webex.internal.conversation.leave(generalConversation, participant, activity)
284
+ );
239
285
  },
240
286
 
241
287
  /**
@@ -256,8 +302,8 @@ const Team = WebexPlugin.extend({
256
302
  target: pick(generalConversation, 'id', 'url', 'objectType'),
257
303
  kmsMessage: {
258
304
  method: 'delete',
259
- uri: `<KRO>/authorizations?${querystring.stringify({authId: conversation.id})}`
260
- }
305
+ uri: `<KRO>/authorizations?${querystring.stringify({authId: conversation.id})}`,
306
+ },
261
307
  };
262
308
 
263
309
  return this.webex.internal.conversation.prepare(activity, properties);
@@ -285,7 +331,9 @@ const Team = WebexPlugin.extend({
285
331
  }
286
332
 
287
333
  if (team.conversations.items.length) {
288
- const generalConversation = find(team.conversations.items, {id: team.generalConversationUuid});
334
+ const generalConversation = find(team.conversations.items, {
335
+ id: team.generalConversationUuid,
336
+ });
289
337
 
290
338
  if (generalConversation) {
291
339
  return Promise.resolve(generalConversation);
@@ -326,19 +374,21 @@ const Team = WebexPlugin.extend({
326
374
  return Promise.resolve(team);
327
375
  }
328
376
 
329
- return Promise.all(team.teamMembers.items.map((participant) => {
330
- // ROOMs or LYRA_SPACEs do not have email addresses, so there's no point attempting to
331
- // record their UUIDs.
332
- if (participant.type === 'ROOM' || participant.type === 'LYRA_SPACE') {
333
- return Promise.resolve();
334
- }
377
+ return Promise.all(
378
+ team.teamMembers.items.map((participant) => {
379
+ // ROOMs or LYRA_SPACEs do not have email addresses, so there's no point attempting to
380
+ // record their UUIDs.
381
+ if (participant.type === 'ROOM' || participant.type === 'LYRA_SPACE') {
382
+ return Promise.resolve();
383
+ }
335
384
 
336
- return this.webex.internal.user.recordUUID(participant)
337
- .catch((err) => this.logger.warn('Could not record uuid', err));
338
- }));
339
- }
385
+ return this.webex.internal.user
386
+ .recordUUID(participant)
387
+ .catch((err) => this.logger.warn('Could not record uuid', err));
388
+ })
389
+ );
390
+ },
340
391
  /* eslint-enable require-jsdoc */
341
-
342
392
  });
343
393
 
344
394
  /**
@@ -348,13 +398,11 @@ const Team = WebexPlugin.extend({
348
398
  * @param {Object} activity
349
399
  * @returns {Promise} Resolves with activity that was posted
350
400
  */
351
- [
352
- 'assignModerator',
353
- 'unassignModerator'
354
- ].forEach((verb) => {
401
+ ['assignModerator', 'unassignModerator'].forEach((verb) => {
355
402
  Team.prototype[verb] = function submitModerationChangeActivity(team, member, activity) {
356
- return this._ensureGeneralConversation(team)
357
- .then((teamConversation) => this.webex.internal.conversation[verb](teamConversation, member, activity));
403
+ return this._ensureGeneralConversation(team).then((teamConversation) =>
404
+ this.webex.internal.conversation[verb](teamConversation, member, activity)
405
+ );
358
406
  };
359
407
  });
360
408
 
@@ -366,10 +414,7 @@ const Team = WebexPlugin.extend({
366
414
  * provisional activity
367
415
  * @returns {Promise} Resolves with the posted activity
368
416
  */
369
- [
370
- 'archive',
371
- 'unarchive'
372
- ].forEach((verb) => {
417
+ ['archive', 'unarchive'].forEach((verb) => {
373
418
  Team.prototype[verb] = function submitArchiveStateChangeActivity(target, activity) {
374
419
  if (!target.objectType) {
375
420
  return Promise.reject(new Error('`target.objectType` is required'));
@@ -378,7 +423,7 @@ const Team = WebexPlugin.extend({
378
423
  const properties = {
379
424
  verb,
380
425
  object: pick(target, 'id', 'url', 'objectType'),
381
- target: pick(target, 'id', 'url', 'objectType')
426
+ target: pick(target, 'id', 'url', 'objectType'),
382
427
  };
383
428
 
384
429
  const teamUrl = this.webex.internal.conversation.getConvoUrl(target);