@webex/internal-plugin-conversation 3.0.0-beta.9 → 3.0.0-bnr.0

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 (57) hide show
  1. package/README.md +1 -3
  2. package/dist/activities.js +8 -69
  3. package/dist/activities.js.map +1 -1
  4. package/dist/activity-thread-ordering.js +19 -79
  5. package/dist/activity-thread-ordering.js.map +1 -1
  6. package/dist/config.js +1 -7
  7. package/dist/config.js.map +1 -1
  8. package/dist/constants.js +4 -5
  9. package/dist/constants.js.map +1 -1
  10. package/dist/conversation.js +790 -1199
  11. package/dist/conversation.js.map +1 -1
  12. package/dist/convo-error.js +0 -23
  13. package/dist/convo-error.js.map +1 -1
  14. package/dist/decryption-transforms.js +35 -98
  15. package/dist/decryption-transforms.js.map +1 -1
  16. package/dist/encryption-transforms.js +11 -48
  17. package/dist/encryption-transforms.js.map +1 -1
  18. package/dist/index.js +7 -50
  19. package/dist/index.js.map +1 -1
  20. package/dist/internal-plugin-conversation.d.ts +21 -0
  21. package/dist/share-activity.js +40 -106
  22. package/dist/share-activity.js.map +1 -1
  23. package/dist/to-array.js +9 -11
  24. package/dist/to-array.js.map +1 -1
  25. package/dist/tsdoc-metadata.json +11 -0
  26. package/dist/types/activities.d.ts +32 -0
  27. package/dist/types/activity-thread-ordering.d.ts +18 -0
  28. package/dist/types/config.d.ts +19 -0
  29. package/dist/types/constants.d.ts +5 -0
  30. package/dist/types/conversation.d.ts +2 -0
  31. package/dist/types/convo-error.d.ts +10 -0
  32. package/dist/types/decryption-transforms.d.ts +1 -0
  33. package/dist/types/encryption-transforms.d.ts +1 -0
  34. package/dist/types/index.d.ts +3 -0
  35. package/dist/types/share-activity.d.ts +7 -0
  36. package/dist/types/to-array.d.ts +9 -0
  37. package/package.json +15 -15
  38. package/src/activities.js +10 -7
  39. package/src/activity-thread-ordering.js +27 -30
  40. package/src/activity-threading.md +68 -49
  41. package/src/config.js +5 -5
  42. package/src/conversation.js +621 -589
  43. package/src/decryption-transforms.js +103 -62
  44. package/src/encryption-transforms.js +103 -83
  45. package/src/index.js +82 -66
  46. package/src/share-activity.js +64 -55
  47. package/src/to-array.js +2 -2
  48. package/test/integration/spec/create.js +184 -118
  49. package/test/integration/spec/encryption.js +250 -186
  50. package/test/integration/spec/get.js +761 -513
  51. package/test/integration/spec/mercury.js +37 -27
  52. package/test/integration/spec/share.js +292 -229
  53. package/test/integration/spec/verbs.js +628 -441
  54. package/test/unit/spec/conversation.js +265 -163
  55. package/test/unit/spec/decrypt-transforms.js +112 -131
  56. package/test/unit/spec/encryption-transforms.js +24 -18
  57. package/test/unit/spec/share-activity.js +37 -40
package/src/index.js CHANGED
@@ -25,7 +25,7 @@ registerInternalPlugin('conversation', Conversation, {
25
25
  },
26
26
  extract(optionsOrResponse) {
27
27
  return Promise.resolve(optionsOrResponse.body);
28
- }
28
+ },
29
29
  },
30
30
  {
31
31
  name: 'transformObject',
@@ -35,7 +35,7 @@ registerInternalPlugin('conversation', Conversation, {
35
35
  },
36
36
  extract(event) {
37
37
  return Promise.resolve(event.activity);
38
- }
38
+ },
39
39
  },
40
40
  {
41
41
  name: 'transformObjectArray',
@@ -44,8 +44,10 @@ registerInternalPlugin('conversation', Conversation, {
44
44
  return Promise.resolve(has(response, 'body.multistatus'));
45
45
  },
46
46
  extract(response) {
47
- return Promise.resolve(response.body.multistatus.map((item) => item && item.data && item.data.activity));
48
- }
47
+ return Promise.resolve(
48
+ response.body.multistatus.map((item) => item && item.data && item.data.activity)
49
+ );
50
+ },
49
51
  },
50
52
  {
51
53
  name: 'normalizeConversationListAndBindDecrypters',
@@ -63,7 +65,7 @@ registerInternalPlugin('conversation', Conversation, {
63
65
  },
64
66
  extract(options) {
65
67
  return Promise.resolve(options.body.items);
66
- }
68
+ },
67
69
  },
68
70
  {
69
71
  name: 'transformObjectArray',
@@ -81,7 +83,7 @@ registerInternalPlugin('conversation', Conversation, {
81
83
  },
82
84
  extract(options) {
83
85
  return Promise.resolve(options.body.items);
84
- }
86
+ },
85
87
  },
86
88
  {
87
89
  name: 'transformThreadArray',
@@ -99,36 +101,39 @@ registerInternalPlugin('conversation', Conversation, {
99
101
  },
100
102
  extract(options) {
101
103
  return Promise.resolve(options.body.items);
102
- }
103
- }
104
+ },
105
+ },
104
106
  ],
105
107
  transforms: [
106
108
  {
107
109
  name: 'normalizeConversationListAndBindDecrypters',
108
110
  fn(ctx, array) {
109
- return Promise.all(array.map((item) => ctx.transform('normalizeObject', item)
110
- .then(() => {
111
- item.decrypt = function decrypt() {
112
- Reflect.deleteProperty(item, 'decrypt');
111
+ return Promise.all(
112
+ array.map((item) =>
113
+ ctx.transform('normalizeObject', item).then(() => {
114
+ item.decrypt = function decrypt() {
115
+ Reflect.deleteProperty(item, 'decrypt');
113
116
 
114
- return ctx.transform('decryptObject', item);
115
- };
117
+ return ctx.transform('decryptObject', item);
118
+ };
116
119
 
117
- return item;
118
- })));
119
- }
120
+ return item;
121
+ })
122
+ )
123
+ );
124
+ },
120
125
  },
121
126
  {
122
127
  name: 'transformObjectArray',
123
128
  fn(ctx, array) {
124
129
  return Promise.all(array.map((item) => ctx.transform('transformObject', item)));
125
- }
130
+ },
126
131
  },
127
132
  {
128
133
  name: 'transformThreadArray',
129
134
  fn(ctx, array) {
130
135
  return Promise.all(array.map((item) => ctx.transform('transformThread', item)));
131
- }
136
+ },
132
137
  },
133
138
  {
134
139
  name: 'transformObject',
@@ -142,10 +147,11 @@ registerInternalPlugin('conversation', Conversation, {
142
147
  return Promise.resolve();
143
148
  }
144
149
 
145
- return ctx.transform('normalizeObject', object)
150
+ return ctx
151
+ .transform('normalizeObject', object)
146
152
  .then(() => ctx.transform('encryptObject', object))
147
153
  .then(() => ctx.transform('encryptKmsMessage', object));
148
- }
154
+ },
149
155
  },
150
156
  {
151
157
  name: 'transformObject',
@@ -159,9 +165,10 @@ registerInternalPlugin('conversation', Conversation, {
159
165
  return Promise.resolve();
160
166
  }
161
167
 
162
- return ctx.transform('decryptObject', object)
168
+ return ctx
169
+ .transform('decryptObject', object)
163
170
  .then(() => ctx.transform('normalizeObject', object));
164
- }
171
+ },
165
172
  },
166
173
  {
167
174
  name: 'normalizeObject',
@@ -176,9 +183,9 @@ registerInternalPlugin('conversation', Conversation, {
176
183
 
177
184
  return Promise.all([
178
185
  ctx.transform(`normalize${capitalize(object.objectType)}`, object),
179
- ctx.transform('normalizePropContent', object)
186
+ ctx.transform('normalizePropContent', object),
180
187
  ]);
181
- }
188
+ },
182
189
  },
183
190
  {
184
191
  name: 'transformThread',
@@ -188,9 +195,10 @@ registerInternalPlugin('conversation', Conversation, {
188
195
  return Promise.resolve();
189
196
  }
190
197
 
191
- return ctx.transform('decryptThread', object)
198
+ return ctx
199
+ .transform('decryptThread', object)
192
200
  .then(() => ctx.transform('normalizeThread', object));
193
- }
201
+ },
194
202
  },
195
203
  {
196
204
  name: 'normalizePropContent',
@@ -199,17 +207,18 @@ registerInternalPlugin('conversation', Conversation, {
199
207
  if (!object.content) {
200
208
  return Promise.resolve();
201
209
  }
202
- const {
203
- inboundProcessFunc,
204
- allowedInboundTags,
205
- allowedInboundStyles
206
- } = ctx.webex.config.conversation;
210
+ const {inboundProcessFunc, allowedInboundTags, allowedInboundStyles} =
211
+ ctx.webex.config.conversation;
207
212
 
208
- return htmlFilter(inboundProcessFunc, allowedInboundTags || {}, allowedInboundStyles, object.content)
209
- .then((c) => {
210
- object.content = c;
211
- });
212
- }
213
+ return htmlFilter(
214
+ inboundProcessFunc,
215
+ allowedInboundTags || {},
216
+ allowedInboundStyles,
217
+ object.content
218
+ ).then((c) => {
219
+ object.content = c;
220
+ });
221
+ },
213
222
  },
214
223
  {
215
224
  name: 'normalizePropContent',
@@ -219,17 +228,18 @@ registerInternalPlugin('conversation', Conversation, {
219
228
  return Promise.resolve();
220
229
  }
221
230
 
222
- const {
223
- outboundProcessFunc,
224
- allowedOutboundTags,
225
- allowedOutboundStyles
226
- } = ctx.webex.config.conversation;
231
+ const {outboundProcessFunc, allowedOutboundTags, allowedOutboundStyles} =
232
+ ctx.webex.config.conversation;
227
233
 
228
- return htmlFilterEscape(outboundProcessFunc, allowedOutboundTags || {}, allowedOutboundStyles, object.content)
229
- .then((c) => {
230
- object.content = c;
231
- });
232
- }
234
+ return htmlFilterEscape(
235
+ outboundProcessFunc,
236
+ allowedOutboundTags || {},
237
+ allowedOutboundStyles,
238
+ object.content
239
+ ).then((c) => {
240
+ object.content = c;
241
+ });
242
+ },
233
243
  },
234
244
  {
235
245
  name: 'normalizeConversation',
@@ -240,10 +250,14 @@ registerInternalPlugin('conversation', Conversation, {
240
250
  conversation.participants.items = conversation.participants.items || [];
241
251
 
242
252
  return Promise.all([
243
- Promise.all(conversation.activities.items.map((item) => ctx.transform('normalizeObject', item))),
244
- Promise.all(conversation.participants.items.map((item) => ctx.transform('normalizeObject', item)))
253
+ Promise.all(
254
+ conversation.activities.items.map((item) => ctx.transform('normalizeObject', item))
255
+ ),
256
+ Promise.all(
257
+ conversation.participants.items.map((item) => ctx.transform('normalizeObject', item))
258
+ ),
245
259
  ]);
246
- }
260
+ },
247
261
  },
248
262
  {
249
263
  name: 'normalizeActivity',
@@ -251,16 +265,18 @@ registerInternalPlugin('conversation', Conversation, {
251
265
  return Promise.all([
252
266
  ctx.transform('normalizeObject', activity.actor),
253
267
  ctx.transform('normalizeObject', activity.object),
254
- ctx.transform('normalizeObject', activity.target)
268
+ ctx.transform('normalizeObject', activity.target),
255
269
  ]);
256
- }
270
+ },
257
271
  },
258
272
  {
259
273
  name: 'normalizeThread',
260
274
  fn(ctx, threadActivity) {
261
275
  // childActivities are of type Activity
262
- return Promise.all(threadActivity.childActivities.map((item) => ctx.transform('normalizeObject', item)));
263
- }
276
+ return Promise.all(
277
+ threadActivity.childActivities.map((item) => ctx.transform('normalizeObject', item))
278
+ );
279
+ },
264
280
  },
265
281
  {
266
282
  name: 'normalizePerson',
@@ -271,8 +287,7 @@ registerInternalPlugin('conversation', Conversation, {
271
287
 
272
288
  if (patterns.email.test(email)) {
273
289
  person.entryEmail = person.emailAddress = email.toLowerCase();
274
- }
275
- else {
290
+ } else {
276
291
  Reflect.deleteProperty(person, 'entryEmail');
277
292
  Reflect.deleteProperty(person, 'emailAddress');
278
293
  }
@@ -288,22 +303,23 @@ registerInternalPlugin('conversation', Conversation, {
288
303
  }
289
304
 
290
305
  if (!email) {
291
- return Promise.reject(new Error('cannot determine id without an `emailAddress` or `entryUUID` property'));
306
+ return Promise.reject(
307
+ new Error('cannot determine id without an `emailAddress` or `entryUUID` property')
308
+ );
292
309
  }
293
310
 
294
- return ctx.webex.internal.user.asUUID(email)
295
- .then((uuid) => {
296
- person.entryUUID = person.id = uuid;
311
+ return ctx.webex.internal.user.asUUID(email).then((uuid) => {
312
+ person.entryUUID = person.id = uuid;
297
313
 
298
- return person;
299
- });
300
- }
301
- }
314
+ return person;
315
+ });
316
+ },
317
+ },
302
318
  ]
303
319
  .concat(decryptionTransforms)
304
- .concat(encryptionTransforms)
320
+ .concat(encryptionTransforms),
305
321
  },
306
- config
322
+ config,
307
323
  });
308
324
 
309
325
  export {default} from './conversation';
@@ -22,7 +22,7 @@ const ShareActivity = WebexPlugin.extend({
22
22
  getSymbols() {
23
23
  return {
24
24
  file: FILE_SYMBOL,
25
- emitter: EMITTER_SYMBOL
25
+ emitter: EMITTER_SYMBOL,
26
26
  };
27
27
  },
28
28
 
@@ -33,15 +33,15 @@ const ShareActivity = WebexPlugin.extend({
33
33
  deps: ['conversation'],
34
34
  fn() {
35
35
  return this.conversation;
36
- }
37
- }
36
+ },
37
+ },
38
38
  },
39
39
 
40
40
  session: {
41
41
  claimedFileType: 'string',
42
42
  conversation: {
43
43
  required: true,
44
- type: 'object'
44
+ type: 'object',
45
45
  },
46
46
 
47
47
  content: 'string',
@@ -52,7 +52,7 @@ const ShareActivity = WebexPlugin.extend({
52
52
 
53
53
  enableThumbnails: {
54
54
  default: true,
55
- type: 'boolean'
55
+ type: 'boolean',
56
56
  },
57
57
 
58
58
  hiddenSpaceUrl: 'object',
@@ -65,26 +65,30 @@ const ShareActivity = WebexPlugin.extend({
65
65
  type: 'object',
66
66
  default() {
67
67
  return new Map();
68
- }
69
- }
68
+ },
69
+ },
70
70
  },
71
71
 
72
72
  initialize(attrs, options) {
73
73
  Reflect.apply(WebexPlugin.prototype.initialize, this, [attrs, options]);
74
74
 
75
75
  if (attrs && attrs.conversation) {
76
- this.spaceUrl = Promise.resolve(attrs.conversation._spaceUrl || this._retrieveSpaceUrl(`${attrs.conversation.url}/space`)
77
- .then((url) => {
78
- attrs.conversation._spaceUrl = url;
79
-
80
- return url;
81
- }));
82
- this.hiddenSpaceUrl = Promise.resolve(attrs.conversation._hiddenSpaceUrl || this._retrieveSpaceUrl(`${attrs.conversation.url}/space/hidden`)
83
- .then((url) => {
84
- attrs.conversation._hiddenSpaceUrl = url;
85
-
86
- return url;
87
- }));
76
+ this.spaceUrl = Promise.resolve(
77
+ attrs.conversation._spaceUrl ||
78
+ this._retrieveSpaceUrl(`${attrs.conversation.url}/space`).then((url) => {
79
+ attrs.conversation._spaceUrl = url;
80
+
81
+ return url;
82
+ })
83
+ );
84
+ this.hiddenSpaceUrl = Promise.resolve(
85
+ attrs.conversation._hiddenSpaceUrl ||
86
+ this._retrieveSpaceUrl(`${attrs.conversation.url}/space/hidden`).then((url) => {
87
+ attrs.conversation._hiddenSpaceUrl = url;
88
+
89
+ return url;
90
+ })
91
+ );
88
92
  }
89
93
  },
90
94
 
@@ -105,7 +109,7 @@ const ShareActivity = WebexPlugin.extend({
105
109
  return Promise.resolve();
106
110
  }
107
111
 
108
- gifToAdd = Object.assign({
112
+ gifToAdd = {
109
113
  displayName: gif.name,
110
114
  fileSize: gif.size || gif.byteLength || gif.length,
111
115
  mimeType: gif.type,
@@ -116,10 +120,11 @@ const ShareActivity = WebexPlugin.extend({
116
120
  image: {
117
121
  height: gif.image.height,
118
122
  width: gif.image.width,
119
- url: 'https://giphy.com'
123
+ url: 'https://giphy.com',
120
124
  },
121
- [FILE_SYMBOL]: gif
122
- }, pick(options, 'actions'));
125
+ [FILE_SYMBOL]: gif,
126
+ ...pick(options, 'actions'),
127
+ };
123
128
 
124
129
  this.uploads.set(gif, gifToAdd);
125
130
 
@@ -151,7 +156,7 @@ const ShareActivity = WebexPlugin.extend({
151
156
  */
152
157
  add(file, options) {
153
158
  options = options || {};
154
- options.claimedFileType = file.displayName.substring(file.displayName.lastIndexOf('.'));
159
+ options.claimedFileType = file.name.substring(file.name.lastIndexOf('.'));
155
160
  let upload = this.uploads.get(file);
156
161
 
157
162
  if (upload) {
@@ -159,14 +164,15 @@ const ShareActivity = WebexPlugin.extend({
159
164
  }
160
165
  const emitter = new EventEmitter();
161
166
 
162
- upload = Object.assign({
167
+ upload = {
163
168
  displayName: file.name,
164
169
  fileSize: file.size || file.byteLength || file.length,
165
170
  mimeType: file.type,
166
171
  objectType: 'file',
167
172
  [EMITTER_SYMBOL]: emitter,
168
- [FILE_SYMBOL]: file
169
- }, pick(options, 'actions'));
173
+ [FILE_SYMBOL]: file,
174
+ ...pick(options, 'actions'),
175
+ };
170
176
 
171
177
  this.uploads.set(file, upload);
172
178
  const promise = detectFileType(file, this.logger)
@@ -179,11 +185,12 @@ const ShareActivity = WebexPlugin.extend({
179
185
  thumbnailMaxWidth: this.config.thumbnailMaxWidth,
180
186
  thumbnailMaxHeight: this.config.thumbnailMaxHeight,
181
187
  enableThumbnails: this.enableThumbnails,
182
- logger: this.logger
188
+ logger: this.logger,
183
189
  });
184
190
  })
185
191
  .then((imageData) => {
186
- const main = this.webex.internal.encryption.encryptBinary(file)
192
+ const main = this.webex.internal.encryption
193
+ .encryptBinary(file)
187
194
  .then(({scr, cdata}) => {
188
195
  upload.scr = scr;
189
196
 
@@ -200,7 +207,6 @@ const ShareActivity = WebexPlugin.extend({
200
207
  upload.url = upload.scr.loc = metadata.downloadUrl;
201
208
  });
202
209
 
203
-
204
210
  let thumb;
205
211
 
206
212
  if (imageData) {
@@ -210,7 +216,8 @@ const ShareActivity = WebexPlugin.extend({
210
216
 
211
217
  if (thumbnail && thumbnailDimensions) {
212
218
  upload.image = thumbnailDimensions;
213
- thumb = this.webex.internal.encryption.encryptBinary(thumbnail)
219
+ thumb = this.webex.internal.encryption
220
+ .encryptBinary(thumbnail)
214
221
  .then(({scr, cdata}) => {
215
222
  upload.image.scr = scr;
216
223
 
@@ -226,7 +233,6 @@ const ShareActivity = WebexPlugin.extend({
226
233
  return Promise.all([main, thumb]);
227
234
  });
228
235
 
229
-
230
236
  upload[PROMISE_SYMBOL] = promise;
231
237
 
232
238
  proxyEvents(emitter, promise);
@@ -248,7 +254,6 @@ const ShareActivity = WebexPlugin.extend({
248
254
  return files;
249
255
  },
250
256
 
251
-
252
257
  /**
253
258
  * @param {File} file
254
259
  * @param {string} uri
@@ -260,30 +265,30 @@ const ShareActivity = WebexPlugin.extend({
260
265
  const fileSize = file.length || file.size || file.byteLength;
261
266
  const fileHash = sha256(file).toString();
262
267
  const {role, claimedFileType} = uploadOptions ?? {};
263
- const initializeBody = Object.assign({fileSize}, {claimedFileType}, role && {role});
268
+ const initializeBody = {fileSize, claimedFileType, ...(role && {role})};
264
269
 
265
270
  return this.webex.upload({
266
271
  uri,
267
272
  file,
268
273
  qs: {
269
- transcode: true
274
+ transcode: true,
270
275
  },
271
276
  phases: {
272
277
  initialize: {
273
- body: initializeBody
278
+ body: initializeBody,
274
279
  },
275
280
  upload: {
276
281
  $url(session) {
277
282
  return session.uploadUrl;
278
- }
283
+ },
279
284
  },
280
285
  finalize: {
281
286
  $uri(session) {
282
287
  return session.finishUploadUrl;
283
288
  },
284
- body: {fileSize, fileHash}
285
- }
286
- }
289
+ body: {fileSize, fileHash},
290
+ },
291
+ },
287
292
  });
288
293
  },
289
294
 
@@ -317,10 +322,10 @@ const ShareActivity = WebexPlugin.extend({
317
322
  content: this.object && this.object.content ? this.object.content : undefined,
318
323
  mentions: this.object && this.object.mentions ? this.object.mentions : undefined,
319
324
  files: {
320
- items: []
321
- }
325
+ items: [],
326
+ },
322
327
  },
323
- clientTempId: this.clientTempId
328
+ clientTempId: this.clientTempId,
324
329
  };
325
330
 
326
331
  const promises = [];
@@ -332,8 +337,7 @@ const ShareActivity = WebexPlugin.extend({
332
337
 
333
338
  activity.object.contentCategory = this._determineContentCategory(activity.object.files.items);
334
339
 
335
- return Promise.all(promises)
336
- .then(() => activity);
340
+ return Promise.all(promises).then(() => activity);
337
341
  },
338
342
 
339
343
  /**
@@ -383,12 +387,13 @@ const ShareActivity = WebexPlugin.extend({
383
387
  * @returns {Promise}
384
388
  */
385
389
  _retrieveSpaceUrl(uri) {
386
- return this.webex.request({
387
- method: 'PUT',
388
- uri
389
- })
390
+ return this.webex
391
+ .request({
392
+ method: 'PUT',
393
+ uri,
394
+ })
390
395
  .then((res) => res.body.spaceUrl);
391
- }
396
+ },
392
397
  });
393
398
 
394
399
  /**
@@ -410,11 +415,15 @@ ShareActivity.create = function create(conversation, object, webex) {
410
415
  Reflect.deleteProperty(object.object, 'files');
411
416
  }
412
417
 
413
- const share = new ShareActivity(Object.assign({
414
- conversation
415
- }, object), {
416
- parent: webex
417
- });
418
+ const share = new ShareActivity(
419
+ {
420
+ conversation,
421
+ ...object,
422
+ },
423
+ {
424
+ parent: webex,
425
+ }
426
+ );
418
427
 
419
428
  files = files?.items ?? files;
420
429
  if (files) {
package/src/to-array.js CHANGED
@@ -20,10 +20,10 @@ export default function toArray(direction, obj) {
20
20
  return {
21
21
  name,
22
22
  direction,
23
- fn: entry
23
+ fn: entry,
24
24
  };
25
25
  }
26
26
 
27
- return Object.assign({name}, entry);
27
+ return {name, ...entry};
28
28
  });
29
29
  }