@atlaskit/collab-provider 7.7.0 → 8.0.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 (36) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/analytics/index.js +17 -27
  3. package/dist/cjs/analytics/performance.js +0 -2
  4. package/dist/cjs/channel.js +74 -35
  5. package/dist/cjs/helpers/const.js +10 -1
  6. package/dist/cjs/provider/catchup.js +2 -2
  7. package/dist/cjs/provider/index.js +174 -65
  8. package/dist/cjs/types.js +10 -1
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/cjs/version.json +1 -1
  11. package/dist/es2019/analytics/index.js +15 -22
  12. package/dist/es2019/analytics/performance.js +0 -2
  13. package/dist/es2019/channel.js +28 -10
  14. package/dist/es2019/helpers/const.js +8 -0
  15. package/dist/es2019/provider/catchup.js +2 -2
  16. package/dist/es2019/provider/index.js +165 -65
  17. package/dist/es2019/types.js +7 -1
  18. package/dist/es2019/version-wrapper.js +1 -1
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/esm/analytics/index.js +15 -22
  21. package/dist/esm/analytics/performance.js +0 -2
  22. package/dist/esm/channel.js +75 -36
  23. package/dist/esm/helpers/const.js +8 -0
  24. package/dist/esm/provider/catchup.js +2 -2
  25. package/dist/esm/provider/index.js +175 -69
  26. package/dist/esm/types.js +7 -1
  27. package/dist/esm/version-wrapper.js +1 -1
  28. package/dist/esm/version.json +1 -1
  29. package/dist/types/analytics/index.d.ts +1 -3
  30. package/dist/types/analytics/performance.d.ts +0 -2
  31. package/dist/types/channel.d.ts +2 -1
  32. package/dist/types/helpers/const.d.ts +30 -2
  33. package/dist/types/provider/index.d.ts +10 -6
  34. package/dist/types/types.d.ts +32 -12
  35. package/package.json +9 -6
  36. package/report.api.md +13 -9
@@ -22,8 +22,9 @@ import { Emitter } from './emitter';
22
22
  import { ErrorCodeMapper } from './error-code-mapper';
23
23
  import { createLogger, getProduct, getSubProduct } from './helpers/utils';
24
24
  import { MEASURE_NAME, startMeasure, stopMeasure } from './analytics/performance';
25
- import { triggerCollabAnalyticsEvent } from './analytics';
25
+ import { triggerAnalyticsEvent } from './analytics';
26
26
  import { EVENT_ACTION, EVENT_STATUS } from './helpers/const';
27
+ import { ExperiencePerformanceTypes, ExperienceTypes, UFOExperience } from '@atlaskit/ufo';
27
28
  var logger = createLogger('Channel', 'green');
28
29
  export var Channel = /*#__PURE__*/function (_Emitter) {
29
30
  _inherits(Channel, _Emitter);
@@ -43,6 +44,16 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
43
44
 
44
45
  _defineProperty(_assertThisInitialized(_this), "initialized", false);
45
46
 
47
+ _defineProperty(_assertThisInitialized(_this), "initExperience", new UFOExperience('collab-provider.document-init', {
48
+ type: ExperienceTypes.Load,
49
+ performanceType: ExperiencePerformanceTypes.Custom,
50
+ performanceConfig: {
51
+ histogram: _defineProperty({}, ExperiencePerformanceTypes.Custom, {
52
+ duration: '250_500_1000_1500_2000_3000_4000'
53
+ })
54
+ }
55
+ }));
56
+
46
57
  _defineProperty(_assertThisInitialized(_this), "getInitialized", function () {
47
58
  return _this.initialized;
48
59
  });
@@ -59,7 +70,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
59
70
  _this.connected = true;
60
71
  logger('Connected.', _this.socket.id);
61
72
  var measure = stopMeasure(MEASURE_NAME.SOCKET_CONNECT);
62
- triggerCollabAnalyticsEvent({
73
+ triggerAnalyticsEvent({
63
74
  eventAction: EVENT_ACTION.CONNECTION,
64
75
  attributes: {
65
76
  eventStatus: EVENT_STATUS.SUCCESS,
@@ -81,7 +92,10 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
81
92
  if (data.type === 'initial') {
82
93
  if (!_this.initialized) {
83
94
  var measure = stopMeasure(MEASURE_NAME.DOCUMENT_INIT);
84
- triggerCollabAnalyticsEvent({
95
+
96
+ _this.initExperience.success();
97
+
98
+ triggerAnalyticsEvent({
85
99
  eventAction: EVENT_ACTION.DOCUMENT_INIT,
86
100
  attributes: {
87
101
  eventStatus: EVENT_STATUS.SUCCESS,
@@ -144,6 +158,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
144
158
 
145
159
  if (!this.initialized) {
146
160
  startMeasure(MEASURE_NAME.DOCUMENT_INIT);
161
+ this.initExperience.start();
147
162
  }
148
163
 
149
164
  var _this$config = this.config,
@@ -156,14 +171,14 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
156
171
  if (permissionTokenRefresh) {
157
172
  authCb = function authCb(cb) {
158
173
  permissionTokenRefresh().then(function (token) {
159
- cb({
160
- // The permission token.
161
- token: token,
174
+ cb(_objectSpread(_objectSpread({}, token ? {
175
+ token: token
176
+ } : {}), {}, {
162
177
  // The initialized status. If false, BE will send document, otherwise not.
163
178
  initialized: _this2.initialized,
164
179
  // ESS-1009 Allow to opt-in into 404 response
165
180
  need404: _this2.config.need404
166
- });
181
+ }));
167
182
  }).catch(function (err) {
168
183
  _this2.emit('error', err);
169
184
  });
@@ -257,7 +272,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
257
272
 
258
273
  this.socket.on('connect_error', function (error) {
259
274
  var measure = stopMeasure(MEASURE_NAME.SOCKET_CONNECT);
260
- triggerCollabAnalyticsEvent({
275
+ triggerAnalyticsEvent({
261
276
  eventAction: EVENT_ACTION.CONNECTION,
262
277
  attributes: {
263
278
  eventStatus: EVENT_STATUS.FAILURE,
@@ -286,7 +301,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
286
301
  key: "fetchCatchup",
287
302
  value: function () {
288
303
  var _fetchCatchup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(fromVersion) {
289
- var _yield$utils$requestS, doc, version, stepMaps, metadata, errorCatchup;
304
+ var _yield$this$config$pe, _yield$utils$requestS, doc, version, stepMaps, metadata, errorCatchup;
290
305
 
291
306
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
292
307
  while (1) {
@@ -304,7 +319,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
304
319
  _context2.t6 = {};
305
320
 
306
321
  if (!this.config.permissionTokenRefresh) {
307
- _context2.next = 15;
322
+ _context2.next = 24;
308
323
  break;
309
324
  }
310
325
 
@@ -312,37 +327,61 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
312
327
  return this.config.permissionTokenRefresh();
313
328
 
314
329
  case 11:
315
- _context2.t8 = _context2.sent;
330
+ _context2.t9 = _yield$this$config$pe = _context2.sent;
331
+ _context2.t8 = _context2.t9 !== null;
332
+
333
+ if (!_context2.t8) {
334
+ _context2.next = 15;
335
+ break;
336
+ }
337
+
338
+ _context2.t8 = _yield$this$config$pe !== void 0;
339
+
340
+ case 15:
341
+ if (!_context2.t8) {
342
+ _context2.next = 19;
343
+ break;
344
+ }
345
+
346
+ _context2.t10 = _yield$this$config$pe;
347
+ _context2.next = 20;
348
+ break;
349
+
350
+ case 19:
351
+ _context2.t10 = undefined;
352
+
353
+ case 20:
354
+ _context2.t11 = _context2.t10;
316
355
  _context2.t7 = {
317
- 'x-token': _context2.t8
356
+ 'x-token': _context2.t11
318
357
  };
319
- _context2.next = 16;
358
+ _context2.next = 25;
320
359
  break;
321
360
 
322
- case 15:
361
+ case 24:
323
362
  _context2.t7 = {};
324
363
 
325
- case 16:
326
- _context2.t9 = _context2.t7;
327
- _context2.t10 = (0, _context2.t5)(_context2.t6, _context2.t9);
328
- _context2.t11 = {};
329
- _context2.t12 = {
364
+ case 25:
365
+ _context2.t12 = _context2.t7;
366
+ _context2.t13 = (0, _context2.t5)(_context2.t6, _context2.t12);
367
+ _context2.t14 = {};
368
+ _context2.t15 = {
330
369
  'x-product': getProduct(this.config.productInfo),
331
370
  'x-subproduct': getSubProduct(this.config.productInfo)
332
371
  };
333
- _context2.t13 = (0, _context2.t4)(_context2.t10, _context2.t11, _context2.t12);
334
- _context2.t14 = {
335
- headers: _context2.t13
372
+ _context2.t16 = (0, _context2.t4)(_context2.t13, _context2.t14, _context2.t15);
373
+ _context2.t17 = {
374
+ headers: _context2.t16
336
375
  };
337
- _context2.t15 = {
376
+ _context2.t18 = {
338
377
  path: _context2.t2,
339
378
  queryParams: _context2.t3,
340
- requestInit: _context2.t14
379
+ requestInit: _context2.t17
341
380
  };
342
- _context2.next = 25;
343
- return _context2.t0.requestService.call(_context2.t0, _context2.t1, _context2.t15);
381
+ _context2.next = 34;
382
+ return _context2.t0.requestService.call(_context2.t0, _context2.t1, _context2.t18);
344
383
 
345
- case 25:
384
+ case 34:
346
385
  _yield$utils$requestS = _context2.sent;
347
386
  doc = _yield$utils$requestS.doc;
348
387
  version = _yield$utils$requestS.version;
@@ -355,26 +394,26 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
355
394
  metadata: metadata
356
395
  });
357
396
 
358
- case 33:
359
- _context2.prev = 33;
360
- _context2.t16 = _context2["catch"](0);
361
- logger("Can't fetch the catchup", _context2.t16.message);
397
+ case 42:
398
+ _context2.prev = 42;
399
+ _context2.t19 = _context2["catch"](0);
400
+ logger("Can't fetch the catchup", _context2.t19.message);
362
401
  errorCatchup = {
363
402
  message: ErrorCodeMapper.catchupFail.message,
364
403
  data: {
365
- status: _context2.t16.status,
404
+ status: _context2.t19.status,
366
405
  code: ErrorCodeMapper.catchupFail.code
367
406
  }
368
407
  };
369
408
  this.emit('error', errorCatchup);
370
409
  return _context2.abrupt("return", {});
371
410
 
372
- case 39:
411
+ case 48:
373
412
  case "end":
374
413
  return _context2.stop();
375
414
  }
376
415
  }
377
- }, _callee2, this, [[0, 33]]);
416
+ }, _callee2, this, [[0, 42]]);
378
417
  }));
379
418
 
380
419
  function fetchCatchup(_x2) {
@@ -389,14 +428,14 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
389
428
 
390
429
  }, {
391
430
  key: "broadcast",
392
- value: function broadcast(type, data) {
431
+ value: function broadcast(type, data, callback) {
393
432
  if (!this.connected || !this.socket) {
394
433
  return;
395
434
  }
396
435
 
397
436
  this.socket.emit('broadcast', _objectSpread({
398
437
  type: type
399
- }, data));
438
+ }, data), callback);
400
439
  }
401
440
  }, {
402
441
  key: "sendMetadata",
@@ -26,4 +26,12 @@ export var EVENT_STATUS;
26
26
  EVENT_STATUS["FAILURE"] = "FAILURE";
27
27
  })(EVENT_STATUS || (EVENT_STATUS = {}));
28
28
 
29
+ export var ADD_STEPS_TYPE;
30
+
31
+ (function (ADD_STEPS_TYPE) {
32
+ ADD_STEPS_TYPE["ACCEPTED"] = "ACCEPTED";
33
+ ADD_STEPS_TYPE["REJECTED"] = "REJECTED";
34
+ ADD_STEPS_TYPE["ERROR"] = "ERROR";
35
+ })(ADD_STEPS_TYPE || (ADD_STEPS_TYPE = {}));
36
+
29
37
  export var ACK_MAX_TRY = 30;
@@ -77,7 +77,7 @@ export var catchup = /*#__PURE__*/function () {
77
77
  * newer.
78
78
  */
79
79
 
80
- opt.fitlerQueue(function (data) {
80
+ opt.filterQueue(function (data) {
81
81
  return data.version > serverVersion;
82
82
  }); // We are too far behind - replace the entire document
83
83
 
@@ -112,7 +112,7 @@ export var catchup = /*#__PURE__*/function () {
112
112
  newUnconfirmedSteps = rebaseSteps(unconfirmedSteps, mapping);
113
113
  logger("Re-aply ".concat(newUnconfirmedSteps.length, " mapped unconfirmed steps: ").concat(JSON.stringify(newUnconfirmedSteps))); // Re-aply local steps
114
114
 
115
- opt.applyLocalsteps(newUnconfirmedSteps);
115
+ opt.applyLocalSteps(newUnconfirmedSteps);
116
116
  }
117
117
  }
118
118
  }