@atlaskit/collab-provider 9.14.0 → 9.15.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/collab-provider
2
2
 
3
+ ## 9.15.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#40940](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/40940) [`7a58a018436`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7a58a018436) - add error logs for when editor state is undefined
8
+
9
+ ## 9.15.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#41131](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41131) [`6d09bbf0bc7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6d09bbf0bc7) - only sending analytics event with unconfirmed step count on first connection when buffering is enabled
14
+
3
15
  ## 9.14.0
4
16
 
5
17
  ### Minor Changes
@@ -136,7 +136,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
136
136
  return (0, _prosemirrorCollab.getVersion)(state);
137
137
  });
138
138
  (0, _defineProperty2.default)(this, "getCurrentState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
139
- var _this$analyticsHelper4, state, adfDocument, currentState, measure, _this$analyticsHelper5, _this$analyticsHelper6, _measure;
139
+ var _this$getState2, _this$analyticsHelper5, _this$analyticsHelper4, state, adfDocument, currentState, measure, _this$analyticsHelper6, _this$analyticsHelper7, _measure;
140
140
  return _regenerator.default.wrap(function _callee2$(_context2) {
141
141
  while (1) switch (_context2.prev = _context2.next) {
142
142
  case 0:
@@ -144,6 +144,9 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
144
144
  (0, _performance.startMeasure)(_performance.MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
145
145
 
146
146
  // Convert ProseMirror document in Editor state to ADF document
147
+ if (!((_this$getState2 = _this.getState) !== null && _this$getState2 !== void 0 && _this$getState2.call(_this))) {
148
+ (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendErrorEvent(new Error('Editor state is undefined'), 'getCurrentState called without state');
149
+ }
147
150
  state = _this.getState();
148
151
  adfDocument = new _editorJsonTransformer.JSONTransformer().encode(state.doc);
149
152
  currentState = {
@@ -152,41 +155,41 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
152
155
  stepVersion: (0, _prosemirrorCollab.getVersion)(state)
153
156
  };
154
157
  measure = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
155
- (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendActionEvent(_const.EVENT_ACTION.GET_CURRENT_STATE, _const.EVENT_STATUS.SUCCESS, {
158
+ (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 || _this$analyticsHelper5.sendActionEvent(_const.EVENT_ACTION.GET_CURRENT_STATE, _const.EVENT_STATUS.SUCCESS, {
156
159
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
157
160
  });
158
161
  return _context2.abrupt("return", currentState);
159
- case 10:
160
- _context2.prev = 10;
162
+ case 11:
163
+ _context2.prev = 11;
161
164
  _context2.t0 = _context2["catch"](0);
162
165
  _measure = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
163
- (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 || _this$analyticsHelper5.sendActionEvent(_const.EVENT_ACTION.GET_CURRENT_STATE, _const.EVENT_STATUS.FAILURE, {
166
+ (_this$analyticsHelper6 = _this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 || _this$analyticsHelper6.sendActionEvent(_const.EVENT_ACTION.GET_CURRENT_STATE, _const.EVENT_STATUS.FAILURE, {
164
167
  latency: _measure === null || _measure === void 0 ? void 0 : _measure.duration
165
168
  });
166
- (_this$analyticsHelper6 = _this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 || _this$analyticsHelper6.sendErrorEvent(_context2.t0, 'Error while returning ADF version of current draft document');
169
+ (_this$analyticsHelper7 = _this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 || _this$analyticsHelper7.sendErrorEvent(_context2.t0, 'Error while returning ADF version of current draft document');
167
170
  throw _context2.t0;
168
- case 16:
171
+ case 17:
169
172
  case "end":
170
173
  return _context2.stop();
171
174
  }
172
- }, _callee2, null, [[0, 10]]);
175
+ }, _callee2, null, [[0, 11]]);
173
176
  })));
174
177
  (0, _defineProperty2.default)(this, "getUnconfirmedStepsOrigins", function () {
175
- var _this$getState2, _sendableSteps;
176
- var state = (_this$getState2 = _this.getState) === null || _this$getState2 === void 0 ? void 0 : _this$getState2.call(_this);
178
+ var _this$getState3, _sendableSteps;
179
+ var state = (_this$getState3 = _this.getState) === null || _this$getState3 === void 0 ? void 0 : _this$getState3.call(_this);
177
180
  if (!state) {
178
- var _this$analyticsHelper7;
179
- (_this$analyticsHelper7 = _this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 || _this$analyticsHelper7.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedStepsOrigins called without state');
181
+ var _this$analyticsHelper8;
182
+ (_this$analyticsHelper8 = _this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 || _this$analyticsHelper8.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedStepsOrigins called without state');
180
183
  return;
181
184
  }
182
185
  return (_sendableSteps = (0, _prosemirrorCollab.sendableSteps)(state)) === null || _sendableSteps === void 0 ? void 0 : _sendableSteps.origins;
183
186
  });
184
187
  (0, _defineProperty2.default)(this, "getUnconfirmedSteps", function () {
185
- var _this$getState3, _sendableSteps2;
186
- var state = (_this$getState3 = _this.getState) === null || _this$getState3 === void 0 ? void 0 : _this$getState3.call(_this);
188
+ var _this$getState4, _sendableSteps2;
189
+ var state = (_this$getState4 = _this.getState) === null || _this$getState4 === void 0 ? void 0 : _this$getState4.call(_this);
187
190
  if (!state) {
188
- var _this$analyticsHelper8;
189
- (_this$analyticsHelper8 = _this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 || _this$analyticsHelper8.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedSteps called without state');
191
+ var _this$analyticsHelper9;
192
+ (_this$analyticsHelper9 = _this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 || _this$analyticsHelper9.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedSteps called without state');
190
193
  return;
191
194
  }
192
195
  return (_sendableSteps2 = (0, _prosemirrorCollab.sendableSteps)(state)) === null || _sendableSteps2 === void 0 ? void 0 : _sendableSteps2.steps;
@@ -226,8 +229,8 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
226
229
  return userId;
227
230
  }));
228
231
  } catch (stepsAddedError) {
229
- var _this$analyticsHelper9;
230
- (_this$analyticsHelper9 = _this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 || _this$analyticsHelper9.sendErrorEvent(stepsAddedError, 'Error while adding steps in the provider');
232
+ var _this$analyticsHelper10;
233
+ (_this$analyticsHelper10 = _this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 || _this$analyticsHelper10.sendErrorEvent(stepsAddedError, 'Error while adding steps in the provider');
231
234
  _this.onErrorHandled({
232
235
  message: 'Error while adding steps in the provider',
233
236
  data: {
@@ -246,7 +249,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
246
249
  // Preserve the unconfirmed steps to prevent data loss.
247
250
  var unconfirmedSteps = _this.getUnconfirmedSteps();
248
251
  try {
249
- var _this$analyticsHelper10;
252
+ var _this$analyticsHelper11;
250
253
  // Reset the editor,
251
254
  // - Replace the document, keep in sync with the server
252
255
  // - Replace the version number, so editor is in sync with NCS server and can commit new changes.
@@ -265,16 +268,16 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
265
268
  if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
266
269
  _this.applyLocalSteps(unconfirmedSteps);
267
270
  }
268
- (_this$analyticsHelper10 = _this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 || _this$analyticsHelper10.sendActionEvent(_const.EVENT_ACTION.REINITIALISE_DOCUMENT, _const.EVENT_STATUS.SUCCESS, {
271
+ (_this$analyticsHelper11 = _this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 || _this$analyticsHelper11.sendActionEvent(_const.EVENT_ACTION.REINITIALISE_DOCUMENT, _const.EVENT_STATUS.SUCCESS, {
269
272
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length,
270
273
  hasTitle: !!(metadata !== null && metadata !== void 0 && metadata.title)
271
274
  });
272
275
  } catch (restoreError) {
273
- var _this$analyticsHelper11, _this$analyticsHelper12;
274
- (_this$analyticsHelper11 = _this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 || _this$analyticsHelper11.sendActionEvent(_const.EVENT_ACTION.REINITIALISE_DOCUMENT, _const.EVENT_STATUS.FAILURE, {
276
+ var _this$analyticsHelper12, _this$analyticsHelper13;
277
+ (_this$analyticsHelper12 = _this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 || _this$analyticsHelper12.sendActionEvent(_const.EVENT_ACTION.REINITIALISE_DOCUMENT, _const.EVENT_STATUS.FAILURE, {
275
278
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
276
279
  });
277
- (_this$analyticsHelper12 = _this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 || _this$analyticsHelper12.sendErrorEvent(restoreError, 'Error while reinitialising document');
280
+ (_this$analyticsHelper13 = _this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 || _this$analyticsHelper13.sendErrorEvent(restoreError, 'Error while reinitialising document');
278
281
  _this.onErrorHandled({
279
282
  message: 'Caught error while trying to recover the document',
280
283
  data: {
@@ -286,7 +289,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
286
289
  }
287
290
  });
288
291
  (0, _defineProperty2.default)(this, "getFinalAcknowledgedState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
289
- var _this$analyticsHelper13, finalAcknowledgedState, currentState, reconcileResponse, measure, _this$analyticsHelper14, _this$analyticsHelper15, _measure2;
292
+ var _this$analyticsHelper14, finalAcknowledgedState, currentState, reconcileResponse, measure, _this$analyticsHelper15, _this$analyticsHelper16, _measure2;
290
293
  return _regenerator.default.wrap(function _callee3$(_context3) {
291
294
  while (1) switch (_context3.prev = _context3.next) {
292
295
  case 0:
@@ -336,7 +339,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
336
339
  finalAcknowledgedState = _context3.sent;
337
340
  case 28:
338
341
  measure = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
339
- (_this$analyticsHelper13 = _this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 || _this$analyticsHelper13.sendActionEvent(_const.EVENT_ACTION.PUBLISH_PAGE, _const.EVENT_STATUS.SUCCESS, {
342
+ (_this$analyticsHelper14 = _this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 || _this$analyticsHelper14.sendActionEvent(_const.EVENT_ACTION.PUBLISH_PAGE, _const.EVENT_STATUS.SUCCESS, {
340
343
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
341
344
  });
342
345
  _this.aggressiveCatchup = false;
@@ -346,10 +349,10 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
346
349
  _context3.t1 = _context3["catch"](1);
347
350
  _this.aggressiveCatchup = false;
348
351
  _measure2 = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
349
- (_this$analyticsHelper14 = _this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 || _this$analyticsHelper14.sendActionEvent(_const.EVENT_ACTION.PUBLISH_PAGE, _const.EVENT_STATUS.FAILURE, {
352
+ (_this$analyticsHelper15 = _this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 || _this$analyticsHelper15.sendActionEvent(_const.EVENT_ACTION.PUBLISH_PAGE, _const.EVENT_STATUS.FAILURE, {
350
353
  latency: _measure2 === null || _measure2 === void 0 ? void 0 : _measure2.duration
351
354
  });
352
- (_this$analyticsHelper15 = _this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 || _this$analyticsHelper15.sendErrorEvent(_context3.t1, 'Error while returning ADF version of the final draft document');
355
+ (_this$analyticsHelper16 = _this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 || _this$analyticsHelper16.sendErrorEvent(_context3.t1, 'Error while returning ADF version of the final draft document');
353
356
  throw _context3.t1;
354
357
  case 41:
355
358
  case "end":
@@ -371,7 +374,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
371
374
  } : {}));
372
375
  var updatedVersion = _this.getCurrentPmVersion();
373
376
  if (_this.getCurrentPmVersion() !== version) {
374
- var _doc$content, _this$analyticsHelper16;
377
+ var _doc$content, _this$analyticsHelper17;
375
378
  var isDocContentValid = _this.validatePMJSONDocument(doc);
376
379
  var _error = new _errorTypes.UpdateDocumentError('Failed to update the document', {
377
380
  newVersion: version,
@@ -380,7 +383,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
380
383
  docHasContent: (doc === null || doc === void 0 || (_doc$content = doc.content) === null || _doc$content === void 0 ? void 0 : _doc$content.length) >= 1,
381
384
  isDocContentValid: isDocContentValid
382
385
  });
383
- (_this$analyticsHelper16 = _this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 || _this$analyticsHelper16.sendErrorEvent(_error, 'Failed to update the document in document service');
386
+ (_this$analyticsHelper17 = _this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 || _this$analyticsHelper17.sendErrorEvent(_error, 'Failed to update the document in document service');
384
387
  if (_this.enableErrorOnFailedDocumentApply) {
385
388
  _this.onErrorHandled({
386
389
  message: 'The provider failed to apply changes to the editor',
@@ -400,6 +403,11 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
400
403
  });
401
404
  (0, _defineProperty2.default)(this, "validatePMJSONDocument", function (doc) {
402
405
  try {
406
+ var _this$getState5;
407
+ if (!((_this$getState5 = _this.getState) !== null && _this$getState5 !== void 0 && _this$getState5.call(_this))) {
408
+ var _this$analyticsHelper18;
409
+ (_this$analyticsHelper18 = _this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 || _this$analyticsHelper18.sendErrorEvent(new Error('Editor state is undefined'), 'validatePMJSONDocument called without state');
410
+ }
403
411
  var state = _this.getState();
404
412
  var content = (doc.content || []).map(function (child) {
405
413
  return state.schema.nodeFromJSON(child);
@@ -421,14 +429,14 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
421
429
  * @throws {Error} Couldn't sync the steps after retrying 30 times
422
430
  */
423
431
  (0, _defineProperty2.default)(this, "commitUnconfirmedSteps", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
424
- var unconfirmedSteps, _this$analyticsHelper17, count, unconfirmedTrs, lastTr, isLastTrConfirmed, nextUnconfirmedSteps, nextUnconfirmedTrs, _this$getUnconfirmedS, state, unconfirmedStepsInfoUGCRemoved, _error2, measure, _this$analyticsHelper18, _this$analyticsHelper19, _measure3;
432
+ var unconfirmedSteps, _this$getState6, _this$analyticsHelper20, count, unconfirmedTrs, lastTr, isLastTrConfirmed, _this$analyticsHelper19, nextUnconfirmedSteps, nextUnconfirmedTrs, _this$getUnconfirmedS, state, unconfirmedStepsInfoUGCRemoved, _error2, measure, _this$analyticsHelper21, _this$analyticsHelper22, _measure3;
425
433
  return _regenerator.default.wrap(function _callee4$(_context4) {
426
434
  while (1) switch (_context4.prev = _context4.next) {
427
435
  case 0:
428
436
  unconfirmedSteps = _this.getUnconfirmedSteps();
429
437
  _context4.prev = 1;
430
438
  if (!(unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length)) {
431
- _context4.next = 23;
439
+ _context4.next = 24;
432
440
  break;
433
441
  }
434
442
  (0, _performance.startMeasure)(_performance.MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
@@ -439,15 +447,18 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
439
447
  unconfirmedTrs = _this.getUnconfirmedStepsOrigins();
440
448
  lastTr = unconfirmedTrs === null || unconfirmedTrs === void 0 ? void 0 : unconfirmedTrs[unconfirmedTrs.length - 1];
441
449
  isLastTrConfirmed = false;
442
- case 8:
450
+ if (!((_this$getState6 = _this.getState) !== null && _this$getState6 !== void 0 && _this$getState6.call(_this))) {
451
+ (_this$analyticsHelper19 = _this.analyticsHelper) === null || _this$analyticsHelper19 === void 0 || _this$analyticsHelper19.sendErrorEvent(new Error('Editor state is undefined'), 'commitUnconfirmedSteps called without state');
452
+ }
453
+ case 9:
443
454
  if (isLastTrConfirmed) {
444
- _context4.next = 21;
455
+ _context4.next = 22;
445
456
  break;
446
457
  }
447
458
  _this.sendStepsFromCurrentState();
448
- _context4.next = 12;
459
+ _context4.next = 13;
449
460
  return (0, _utils.sleep)(500);
450
- case 12:
461
+ case 13:
451
462
  nextUnconfirmedSteps = _this.getUnconfirmedSteps();
452
463
  if (nextUnconfirmedSteps !== null && nextUnconfirmedSteps !== void 0 && nextUnconfirmedSteps.length) {
453
464
  nextUnconfirmedTrs = _this.getUnconfirmedStepsOrigins();
@@ -458,7 +469,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
458
469
  isLastTrConfirmed = true;
459
470
  }
460
471
  if (!(!isLastTrConfirmed && count++ >= _const.ACK_MAX_TRY)) {
461
- _context4.next = 19;
472
+ _context4.next = 20;
462
473
  break;
463
474
  }
464
475
  if (_this.onSyncUpError) {
@@ -478,47 +489,47 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
478
489
  unconfirmedStepsInfo: unconfirmedStepsInfoUGCRemoved ? unconfirmedStepsInfoUGCRemoved.toString() : 'Unable to generate UGC removed step info'
479
490
  });
480
491
  throw _error2;
481
- case 19:
482
- _context4.next = 8;
492
+ case 20:
493
+ _context4.next = 9;
483
494
  break;
484
- case 21:
495
+ case 22:
485
496
  measure = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
486
- (_this$analyticsHelper17 = _this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 || _this$analyticsHelper17.sendActionEvent(_const.EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, _const.EVENT_STATUS.SUCCESS, {
497
+ (_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 || _this$analyticsHelper20.sendActionEvent(_const.EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, _const.EVENT_STATUS.SUCCESS, {
487
498
  latency: measure === null || measure === void 0 ? void 0 : measure.duration,
488
499
  // upon success, emit the total number of unconfirmed steps we synced
489
500
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
490
501
  });
491
- case 23:
492
- _context4.next = 31;
502
+ case 24:
503
+ _context4.next = 32;
493
504
  break;
494
- case 25:
495
- _context4.prev = 25;
505
+ case 26:
506
+ _context4.prev = 26;
496
507
  _context4.t0 = _context4["catch"](1);
497
508
  _measure3 = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
498
- (_this$analyticsHelper18 = _this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 || _this$analyticsHelper18.sendActionEvent(_const.EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, _const.EVENT_STATUS.FAILURE, {
509
+ (_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 || _this$analyticsHelper21.sendActionEvent(_const.EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, _const.EVENT_STATUS.FAILURE, {
499
510
  latency: _measure3 === null || _measure3 === void 0 ? void 0 : _measure3.duration,
500
511
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
501
512
  });
502
- (_this$analyticsHelper19 = _this.analyticsHelper) === null || _this$analyticsHelper19 === void 0 || _this$analyticsHelper19.sendErrorEvent(_context4.t0, 'Error while committing unconfirmed steps');
513
+ (_this$analyticsHelper22 = _this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 || _this$analyticsHelper22.sendErrorEvent(_context4.t0, 'Error while committing unconfirmed steps');
503
514
  throw _context4.t0;
504
- case 31:
515
+ case 32:
505
516
  case "end":
506
517
  return _context4.stop();
507
518
  }
508
- }, _callee4, null, [[1, 25]]);
519
+ }, _callee4, null, [[1, 26]]);
509
520
  })));
510
521
  (0, _defineProperty2.default)(this, "onStepRejectedError", function () {
511
- var _this$analyticsHelper20;
522
+ var _this$analyticsHelper23;
512
523
  _this.stepRejectCounter++;
513
524
  logger("Steps rejected (tries=".concat(_this.stepRejectCounter, ")"));
514
- (_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 || _this$analyticsHelper20.sendActionEvent(_const.EVENT_ACTION.SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO, {
525
+ (_this$analyticsHelper23 = _this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 || _this$analyticsHelper23.sendActionEvent(_const.EVENT_ACTION.SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO, {
515
526
  count: _this.stepRejectCounter
516
527
  });
517
528
  var maxRetries = _this.aggressiveCatchup ? _this.failedStepsBeforeCatchupOnPublish : _provider.MAX_STEP_REJECTED_ERROR;
518
529
  if (_this.stepRejectCounter >= maxRetries) {
519
- var _this$analyticsHelper21;
530
+ var _this$analyticsHelper24;
520
531
  logger("The steps were rejected too many times (tries=".concat(_this.stepRejectCounter, ", limit=").concat(_provider.MAX_STEP_REJECTED_ERROR, "). Trying to catch-up."));
521
- (_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 || _this$analyticsHelper21.sendActionEvent(_const.EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO);
532
+ (_this$analyticsHelper24 = _this.analyticsHelper) === null || _this$analyticsHelper24 === void 0 || _this$analyticsHelper24.sendActionEvent(_const.EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO);
522
533
  _this.throttledCatchup();
523
534
  } else {
524
535
  // If committing steps failed try again automatically in 1s
@@ -593,9 +604,9 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
593
604
  }, 100);
594
605
  }
595
606
  } catch (error) {
596
- var _this$analyticsHelper22;
607
+ var _this$analyticsHelper25;
597
608
  logger("Processing steps failed with error: ".concat(error, ". Triggering catch up call."));
598
- (_this$analyticsHelper22 = this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 || _this$analyticsHelper22.sendErrorEvent(error, 'Error while processing steps');
609
+ (_this$analyticsHelper25 = this.analyticsHelper) === null || _this$analyticsHelper25 === void 0 || _this$analyticsHelper25.sendErrorEvent(error, 'Error while processing steps');
599
610
  this.throttledCatchup();
600
611
  }
601
612
  }
@@ -621,13 +632,15 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
621
632
  */
622
633
  }, {
623
634
  key: "sendStepsFromCurrentState",
624
- value: function sendStepsFromCurrentState() {
625
- var _this$getState4;
626
- var state = (_this$getState4 = this.getState) === null || _this$getState4 === void 0 ? void 0 : _this$getState4.call(this);
635
+ value: function sendStepsFromCurrentState(sendAnalyticsEvent) {
636
+ var _this$getState7;
637
+ var state = (_this$getState7 = this.getState) === null || _this$getState7 === void 0 ? void 0 : _this$getState7.call(this);
627
638
  if (!state) {
639
+ var _this$analyticsHelper26;
640
+ (_this$analyticsHelper26 = this.analyticsHelper) === null || _this$analyticsHelper26 === void 0 || _this$analyticsHelper26.sendErrorEvent(new Error('Editor state is undefined'), 'sendStepsFromCurrentState called without state');
628
641
  return;
629
642
  }
630
- this.send(null, null, state);
643
+ this.send(null, null, state, sendAnalyticsEvent);
631
644
  }
632
645
  }, {
633
646
  key: "send",
@@ -636,8 +649,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
636
649
  * Send steps from transaction to other participants
637
650
  * It needs the superfluous arguments because we keep the interface of the send API the same as the Synchrony plugin
638
651
  */
639
- function send(_tr, _oldState, newState) {
640
- var _this$analyticsHelper23;
652
+ function send(_tr, _oldState, newState, sendAnalyticsEvent) {
641
653
  var unconfirmedStepsData = (0, _prosemirrorCollab.sendableSteps)(newState);
642
654
  var version = (0, _prosemirrorCollab.getVersion)(newState);
643
655
 
@@ -646,9 +658,15 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
646
658
  return;
647
659
  }
648
660
  var unconfirmedSteps = unconfirmedStepsData.steps;
649
- (_this$analyticsHelper23 = this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 || _this$analyticsHelper23.sendActionEvent(_const.EVENT_ACTION.HAS_UNCONFIRMED_STEPS, _const.EVENT_STATUS.INFO, {
650
- numUnconfirmedSteps: (unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length) || 0
651
- });
661
+ // sendAnalyticsEvent is only true when buffering is enabled,
662
+ // to ensure that analytics events with the number of unconfirmed steps is only
663
+ // sent once on connection (as opposed to on every step)
664
+ if (sendAnalyticsEvent) {
665
+ var _this$analyticsHelper27;
666
+ (_this$analyticsHelper27 = this.analyticsHelper) === null || _this$analyticsHelper27 === void 0 || _this$analyticsHelper27.sendActionEvent(_const.EVENT_ACTION.HAS_UNCONFIRMED_STEPS, _const.EVENT_STATUS.INFO, {
667
+ numUnconfirmedSteps: (unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length) || 0
668
+ });
669
+ }
652
670
  if (!(unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length)) {
653
671
  return;
654
672
  }
@@ -100,7 +100,7 @@ var Provider = exports.Provider = /*#__PURE__*/function (_Emitter) {
100
100
  // send any unconfirmed steps
101
101
  if (_this.isBufferingEnabled && _this.isProviderInitialized && !_this.isBuffered) {
102
102
  _this.isBuffered = true; // setting buffering to true so that the sending of unconfirmed steps happens only on first connection
103
- _this.documentService.sendStepsFromCurrentState();
103
+ _this.documentService.sendStepsFromCurrentState(true);
104
104
  }
105
105
 
106
106
  // Early initialization with initial draft passed via provider
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/collab-provider";
8
- var version = exports.version = "9.14.0";
8
+ var version = exports.version = "9.15.1";
9
9
  var nextMajorVersion = exports.nextMajorVersion = function nextMajorVersion() {
10
10
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
11
11
  };
@@ -101,10 +101,14 @@ export class DocumentService {
101
101
  });
102
102
  _defineProperty(this, "getCurrentState", async () => {
103
103
  try {
104
- var _this$analyticsHelper4;
104
+ var _this$getState2, _this$analyticsHelper5;
105
105
  startMeasure(MEASURE_NAME.GET_CURRENT_STATE, this.analyticsHelper);
106
106
 
107
107
  // Convert ProseMirror document in Editor state to ADF document
108
+ if (!((_this$getState2 = this.getState) !== null && _this$getState2 !== void 0 && _this$getState2.call(this))) {
109
+ var _this$analyticsHelper4;
110
+ (_this$analyticsHelper4 = this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(new Error('Editor state is undefined'), 'getCurrentState called without state');
111
+ }
108
112
  const state = this.getState();
109
113
  const adfDocument = new JSONTransformer().encode(state.doc);
110
114
  const currentState = {
@@ -113,36 +117,36 @@ export class DocumentService {
113
117
  stepVersion: getVersion(state)
114
118
  };
115
119
  const measure = stopMeasure(MEASURE_NAME.GET_CURRENT_STATE, this.analyticsHelper);
116
- (_this$analyticsHelper4 = this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.SUCCESS, {
120
+ (_this$analyticsHelper5 = this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.SUCCESS, {
117
121
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
118
122
  });
119
123
  return currentState;
120
124
  } catch (error) {
121
- var _this$analyticsHelper5, _this$analyticsHelper6;
125
+ var _this$analyticsHelper6, _this$analyticsHelper7;
122
126
  const measure = stopMeasure(MEASURE_NAME.GET_CURRENT_STATE, this.analyticsHelper);
123
- (_this$analyticsHelper5 = this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.FAILURE, {
127
+ (_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.FAILURE, {
124
128
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
125
129
  });
126
- (_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(error, 'Error while returning ADF version of current draft document');
130
+ (_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(error, 'Error while returning ADF version of current draft document');
127
131
  throw error; // Reject the promise so the consumer can react to it failing
128
132
  }
129
133
  });
130
134
  _defineProperty(this, "getUnconfirmedStepsOrigins", () => {
131
- var _this$getState2, _sendableSteps;
132
- const state = (_this$getState2 = this.getState) === null || _this$getState2 === void 0 ? void 0 : _this$getState2.call(this);
135
+ var _this$getState3, _sendableSteps;
136
+ const state = (_this$getState3 = this.getState) === null || _this$getState3 === void 0 ? void 0 : _this$getState3.call(this);
133
137
  if (!state) {
134
- var _this$analyticsHelper7;
135
- (_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedStepsOrigins called without state');
138
+ var _this$analyticsHelper8;
139
+ (_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedStepsOrigins called without state');
136
140
  return;
137
141
  }
138
142
  return (_sendableSteps = sendableSteps(state)) === null || _sendableSteps === void 0 ? void 0 : _sendableSteps.origins;
139
143
  });
140
144
  _defineProperty(this, "getUnconfirmedSteps", () => {
141
- var _this$getState3, _sendableSteps2;
142
- const state = (_this$getState3 = this.getState) === null || _this$getState3 === void 0 ? void 0 : _this$getState3.call(this);
145
+ var _this$getState4, _sendableSteps2;
146
+ const state = (_this$getState4 = this.getState) === null || _this$getState4 === void 0 ? void 0 : _this$getState4.call(this);
143
147
  if (!state) {
144
- var _this$analyticsHelper8;
145
- (_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedSteps called without state');
148
+ var _this$analyticsHelper9;
149
+ (_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedSteps called without state');
146
150
  return;
147
151
  }
148
152
  return (_sendableSteps2 = sendableSteps(state)) === null || _sendableSteps2 === void 0 ? void 0 : _sendableSteps2.steps;
@@ -181,8 +185,8 @@ export class DocumentService {
181
185
  userId
182
186
  }) => userId));
183
187
  } catch (stepsAddedError) {
184
- var _this$analyticsHelper9;
185
- (_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(stepsAddedError, 'Error while adding steps in the provider');
188
+ var _this$analyticsHelper10;
189
+ (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(stepsAddedError, 'Error while adding steps in the provider');
186
190
  this.onErrorHandled({
187
191
  message: 'Error while adding steps in the provider',
188
192
  data: {
@@ -202,7 +206,7 @@ export class DocumentService {
202
206
  // Preserve the unconfirmed steps to prevent data loss.
203
207
  const unconfirmedSteps = this.getUnconfirmedSteps();
204
208
  try {
205
- var _this$analyticsHelper10;
209
+ var _this$analyticsHelper11;
206
210
  // Reset the editor,
207
211
  // - Replace the document, keep in sync with the server
208
212
  // - Replace the version number, so editor is in sync with NCS server and can commit new changes.
@@ -221,16 +225,16 @@ export class DocumentService {
221
225
  if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
222
226
  this.applyLocalSteps(unconfirmedSteps);
223
227
  }
224
- (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.SUCCESS, {
228
+ (_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.SUCCESS, {
225
229
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length,
226
230
  hasTitle: !!(metadata !== null && metadata !== void 0 && metadata.title)
227
231
  });
228
232
  } catch (restoreError) {
229
- var _this$analyticsHelper11, _this$analyticsHelper12;
230
- (_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.FAILURE, {
233
+ var _this$analyticsHelper12, _this$analyticsHelper13;
234
+ (_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.FAILURE, {
231
235
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
232
236
  });
233
- (_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(restoreError, 'Error while reinitialising document');
237
+ (_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(restoreError, 'Error while reinitialising document');
234
238
  this.onErrorHandled({
235
239
  message: 'Caught error while trying to recover the document',
236
240
  data: {
@@ -244,7 +248,7 @@ export class DocumentService {
244
248
  _defineProperty(this, "getFinalAcknowledgedState", async () => {
245
249
  this.aggressiveCatchup = true;
246
250
  try {
247
- var _this$analyticsHelper13;
251
+ var _this$analyticsHelper14;
248
252
  startMeasure(MEASURE_NAME.PUBLISH_PAGE, this.analyticsHelper);
249
253
  let finalAcknowledgedState;
250
254
  if (getCollabProviderFeatureFlag('enableFallbackToReconcile', this.featureFlags)) {
@@ -266,19 +270,19 @@ export class DocumentService {
266
270
  finalAcknowledgedState = await this.getCurrentState();
267
271
  }
268
272
  const measure = stopMeasure(MEASURE_NAME.PUBLISH_PAGE, this.analyticsHelper);
269
- (_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.SUCCESS, {
273
+ (_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.SUCCESS, {
270
274
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
271
275
  });
272
276
  this.aggressiveCatchup = false;
273
277
  return finalAcknowledgedState;
274
278
  } catch (error) {
275
- var _this$analyticsHelper14, _this$analyticsHelper15;
279
+ var _this$analyticsHelper15, _this$analyticsHelper16;
276
280
  this.aggressiveCatchup = false;
277
281
  const measure = stopMeasure(MEASURE_NAME.PUBLISH_PAGE, this.analyticsHelper);
278
- (_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.FAILURE, {
282
+ (_this$analyticsHelper15 = this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 ? void 0 : _this$analyticsHelper15.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.FAILURE, {
279
283
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
280
284
  });
281
- (_this$analyticsHelper15 = this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 ? void 0 : _this$analyticsHelper15.sendErrorEvent(error, 'Error while returning ADF version of the final draft document');
285
+ (_this$analyticsHelper16 = this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 ? void 0 : _this$analyticsHelper16.sendErrorEvent(error, 'Error while returning ADF version of the final draft document');
282
286
  throw error; // Reject the promise so the consumer can react to it failing
283
287
  }
284
288
  });
@@ -298,7 +302,7 @@ export class DocumentService {
298
302
  });
299
303
  const updatedVersion = this.getCurrentPmVersion();
300
304
  if (this.getCurrentPmVersion() !== version) {
301
- var _doc$content, _this$analyticsHelper16;
305
+ var _doc$content, _this$analyticsHelper17;
302
306
  const isDocContentValid = this.validatePMJSONDocument(doc);
303
307
  const error = new UpdateDocumentError('Failed to update the document', {
304
308
  newVersion: version,
@@ -307,7 +311,7 @@ export class DocumentService {
307
311
  docHasContent: (doc === null || doc === void 0 ? void 0 : (_doc$content = doc.content) === null || _doc$content === void 0 ? void 0 : _doc$content.length) >= 1,
308
312
  isDocContentValid
309
313
  });
310
- (_this$analyticsHelper16 = this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 ? void 0 : _this$analyticsHelper16.sendErrorEvent(error, 'Failed to update the document in document service');
314
+ (_this$analyticsHelper17 = this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 ? void 0 : _this$analyticsHelper17.sendErrorEvent(error, 'Failed to update the document in document service');
311
315
  if (this.enableErrorOnFailedDocumentApply) {
312
316
  this.onErrorHandled({
313
317
  message: 'The provider failed to apply changes to the editor',
@@ -327,6 +331,11 @@ export class DocumentService {
327
331
  });
328
332
  _defineProperty(this, "validatePMJSONDocument", doc => {
329
333
  try {
334
+ var _this$getState5;
335
+ if (!((_this$getState5 = this.getState) !== null && _this$getState5 !== void 0 && _this$getState5.call(this))) {
336
+ var _this$analyticsHelper18;
337
+ (_this$analyticsHelper18 = this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 ? void 0 : _this$analyticsHelper18.sendErrorEvent(new Error('Editor state is undefined'), 'validatePMJSONDocument called without state');
338
+ }
330
339
  const state = this.getState();
331
340
  const content = (doc.content || []).map(child => state.schema.nodeFromJSON(child));
332
341
  return content.every(node => {
@@ -349,7 +358,7 @@ export class DocumentService {
349
358
  const unconfirmedSteps = this.getUnconfirmedSteps();
350
359
  try {
351
360
  if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
352
- var _this$analyticsHelper17;
361
+ var _this$getState6, _this$analyticsHelper20;
353
362
  startMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, this.analyticsHelper);
354
363
  let count = 0;
355
364
  // We use origins here as steps can be rebased. When steps are rebased a new step is created.
@@ -359,6 +368,10 @@ export class DocumentService {
359
368
  const unconfirmedTrs = this.getUnconfirmedStepsOrigins();
360
369
  const lastTr = unconfirmedTrs === null || unconfirmedTrs === void 0 ? void 0 : unconfirmedTrs[unconfirmedTrs.length - 1];
361
370
  let isLastTrConfirmed = false;
371
+ if (!((_this$getState6 = this.getState) !== null && _this$getState6 !== void 0 && _this$getState6.call(this))) {
372
+ var _this$analyticsHelper19;
373
+ (_this$analyticsHelper19 = this.analyticsHelper) === null || _this$analyticsHelper19 === void 0 ? void 0 : _this$analyticsHelper19.sendErrorEvent(new Error('Editor state is undefined'), 'commitUnconfirmedSteps called without state');
374
+ }
362
375
  while (!isLastTrConfirmed) {
363
376
  this.sendStepsFromCurrentState();
364
377
  await sleep(500);
@@ -389,35 +402,35 @@ export class DocumentService {
389
402
  }
390
403
  }
391
404
  const measure = stopMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, this.analyticsHelper);
392
- (_this$analyticsHelper17 = this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 ? void 0 : _this$analyticsHelper17.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.SUCCESS, {
405
+ (_this$analyticsHelper20 = this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 ? void 0 : _this$analyticsHelper20.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.SUCCESS, {
393
406
  latency: measure === null || measure === void 0 ? void 0 : measure.duration,
394
407
  // upon success, emit the total number of unconfirmed steps we synced
395
408
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
396
409
  });
397
410
  }
398
411
  } catch (error) {
399
- var _this$analyticsHelper18, _this$analyticsHelper19;
412
+ var _this$analyticsHelper21, _this$analyticsHelper22;
400
413
  const measure = stopMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, this.analyticsHelper);
401
- (_this$analyticsHelper18 = this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 ? void 0 : _this$analyticsHelper18.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.FAILURE, {
414
+ (_this$analyticsHelper21 = this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 ? void 0 : _this$analyticsHelper21.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.FAILURE, {
402
415
  latency: measure === null || measure === void 0 ? void 0 : measure.duration,
403
416
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
404
417
  });
405
- (_this$analyticsHelper19 = this.analyticsHelper) === null || _this$analyticsHelper19 === void 0 ? void 0 : _this$analyticsHelper19.sendErrorEvent(error, 'Error while committing unconfirmed steps');
418
+ (_this$analyticsHelper22 = this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 ? void 0 : _this$analyticsHelper22.sendErrorEvent(error, 'Error while committing unconfirmed steps');
406
419
  throw error;
407
420
  }
408
421
  });
409
422
  _defineProperty(this, "onStepRejectedError", () => {
410
- var _this$analyticsHelper20;
423
+ var _this$analyticsHelper23;
411
424
  this.stepRejectCounter++;
412
425
  logger(`Steps rejected (tries=${this.stepRejectCounter})`);
413
- (_this$analyticsHelper20 = this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 ? void 0 : _this$analyticsHelper20.sendActionEvent(EVENT_ACTION.SEND_STEPS_RETRY, EVENT_STATUS.INFO, {
426
+ (_this$analyticsHelper23 = this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 ? void 0 : _this$analyticsHelper23.sendActionEvent(EVENT_ACTION.SEND_STEPS_RETRY, EVENT_STATUS.INFO, {
414
427
  count: this.stepRejectCounter
415
428
  });
416
429
  let maxRetries = this.aggressiveCatchup ? this.failedStepsBeforeCatchupOnPublish : MAX_STEP_REJECTED_ERROR;
417
430
  if (this.stepRejectCounter >= maxRetries) {
418
- var _this$analyticsHelper21;
431
+ var _this$analyticsHelper24;
419
432
  logger(`The steps were rejected too many times (tries=${this.stepRejectCounter}, limit=${MAX_STEP_REJECTED_ERROR}). Trying to catch-up.`);
420
- (_this$analyticsHelper21 = this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 ? void 0 : _this$analyticsHelper21.sendActionEvent(EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, EVENT_STATUS.INFO);
433
+ (_this$analyticsHelper24 = this.analyticsHelper) === null || _this$analyticsHelper24 === void 0 ? void 0 : _this$analyticsHelper24.sendActionEvent(EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, EVENT_STATUS.INFO);
421
434
  this.throttledCatchup();
422
435
  } else {
423
436
  // If committing steps failed try again automatically in 1s
@@ -484,9 +497,9 @@ export class DocumentService {
484
497
  setTimeout(() => this.sendStepsFromCurrentState(), 100);
485
498
  }
486
499
  } catch (error) {
487
- var _this$analyticsHelper22;
500
+ var _this$analyticsHelper25;
488
501
  logger(`Processing steps failed with error: ${error}. Triggering catch up call.`);
489
- (_this$analyticsHelper22 = this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 ? void 0 : _this$analyticsHelper22.sendErrorEvent(error, 'Error while processing steps');
502
+ (_this$analyticsHelper25 = this.analyticsHelper) === null || _this$analyticsHelper25 === void 0 ? void 0 : _this$analyticsHelper25.sendErrorEvent(error, 'Error while processing steps');
490
503
  this.throttledCatchup();
491
504
  }
492
505
  }
@@ -509,20 +522,21 @@ export class DocumentService {
509
522
  * The getState function will return the current EditorState
510
523
  * from the EditorView.
511
524
  */
512
- sendStepsFromCurrentState() {
513
- var _this$getState4;
514
- const state = (_this$getState4 = this.getState) === null || _this$getState4 === void 0 ? void 0 : _this$getState4.call(this);
525
+ sendStepsFromCurrentState(sendAnalyticsEvent) {
526
+ var _this$getState7;
527
+ const state = (_this$getState7 = this.getState) === null || _this$getState7 === void 0 ? void 0 : _this$getState7.call(this);
515
528
  if (!state) {
529
+ var _this$analyticsHelper26;
530
+ (_this$analyticsHelper26 = this.analyticsHelper) === null || _this$analyticsHelper26 === void 0 ? void 0 : _this$analyticsHelper26.sendErrorEvent(new Error('Editor state is undefined'), 'sendStepsFromCurrentState called without state');
516
531
  return;
517
532
  }
518
- this.send(null, null, state);
533
+ this.send(null, null, state, sendAnalyticsEvent);
519
534
  }
520
535
  /**
521
536
  * Send steps from transaction to other participants
522
537
  * It needs the superfluous arguments because we keep the interface of the send API the same as the Synchrony plugin
523
538
  */
524
- send(_tr, _oldState, newState) {
525
- var _this$analyticsHelper23;
539
+ send(_tr, _oldState, newState, sendAnalyticsEvent) {
526
540
  const unconfirmedStepsData = sendableSteps(newState);
527
541
  const version = getVersion(newState);
528
542
 
@@ -531,9 +545,15 @@ export class DocumentService {
531
545
  return;
532
546
  }
533
547
  const unconfirmedSteps = unconfirmedStepsData.steps;
534
- (_this$analyticsHelper23 = this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 ? void 0 : _this$analyticsHelper23.sendActionEvent(EVENT_ACTION.HAS_UNCONFIRMED_STEPS, EVENT_STATUS.INFO, {
535
- numUnconfirmedSteps: (unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length) || 0
536
- });
548
+ // sendAnalyticsEvent is only true when buffering is enabled,
549
+ // to ensure that analytics events with the number of unconfirmed steps is only
550
+ // sent once on connection (as opposed to on every step)
551
+ if (sendAnalyticsEvent) {
552
+ var _this$analyticsHelper27;
553
+ (_this$analyticsHelper27 = this.analyticsHelper) === null || _this$analyticsHelper27 === void 0 ? void 0 : _this$analyticsHelper27.sendActionEvent(EVENT_ACTION.HAS_UNCONFIRMED_STEPS, EVENT_STATUS.INFO, {
554
+ numUnconfirmedSteps: (unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length) || 0
555
+ });
556
+ }
537
557
  if (!(unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length)) {
538
558
  return;
539
559
  }
@@ -78,7 +78,7 @@ export class Provider extends Emitter {
78
78
  // send any unconfirmed steps
79
79
  if (this.isBufferingEnabled && this.isProviderInitialized && !this.isBuffered) {
80
80
  this.isBuffered = true; // setting buffering to true so that the sending of unconfirmed steps happens only on first connection
81
- this.documentService.sendStepsFromCurrentState();
81
+ this.documentService.sendStepsFromCurrentState(true);
82
82
  }
83
83
 
84
84
  // Early initialization with initial draft passed via provider
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/collab-provider";
2
- export const version = "9.14.0";
2
+ export const version = "9.15.1";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -129,7 +129,7 @@ export var DocumentService = /*#__PURE__*/function () {
129
129
  return getVersion(state);
130
130
  });
131
131
  _defineProperty(this, "getCurrentState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
132
- var _this$analyticsHelper4, state, adfDocument, currentState, measure, _this$analyticsHelper5, _this$analyticsHelper6, _measure;
132
+ var _this$getState2, _this$analyticsHelper5, _this$analyticsHelper4, state, adfDocument, currentState, measure, _this$analyticsHelper6, _this$analyticsHelper7, _measure;
133
133
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
134
134
  while (1) switch (_context2.prev = _context2.next) {
135
135
  case 0:
@@ -137,6 +137,9 @@ export var DocumentService = /*#__PURE__*/function () {
137
137
  startMeasure(MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
138
138
 
139
139
  // Convert ProseMirror document in Editor state to ADF document
140
+ if (!((_this$getState2 = _this.getState) !== null && _this$getState2 !== void 0 && _this$getState2.call(_this))) {
141
+ (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendErrorEvent(new Error('Editor state is undefined'), 'getCurrentState called without state');
142
+ }
140
143
  state = _this.getState();
141
144
  adfDocument = new JSONTransformer().encode(state.doc);
142
145
  currentState = {
@@ -145,41 +148,41 @@ export var DocumentService = /*#__PURE__*/function () {
145
148
  stepVersion: getVersion(state)
146
149
  };
147
150
  measure = stopMeasure(MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
148
- (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.SUCCESS, {
151
+ (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 || _this$analyticsHelper5.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.SUCCESS, {
149
152
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
150
153
  });
151
154
  return _context2.abrupt("return", currentState);
152
- case 10:
153
- _context2.prev = 10;
155
+ case 11:
156
+ _context2.prev = 11;
154
157
  _context2.t0 = _context2["catch"](0);
155
158
  _measure = stopMeasure(MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
156
- (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 || _this$analyticsHelper5.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.FAILURE, {
159
+ (_this$analyticsHelper6 = _this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 || _this$analyticsHelper6.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.FAILURE, {
157
160
  latency: _measure === null || _measure === void 0 ? void 0 : _measure.duration
158
161
  });
159
- (_this$analyticsHelper6 = _this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 || _this$analyticsHelper6.sendErrorEvent(_context2.t0, 'Error while returning ADF version of current draft document');
162
+ (_this$analyticsHelper7 = _this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 || _this$analyticsHelper7.sendErrorEvent(_context2.t0, 'Error while returning ADF version of current draft document');
160
163
  throw _context2.t0;
161
- case 16:
164
+ case 17:
162
165
  case "end":
163
166
  return _context2.stop();
164
167
  }
165
- }, _callee2, null, [[0, 10]]);
168
+ }, _callee2, null, [[0, 11]]);
166
169
  })));
167
170
  _defineProperty(this, "getUnconfirmedStepsOrigins", function () {
168
- var _this$getState2, _sendableSteps;
169
- var state = (_this$getState2 = _this.getState) === null || _this$getState2 === void 0 ? void 0 : _this$getState2.call(_this);
171
+ var _this$getState3, _sendableSteps;
172
+ var state = (_this$getState3 = _this.getState) === null || _this$getState3 === void 0 ? void 0 : _this$getState3.call(_this);
170
173
  if (!state) {
171
- var _this$analyticsHelper7;
172
- (_this$analyticsHelper7 = _this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 || _this$analyticsHelper7.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedStepsOrigins called without state');
174
+ var _this$analyticsHelper8;
175
+ (_this$analyticsHelper8 = _this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 || _this$analyticsHelper8.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedStepsOrigins called without state');
173
176
  return;
174
177
  }
175
178
  return (_sendableSteps = sendableSteps(state)) === null || _sendableSteps === void 0 ? void 0 : _sendableSteps.origins;
176
179
  });
177
180
  _defineProperty(this, "getUnconfirmedSteps", function () {
178
- var _this$getState3, _sendableSteps2;
179
- var state = (_this$getState3 = _this.getState) === null || _this$getState3 === void 0 ? void 0 : _this$getState3.call(_this);
181
+ var _this$getState4, _sendableSteps2;
182
+ var state = (_this$getState4 = _this.getState) === null || _this$getState4 === void 0 ? void 0 : _this$getState4.call(_this);
180
183
  if (!state) {
181
- var _this$analyticsHelper8;
182
- (_this$analyticsHelper8 = _this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 || _this$analyticsHelper8.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedSteps called without state');
184
+ var _this$analyticsHelper9;
185
+ (_this$analyticsHelper9 = _this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 || _this$analyticsHelper9.sendErrorEvent(new Error('No editor state when calling ProseMirror function'), 'getUnconfirmedSteps called without state');
183
186
  return;
184
187
  }
185
188
  return (_sendableSteps2 = sendableSteps(state)) === null || _sendableSteps2 === void 0 ? void 0 : _sendableSteps2.steps;
@@ -219,8 +222,8 @@ export var DocumentService = /*#__PURE__*/function () {
219
222
  return userId;
220
223
  }));
221
224
  } catch (stepsAddedError) {
222
- var _this$analyticsHelper9;
223
- (_this$analyticsHelper9 = _this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 || _this$analyticsHelper9.sendErrorEvent(stepsAddedError, 'Error while adding steps in the provider');
225
+ var _this$analyticsHelper10;
226
+ (_this$analyticsHelper10 = _this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 || _this$analyticsHelper10.sendErrorEvent(stepsAddedError, 'Error while adding steps in the provider');
224
227
  _this.onErrorHandled({
225
228
  message: 'Error while adding steps in the provider',
226
229
  data: {
@@ -239,7 +242,7 @@ export var DocumentService = /*#__PURE__*/function () {
239
242
  // Preserve the unconfirmed steps to prevent data loss.
240
243
  var unconfirmedSteps = _this.getUnconfirmedSteps();
241
244
  try {
242
- var _this$analyticsHelper10;
245
+ var _this$analyticsHelper11;
243
246
  // Reset the editor,
244
247
  // - Replace the document, keep in sync with the server
245
248
  // - Replace the version number, so editor is in sync with NCS server and can commit new changes.
@@ -258,16 +261,16 @@ export var DocumentService = /*#__PURE__*/function () {
258
261
  if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
259
262
  _this.applyLocalSteps(unconfirmedSteps);
260
263
  }
261
- (_this$analyticsHelper10 = _this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 || _this$analyticsHelper10.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.SUCCESS, {
264
+ (_this$analyticsHelper11 = _this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 || _this$analyticsHelper11.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.SUCCESS, {
262
265
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length,
263
266
  hasTitle: !!(metadata !== null && metadata !== void 0 && metadata.title)
264
267
  });
265
268
  } catch (restoreError) {
266
- var _this$analyticsHelper11, _this$analyticsHelper12;
267
- (_this$analyticsHelper11 = _this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 || _this$analyticsHelper11.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.FAILURE, {
269
+ var _this$analyticsHelper12, _this$analyticsHelper13;
270
+ (_this$analyticsHelper12 = _this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 || _this$analyticsHelper12.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.FAILURE, {
268
271
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
269
272
  });
270
- (_this$analyticsHelper12 = _this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 || _this$analyticsHelper12.sendErrorEvent(restoreError, 'Error while reinitialising document');
273
+ (_this$analyticsHelper13 = _this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 || _this$analyticsHelper13.sendErrorEvent(restoreError, 'Error while reinitialising document');
271
274
  _this.onErrorHandled({
272
275
  message: 'Caught error while trying to recover the document',
273
276
  data: {
@@ -279,7 +282,7 @@ export var DocumentService = /*#__PURE__*/function () {
279
282
  }
280
283
  });
281
284
  _defineProperty(this, "getFinalAcknowledgedState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
282
- var _this$analyticsHelper13, finalAcknowledgedState, currentState, reconcileResponse, measure, _this$analyticsHelper14, _this$analyticsHelper15, _measure2;
285
+ var _this$analyticsHelper14, finalAcknowledgedState, currentState, reconcileResponse, measure, _this$analyticsHelper15, _this$analyticsHelper16, _measure2;
283
286
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
284
287
  while (1) switch (_context3.prev = _context3.next) {
285
288
  case 0:
@@ -329,7 +332,7 @@ export var DocumentService = /*#__PURE__*/function () {
329
332
  finalAcknowledgedState = _context3.sent;
330
333
  case 28:
331
334
  measure = stopMeasure(MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
332
- (_this$analyticsHelper13 = _this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 || _this$analyticsHelper13.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.SUCCESS, {
335
+ (_this$analyticsHelper14 = _this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 || _this$analyticsHelper14.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.SUCCESS, {
333
336
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
334
337
  });
335
338
  _this.aggressiveCatchup = false;
@@ -339,10 +342,10 @@ export var DocumentService = /*#__PURE__*/function () {
339
342
  _context3.t1 = _context3["catch"](1);
340
343
  _this.aggressiveCatchup = false;
341
344
  _measure2 = stopMeasure(MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
342
- (_this$analyticsHelper14 = _this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 || _this$analyticsHelper14.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.FAILURE, {
345
+ (_this$analyticsHelper15 = _this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 || _this$analyticsHelper15.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.FAILURE, {
343
346
  latency: _measure2 === null || _measure2 === void 0 ? void 0 : _measure2.duration
344
347
  });
345
- (_this$analyticsHelper15 = _this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 || _this$analyticsHelper15.sendErrorEvent(_context3.t1, 'Error while returning ADF version of the final draft document');
348
+ (_this$analyticsHelper16 = _this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 || _this$analyticsHelper16.sendErrorEvent(_context3.t1, 'Error while returning ADF version of the final draft document');
346
349
  throw _context3.t1;
347
350
  case 41:
348
351
  case "end":
@@ -364,7 +367,7 @@ export var DocumentService = /*#__PURE__*/function () {
364
367
  } : {}));
365
368
  var updatedVersion = _this.getCurrentPmVersion();
366
369
  if (_this.getCurrentPmVersion() !== version) {
367
- var _doc$content, _this$analyticsHelper16;
370
+ var _doc$content, _this$analyticsHelper17;
368
371
  var isDocContentValid = _this.validatePMJSONDocument(doc);
369
372
  var _error = new UpdateDocumentError('Failed to update the document', {
370
373
  newVersion: version,
@@ -373,7 +376,7 @@ export var DocumentService = /*#__PURE__*/function () {
373
376
  docHasContent: (doc === null || doc === void 0 || (_doc$content = doc.content) === null || _doc$content === void 0 ? void 0 : _doc$content.length) >= 1,
374
377
  isDocContentValid: isDocContentValid
375
378
  });
376
- (_this$analyticsHelper16 = _this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 || _this$analyticsHelper16.sendErrorEvent(_error, 'Failed to update the document in document service');
379
+ (_this$analyticsHelper17 = _this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 || _this$analyticsHelper17.sendErrorEvent(_error, 'Failed to update the document in document service');
377
380
  if (_this.enableErrorOnFailedDocumentApply) {
378
381
  _this.onErrorHandled({
379
382
  message: 'The provider failed to apply changes to the editor',
@@ -393,6 +396,11 @@ export var DocumentService = /*#__PURE__*/function () {
393
396
  });
394
397
  _defineProperty(this, "validatePMJSONDocument", function (doc) {
395
398
  try {
399
+ var _this$getState5;
400
+ if (!((_this$getState5 = _this.getState) !== null && _this$getState5 !== void 0 && _this$getState5.call(_this))) {
401
+ var _this$analyticsHelper18;
402
+ (_this$analyticsHelper18 = _this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 || _this$analyticsHelper18.sendErrorEvent(new Error('Editor state is undefined'), 'validatePMJSONDocument called without state');
403
+ }
396
404
  var state = _this.getState();
397
405
  var content = (doc.content || []).map(function (child) {
398
406
  return state.schema.nodeFromJSON(child);
@@ -414,14 +422,14 @@ export var DocumentService = /*#__PURE__*/function () {
414
422
  * @throws {Error} Couldn't sync the steps after retrying 30 times
415
423
  */
416
424
  _defineProperty(this, "commitUnconfirmedSteps", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
417
- var unconfirmedSteps, _this$analyticsHelper17, count, unconfirmedTrs, lastTr, isLastTrConfirmed, nextUnconfirmedSteps, nextUnconfirmedTrs, _this$getUnconfirmedS, state, unconfirmedStepsInfoUGCRemoved, _error2, measure, _this$analyticsHelper18, _this$analyticsHelper19, _measure3;
425
+ var unconfirmedSteps, _this$getState6, _this$analyticsHelper20, count, unconfirmedTrs, lastTr, isLastTrConfirmed, _this$analyticsHelper19, nextUnconfirmedSteps, nextUnconfirmedTrs, _this$getUnconfirmedS, state, unconfirmedStepsInfoUGCRemoved, _error2, measure, _this$analyticsHelper21, _this$analyticsHelper22, _measure3;
418
426
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
419
427
  while (1) switch (_context4.prev = _context4.next) {
420
428
  case 0:
421
429
  unconfirmedSteps = _this.getUnconfirmedSteps();
422
430
  _context4.prev = 1;
423
431
  if (!(unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length)) {
424
- _context4.next = 23;
432
+ _context4.next = 24;
425
433
  break;
426
434
  }
427
435
  startMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
@@ -432,15 +440,18 @@ export var DocumentService = /*#__PURE__*/function () {
432
440
  unconfirmedTrs = _this.getUnconfirmedStepsOrigins();
433
441
  lastTr = unconfirmedTrs === null || unconfirmedTrs === void 0 ? void 0 : unconfirmedTrs[unconfirmedTrs.length - 1];
434
442
  isLastTrConfirmed = false;
435
- case 8:
443
+ if (!((_this$getState6 = _this.getState) !== null && _this$getState6 !== void 0 && _this$getState6.call(_this))) {
444
+ (_this$analyticsHelper19 = _this.analyticsHelper) === null || _this$analyticsHelper19 === void 0 || _this$analyticsHelper19.sendErrorEvent(new Error('Editor state is undefined'), 'commitUnconfirmedSteps called without state');
445
+ }
446
+ case 9:
436
447
  if (isLastTrConfirmed) {
437
- _context4.next = 21;
448
+ _context4.next = 22;
438
449
  break;
439
450
  }
440
451
  _this.sendStepsFromCurrentState();
441
- _context4.next = 12;
452
+ _context4.next = 13;
442
453
  return sleep(500);
443
- case 12:
454
+ case 13:
444
455
  nextUnconfirmedSteps = _this.getUnconfirmedSteps();
445
456
  if (nextUnconfirmedSteps !== null && nextUnconfirmedSteps !== void 0 && nextUnconfirmedSteps.length) {
446
457
  nextUnconfirmedTrs = _this.getUnconfirmedStepsOrigins();
@@ -451,7 +462,7 @@ export var DocumentService = /*#__PURE__*/function () {
451
462
  isLastTrConfirmed = true;
452
463
  }
453
464
  if (!(!isLastTrConfirmed && count++ >= ACK_MAX_TRY)) {
454
- _context4.next = 19;
465
+ _context4.next = 20;
455
466
  break;
456
467
  }
457
468
  if (_this.onSyncUpError) {
@@ -471,47 +482,47 @@ export var DocumentService = /*#__PURE__*/function () {
471
482
  unconfirmedStepsInfo: unconfirmedStepsInfoUGCRemoved ? unconfirmedStepsInfoUGCRemoved.toString() : 'Unable to generate UGC removed step info'
472
483
  });
473
484
  throw _error2;
474
- case 19:
475
- _context4.next = 8;
485
+ case 20:
486
+ _context4.next = 9;
476
487
  break;
477
- case 21:
488
+ case 22:
478
489
  measure = stopMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
479
- (_this$analyticsHelper17 = _this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 || _this$analyticsHelper17.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.SUCCESS, {
490
+ (_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 || _this$analyticsHelper20.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.SUCCESS, {
480
491
  latency: measure === null || measure === void 0 ? void 0 : measure.duration,
481
492
  // upon success, emit the total number of unconfirmed steps we synced
482
493
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
483
494
  });
484
- case 23:
485
- _context4.next = 31;
495
+ case 24:
496
+ _context4.next = 32;
486
497
  break;
487
- case 25:
488
- _context4.prev = 25;
498
+ case 26:
499
+ _context4.prev = 26;
489
500
  _context4.t0 = _context4["catch"](1);
490
501
  _measure3 = stopMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
491
- (_this$analyticsHelper18 = _this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 || _this$analyticsHelper18.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.FAILURE, {
502
+ (_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 || _this$analyticsHelper21.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.FAILURE, {
492
503
  latency: _measure3 === null || _measure3 === void 0 ? void 0 : _measure3.duration,
493
504
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
494
505
  });
495
- (_this$analyticsHelper19 = _this.analyticsHelper) === null || _this$analyticsHelper19 === void 0 || _this$analyticsHelper19.sendErrorEvent(_context4.t0, 'Error while committing unconfirmed steps');
506
+ (_this$analyticsHelper22 = _this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 || _this$analyticsHelper22.sendErrorEvent(_context4.t0, 'Error while committing unconfirmed steps');
496
507
  throw _context4.t0;
497
- case 31:
508
+ case 32:
498
509
  case "end":
499
510
  return _context4.stop();
500
511
  }
501
- }, _callee4, null, [[1, 25]]);
512
+ }, _callee4, null, [[1, 26]]);
502
513
  })));
503
514
  _defineProperty(this, "onStepRejectedError", function () {
504
- var _this$analyticsHelper20;
515
+ var _this$analyticsHelper23;
505
516
  _this.stepRejectCounter++;
506
517
  logger("Steps rejected (tries=".concat(_this.stepRejectCounter, ")"));
507
- (_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 || _this$analyticsHelper20.sendActionEvent(EVENT_ACTION.SEND_STEPS_RETRY, EVENT_STATUS.INFO, {
518
+ (_this$analyticsHelper23 = _this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 || _this$analyticsHelper23.sendActionEvent(EVENT_ACTION.SEND_STEPS_RETRY, EVENT_STATUS.INFO, {
508
519
  count: _this.stepRejectCounter
509
520
  });
510
521
  var maxRetries = _this.aggressiveCatchup ? _this.failedStepsBeforeCatchupOnPublish : MAX_STEP_REJECTED_ERROR;
511
522
  if (_this.stepRejectCounter >= maxRetries) {
512
- var _this$analyticsHelper21;
523
+ var _this$analyticsHelper24;
513
524
  logger("The steps were rejected too many times (tries=".concat(_this.stepRejectCounter, ", limit=").concat(MAX_STEP_REJECTED_ERROR, "). Trying to catch-up."));
514
- (_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 || _this$analyticsHelper21.sendActionEvent(EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, EVENT_STATUS.INFO);
525
+ (_this$analyticsHelper24 = _this.analyticsHelper) === null || _this$analyticsHelper24 === void 0 || _this$analyticsHelper24.sendActionEvent(EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, EVENT_STATUS.INFO);
515
526
  _this.throttledCatchup();
516
527
  } else {
517
528
  // If committing steps failed try again automatically in 1s
@@ -586,9 +597,9 @@ export var DocumentService = /*#__PURE__*/function () {
586
597
  }, 100);
587
598
  }
588
599
  } catch (error) {
589
- var _this$analyticsHelper22;
600
+ var _this$analyticsHelper25;
590
601
  logger("Processing steps failed with error: ".concat(error, ". Triggering catch up call."));
591
- (_this$analyticsHelper22 = this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 || _this$analyticsHelper22.sendErrorEvent(error, 'Error while processing steps');
602
+ (_this$analyticsHelper25 = this.analyticsHelper) === null || _this$analyticsHelper25 === void 0 || _this$analyticsHelper25.sendErrorEvent(error, 'Error while processing steps');
592
603
  this.throttledCatchup();
593
604
  }
594
605
  }
@@ -614,13 +625,15 @@ export var DocumentService = /*#__PURE__*/function () {
614
625
  */
615
626
  }, {
616
627
  key: "sendStepsFromCurrentState",
617
- value: function sendStepsFromCurrentState() {
618
- var _this$getState4;
619
- var state = (_this$getState4 = this.getState) === null || _this$getState4 === void 0 ? void 0 : _this$getState4.call(this);
628
+ value: function sendStepsFromCurrentState(sendAnalyticsEvent) {
629
+ var _this$getState7;
630
+ var state = (_this$getState7 = this.getState) === null || _this$getState7 === void 0 ? void 0 : _this$getState7.call(this);
620
631
  if (!state) {
632
+ var _this$analyticsHelper26;
633
+ (_this$analyticsHelper26 = this.analyticsHelper) === null || _this$analyticsHelper26 === void 0 || _this$analyticsHelper26.sendErrorEvent(new Error('Editor state is undefined'), 'sendStepsFromCurrentState called without state');
621
634
  return;
622
635
  }
623
- this.send(null, null, state);
636
+ this.send(null, null, state, sendAnalyticsEvent);
624
637
  }
625
638
  }, {
626
639
  key: "send",
@@ -629,8 +642,7 @@ export var DocumentService = /*#__PURE__*/function () {
629
642
  * Send steps from transaction to other participants
630
643
  * It needs the superfluous arguments because we keep the interface of the send API the same as the Synchrony plugin
631
644
  */
632
- function send(_tr, _oldState, newState) {
633
- var _this$analyticsHelper23;
645
+ function send(_tr, _oldState, newState, sendAnalyticsEvent) {
634
646
  var unconfirmedStepsData = sendableSteps(newState);
635
647
  var version = getVersion(newState);
636
648
 
@@ -639,9 +651,15 @@ export var DocumentService = /*#__PURE__*/function () {
639
651
  return;
640
652
  }
641
653
  var unconfirmedSteps = unconfirmedStepsData.steps;
642
- (_this$analyticsHelper23 = this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 || _this$analyticsHelper23.sendActionEvent(EVENT_ACTION.HAS_UNCONFIRMED_STEPS, EVENT_STATUS.INFO, {
643
- numUnconfirmedSteps: (unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length) || 0
644
- });
654
+ // sendAnalyticsEvent is only true when buffering is enabled,
655
+ // to ensure that analytics events with the number of unconfirmed steps is only
656
+ // sent once on connection (as opposed to on every step)
657
+ if (sendAnalyticsEvent) {
658
+ var _this$analyticsHelper27;
659
+ (_this$analyticsHelper27 = this.analyticsHelper) === null || _this$analyticsHelper27 === void 0 || _this$analyticsHelper27.sendActionEvent(EVENT_ACTION.HAS_UNCONFIRMED_STEPS, EVENT_STATUS.INFO, {
660
+ numUnconfirmedSteps: (unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length) || 0
661
+ });
662
+ }
645
663
  if (!(unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length)) {
646
664
  return;
647
665
  }
@@ -93,7 +93,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
93
93
  // send any unconfirmed steps
94
94
  if (_this.isBufferingEnabled && _this.isProviderInitialized && !_this.isBuffered) {
95
95
  _this.isBuffered = true; // setting buffering to true so that the sending of unconfirmed steps happens only on first connection
96
- _this.documentService.sendStepsFromCurrentState();
96
+ _this.documentService.sendStepsFromCurrentState(true);
97
97
  }
98
98
 
99
99
  // Early initialization with initial draft passed via provider
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/collab-provider";
2
- export var version = "9.14.0";
2
+ export var version = "9.15.1";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -88,11 +88,11 @@ export declare class DocumentService {
88
88
  * The getState function will return the current EditorState
89
89
  * from the EditorView.
90
90
  */
91
- sendStepsFromCurrentState(): void;
91
+ sendStepsFromCurrentState(sendAnalyticsEvent?: boolean): void;
92
92
  onStepRejectedError: () => void;
93
93
  /**
94
94
  * Send steps from transaction to other participants
95
95
  * It needs the superfluous arguments because we keep the interface of the send API the same as the Synchrony plugin
96
96
  */
97
- send(_tr: Transaction | null, _oldState: EditorState | null, newState: EditorState): void;
97
+ send(_tr: Transaction | null, _oldState: EditorState | null, newState: EditorState, sendAnalyticsEvent?: boolean): void;
98
98
  }
@@ -88,11 +88,11 @@ export declare class DocumentService {
88
88
  * The getState function will return the current EditorState
89
89
  * from the EditorView.
90
90
  */
91
- sendStepsFromCurrentState(): void;
91
+ sendStepsFromCurrentState(sendAnalyticsEvent?: boolean): void;
92
92
  onStepRejectedError: () => void;
93
93
  /**
94
94
  * Send steps from transaction to other participants
95
95
  * It needs the superfluous arguments because we keep the interface of the send API the same as the Synchrony plugin
96
96
  */
97
- send(_tr: Transaction | null, _oldState: EditorState | null, newState: EditorState): void;
97
+ send(_tr: Transaction | null, _oldState: EditorState | null, newState: EditorState, sendAnalyticsEvent?: boolean): void;
98
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "9.14.0",
3
+ "version": "9.15.1",
4
4
  "description": "A provider for collaborative editing.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "@atlaskit/analytics-gas-types": "^5.1.0",
38
38
  "@atlaskit/analytics-listeners": "^8.7.0",
39
- "@atlaskit/editor-common": "^76.3.0",
39
+ "@atlaskit/editor-common": "^76.5.0",
40
40
  "@atlaskit/editor-json-transformer": "^8.10.0",
41
41
  "@atlaskit/editor-prosemirror": "1.1.0",
42
42
  "@atlaskit/prosemirror-collab": "^0.2.0",