@atlaskit/collab-provider 8.3.0 → 8.4.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 (42) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/analytics/index.js +2 -1
  3. package/dist/cjs/analytics/performance.js +1 -0
  4. package/dist/cjs/channel.js +230 -120
  5. package/dist/cjs/{error-code-mapper.js → errors/error-code-mapper.js} +1 -1
  6. package/dist/cjs/errors/error-types.js +43 -0
  7. package/dist/cjs/helpers/const.js +2 -4
  8. package/dist/cjs/provider/commit-step.js +39 -35
  9. package/dist/cjs/provider/index.js +71 -56
  10. package/dist/cjs/version-wrapper.js +1 -1
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/analytics/index.js +2 -1
  13. package/dist/es2019/analytics/performance.js +1 -0
  14. package/dist/es2019/channel.js +116 -48
  15. package/dist/es2019/{error-code-mapper.js → errors/error-code-mapper.js} +1 -1
  16. package/dist/es2019/errors/error-types.js +13 -0
  17. package/dist/es2019/helpers/const.js +2 -4
  18. package/dist/es2019/provider/commit-step.js +37 -33
  19. package/dist/es2019/provider/index.js +83 -71
  20. package/dist/es2019/version-wrapper.js +1 -1
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/analytics/index.js +2 -1
  23. package/dist/esm/analytics/performance.js +1 -0
  24. package/dist/esm/channel.js +231 -121
  25. package/dist/esm/{error-code-mapper.js → errors/error-code-mapper.js} +1 -1
  26. package/dist/esm/errors/error-types.js +34 -0
  27. package/dist/esm/helpers/const.js +2 -4
  28. package/dist/esm/provider/commit-step.js +39 -35
  29. package/dist/esm/provider/index.js +70 -56
  30. package/dist/esm/version-wrapper.js +1 -1
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/analytics/performance.d.ts +2 -1
  33. package/dist/types/channel.d.ts +5 -0
  34. package/dist/types/{error-code-mapper.d.ts → errors/error-code-mapper.d.ts} +1 -1
  35. package/dist/types/errors/error-types.d.ts +8 -0
  36. package/dist/types/helpers/const.d.ts +29 -6
  37. package/dist/types/provider/index.d.ts +15 -1
  38. package/dist/types/socket-io-provider.d.ts +2 -2
  39. package/dist/types/types.d.ts +18 -3
  40. package/package.json +3 -3
  41. package/report.api.md +21 -4
  42. package/error-code-mapper/package.json +0 -15
@@ -20,39 +20,43 @@ export var commitStep = function commitStep(_ref) {
20
20
  });
21
21
  });
22
22
  var start = new Date().getTime();
23
- channel.broadcast('steps:commit', {
24
- steps: stepsWithClientAndUserId,
25
- version: version,
26
- userId: userId
27
- }, function (response) {
28
- var latency = new Date().getTime() - start;
29
- if (response.type === AcknowledgementResponseTypes.SUCCESS) {
30
- onStepsAdded({
31
- steps: stepsWithClientAndUserId,
32
- version: response.version
33
- });
34
- analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendActionEvent(EVENT_ACTION.ADD_STEPS, EVENT_STATUS.SUCCESS, {
35
- type: ADD_STEPS_TYPE.ACCEPTED,
36
- latency: latency,
37
- stepType: countBy(stepsWithClientAndUserId, function (stepWithClientAndUserId) {
38
- return stepWithClientAndUserId.stepType;
39
- })
40
- });
41
- } else if (response.type === AcknowledgementResponseTypes.ERROR) {
42
- var _response$error, _response$error$data, _response$error2, _response$error2$data;
43
- onErrorHandled(response.error);
44
- analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendActionEvent(EVENT_ACTION.ADD_STEPS, EVENT_STATUS.FAILURE, {
45
- // User tried committing steps but they were rejected because:
46
- // - HEAD_VERSION_UPDATE_FAILED: the collab service's latest stored step tail version didn't correspond to the head version of the first step submitted
47
- // - VERSION_NUMBER_ALREADY_EXISTS: while storing the steps there was a conflict meaning someone else wrote steps into the database more quickly
48
- type: ((_response$error = response.error) === null || _response$error === void 0 ? void 0 : (_response$error$data = _response$error.data) === null || _response$error$data === void 0 ? void 0 : _response$error$data.code) === 'HEAD_VERSION_UPDATE_FAILED' || ((_response$error2 = response.error) === null || _response$error2 === void 0 ? void 0 : (_response$error2$data = _response$error2.data) === null || _response$error2$data === void 0 ? void 0 : _response$error2$data.code) === 'VERSION_NUMBER_ALREADY_EXISTS' ? ADD_STEPS_TYPE.REJECTED : ADD_STEPS_TYPE.ERROR,
49
- latency: latency
50
- });
51
- analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(response.error, 'Error while adding steps - Acknowledgement Error');
52
- } else {
53
- analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(
54
- // @ts-expect-error We didn't type the invalid type case
55
- new Error("Response type: ".concat((response === null || response === void 0 ? void 0 : response.type) || 'No response type')), 'Error while adding steps - Invalid Acknowledgement');
56
- }
57
- });
23
+ try {
24
+ channel.broadcast('steps:commit', {
25
+ steps: stepsWithClientAndUserId,
26
+ version: version,
27
+ userId: userId
28
+ }, function (response) {
29
+ var latency = new Date().getTime() - start;
30
+ if (response.type === AcknowledgementResponseTypes.SUCCESS) {
31
+ onStepsAdded({
32
+ steps: stepsWithClientAndUserId,
33
+ version: response.version
34
+ });
35
+ analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendActionEvent(EVENT_ACTION.ADD_STEPS, EVENT_STATUS.SUCCESS, {
36
+ type: ADD_STEPS_TYPE.ACCEPTED,
37
+ latency: latency,
38
+ stepType: countBy(stepsWithClientAndUserId, function (stepWithClientAndUserId) {
39
+ return stepWithClientAndUserId.stepType;
40
+ })
41
+ });
42
+ } else if (response.type === AcknowledgementResponseTypes.ERROR) {
43
+ var _response$error, _response$error$data, _response$error2, _response$error2$data;
44
+ onErrorHandled(response.error);
45
+ analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendActionEvent(EVENT_ACTION.ADD_STEPS, EVENT_STATUS.FAILURE, {
46
+ // User tried committing steps but they were rejected because:
47
+ // - HEAD_VERSION_UPDATE_FAILED: the collab service's latest stored step tail version didn't correspond to the head version of the first step submitted
48
+ // - VERSION_NUMBER_ALREADY_EXISTS: while storing the steps there was a conflict meaning someone else wrote steps into the database more quickly
49
+ type: ((_response$error = response.error) === null || _response$error === void 0 ? void 0 : (_response$error$data = _response$error.data) === null || _response$error$data === void 0 ? void 0 : _response$error$data.code) === 'HEAD_VERSION_UPDATE_FAILED' || ((_response$error2 = response.error) === null || _response$error2 === void 0 ? void 0 : (_response$error2$data = _response$error2.data) === null || _response$error2$data === void 0 ? void 0 : _response$error2$data.code) === 'VERSION_NUMBER_ALREADY_EXISTS' ? ADD_STEPS_TYPE.REJECTED : ADD_STEPS_TYPE.ERROR,
50
+ latency: latency
51
+ });
52
+ analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(response.error, 'Error while adding steps - Acknowledgement Error');
53
+ } else {
54
+ analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(
55
+ // @ts-expect-error We didn't type the invalid type case
56
+ new Error("Response type: ".concat((response === null || response === void 0 ? void 0 : response.type) || 'No response type')), 'Error while adding steps - Invalid Acknowledgement');
57
+ }
58
+ });
59
+ } catch (error) {
60
+ analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(error, 'Error while adding steps - Broadcast threw exception');
61
+ }
58
62
  };
@@ -23,7 +23,7 @@ import { createLogger, getParticipant, sleep } from '../helpers/utils';
23
23
  import { ACK_MAX_TRY, EVENT_ACTION, EVENT_STATUS } from '../helpers/const';
24
24
  import AnalyticsHelper from '../analytics';
25
25
  import { catchup } from './catchup';
26
- import { ErrorCodeMapper, errorCodeMapper } from '../error-code-mapper';
26
+ import { ErrorCodeMapper, errorCodeMapper } from '../errors/error-code-mapper';
27
27
  import { disconnectedReasonMapper } from '../disconnected-reason-mapper';
28
28
  import { MEASURE_NAME, startMeasure, stopMeasure } from '../analytics/performance';
29
29
  import { commitStep } from './commit-step';
@@ -36,7 +36,7 @@ var CATCHUP_THROTTLE = 1 * 1000; // 1 second
36
36
  var OUT_OF_SYNC_PERIOD = 3 * 1000; // 3 seconds
37
37
  var noop = function noop() {};
38
38
  export var MAX_STEP_REJECTED_ERROR = 15;
39
- var throttledCommitStep = throttle(commitStep, SEND_STEPS_THROTTLE, {
39
+ export var throttledCommitStep = throttle(commitStep, SEND_STEPS_THROTTLE, {
40
40
  leading: false,
41
41
  trailing: true
42
42
  });
@@ -544,68 +544,79 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
544
544
  }
545
545
  });
546
546
  _defineProperty(_assertThisInitialized(_this), "getCurrentState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
547
- var _this$metadata$title, state, adfDocument, _this$analyticsHelper20;
547
+ var _this$metadata$title, _this$analyticsHelper20, state, adfDocument, currentState, measure, _this$analyticsHelper21, _this$analyticsHelper22, _measure;
548
548
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
549
549
  while (1) {
550
550
  switch (_context3.prev = _context3.next) {
551
551
  case 0:
552
552
  _context3.prev = 0;
553
+ startMeasure(MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
554
+
553
555
  // Convert ProseMirror document in Editor state to ADF document
554
556
  state = _this.getState();
555
557
  adfDocument = new JSONTransformer().encode(state.doc);
556
- return _context3.abrupt("return", {
558
+ currentState = {
557
559
  content: adfDocument,
558
560
  title: (_this$metadata$title = _this.metadata.title) === null || _this$metadata$title === void 0 ? void 0 : _this$metadata$title.toString(),
559
561
  stepVersion: getVersion(state)
562
+ };
563
+ measure = stopMeasure(MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
564
+ (_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 ? void 0 : _this$analyticsHelper20.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.SUCCESS, {
565
+ latency: measure === null || measure === void 0 ? void 0 : measure.duration
560
566
  });
561
- case 6:
562
- _context3.prev = 6;
567
+ return _context3.abrupt("return", currentState);
568
+ case 10:
569
+ _context3.prev = 10;
563
570
  _context3.t0 = _context3["catch"](0);
564
- (_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 ? void 0 : _this$analyticsHelper20.sendErrorEvent(_context3.t0, 'Error while returning ADF version of current draft document');
571
+ _measure = stopMeasure(MEASURE_NAME.GET_CURRENT_STATE, _this.analyticsHelper);
572
+ (_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 ? void 0 : _this$analyticsHelper21.sendActionEvent(EVENT_ACTION.GET_CURRENT_STATE, EVENT_STATUS.FAILURE, {
573
+ latency: _measure === null || _measure === void 0 ? void 0 : _measure.duration
574
+ });
575
+ (_this$analyticsHelper22 = _this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 ? void 0 : _this$analyticsHelper22.sendErrorEvent(_context3.t0, 'Error while returning ADF version of current draft document');
565
576
  throw _context3.t0;
566
- case 10:
577
+ case 16:
567
578
  case "end":
568
579
  return _context3.stop();
569
580
  }
570
581
  }
571
- }, _callee3, null, [[0, 6]]);
582
+ }, _callee3, null, [[0, 10]]);
572
583
  })));
573
584
  _defineProperty(_assertThisInitialized(_this), "commitUnconfirmedSteps", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
574
- var count, unconfirmedSteps;
585
+ var unconfirmedSteps, _this$analyticsHelper24, _this$analyticsHelper25, measure;
575
586
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
576
587
  while (1) {
577
588
  switch (_context5.prev = _context5.next) {
578
589
  case 0:
579
- count = 0;
580
590
  unconfirmedSteps = _this.getUnconfirmedSteps();
591
+ _context5.prev = 1;
581
592
  if (!(unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length)) {
582
593
  _context5.next = 4;
583
594
  break;
584
595
  }
585
596
  return _context5.delegateYield( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
586
- var _this$analyticsHelper22;
587
- var unconfirmedTrs, lastTr, isLastTrConfirmed, nextUnconfirmedSteps, nextUnconfirmedTrs, _this$analyticsHelper21, state, _measure, measure;
597
+ var _this$analyticsHelper23;
598
+ var count, unconfirmedTrs, lastTr, isLastTrConfirmed, nextUnconfirmedSteps, nextUnconfirmedTrs, state, measure;
588
599
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
589
600
  while (1) {
590
601
  switch (_context4.prev = _context4.next) {
591
602
  case 0:
592
603
  startMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
593
- // We use origins here as steps can be rebased. When steps are rebased a new step is created.
604
+ count = 0; // We use origins here as steps can be rebased. When steps are rebased a new step is created.
594
605
  // This means that we can not track if it has been removed from the unconfirmed array or not.
595
606
  // Origins points to the original transaction that the step was created in. This is never changed
596
607
  // and gets passed down when a step is rebased.
597
608
  unconfirmedTrs = _this.getUnconfirmedStepsOrigins();
598
609
  lastTr = unconfirmedTrs === null || unconfirmedTrs === void 0 ? void 0 : unconfirmedTrs[unconfirmedTrs.length - 1];
599
610
  isLastTrConfirmed = false;
600
- case 4:
611
+ case 5:
601
612
  if (isLastTrConfirmed) {
602
- _context4.next = 17;
613
+ _context4.next = 16;
603
614
  break;
604
615
  }
605
616
  _this.sendStepsFromCurrentState();
606
- _context4.next = 8;
617
+ _context4.next = 9;
607
618
  return sleep(1000);
608
- case 8:
619
+ case 9:
609
620
  nextUnconfirmedSteps = _this.getUnconfirmedSteps();
610
621
  if (nextUnconfirmedSteps !== null && nextUnconfirmedSteps !== void 0 && nextUnconfirmedSteps.length) {
611
622
  nextUnconfirmedTrs = _this.getUnconfirmedStepsOrigins();
@@ -616,7 +627,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
616
627
  isLastTrConfirmed = true;
617
628
  }
618
629
  if (!(!isLastTrConfirmed && count++ >= ACK_MAX_TRY)) {
619
- _context4.next = 15;
630
+ _context4.next = 14;
620
631
  break;
621
632
  }
622
633
  if (_this.onSyncUpError) {
@@ -629,24 +640,18 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
629
640
  version: getVersion(state)
630
641
  });
631
642
  }
632
- _measure = stopMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
633
- (_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 ? void 0 : _this$analyticsHelper21.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.FAILURE, {
634
- latency: _measure === null || _measure === void 0 ? void 0 : _measure.duration,
635
- // upon failure, emit the number of unconfirmed steps we attempted to sync
636
- numUnconfirmedSteps: nextUnconfirmedSteps === null || nextUnconfirmedSteps === void 0 ? void 0 : nextUnconfirmedSteps.length
637
- });
638
643
  throw new Error("Can't sync up with Collab Service");
639
- case 15:
640
- _context4.next = 4;
644
+ case 14:
645
+ _context4.next = 5;
641
646
  break;
642
- case 17:
647
+ case 16:
643
648
  measure = stopMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
644
- (_this$analyticsHelper22 = _this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 ? void 0 : _this$analyticsHelper22.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.SUCCESS, {
649
+ (_this$analyticsHelper23 = _this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 ? void 0 : _this$analyticsHelper23.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.SUCCESS, {
645
650
  latency: measure === null || measure === void 0 ? void 0 : measure.duration,
646
651
  // upon success, emit the total number of unconfirmed steps we synced
647
652
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
648
653
  });
649
- case 19:
654
+ case 18:
650
655
  case "end":
651
656
  return _context4.stop();
652
657
  }
@@ -654,53 +659,60 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
654
659
  }, _callee4);
655
660
  })(), "t0", 4);
656
661
  case 4:
662
+ _context5.next = 12;
663
+ break;
664
+ case 6:
665
+ _context5.prev = 6;
666
+ _context5.t1 = _context5["catch"](1);
667
+ measure = stopMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
668
+ (_this$analyticsHelper24 = _this.analyticsHelper) === null || _this$analyticsHelper24 === void 0 ? void 0 : _this$analyticsHelper24.sendActionEvent(EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, EVENT_STATUS.FAILURE, {
669
+ latency: measure === null || measure === void 0 ? void 0 : measure.duration,
670
+ numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
671
+ });
672
+ (_this$analyticsHelper25 = _this.analyticsHelper) === null || _this$analyticsHelper25 === void 0 ? void 0 : _this$analyticsHelper25.sendErrorEvent(_context5.t1, 'Error while committing unconfirmed steps');
673
+ throw _context5.t1;
674
+ case 12:
657
675
  case "end":
658
676
  return _context5.stop();
659
677
  }
660
678
  }
661
- }, _callee5);
679
+ }, _callee5, null, [[1, 6]]);
662
680
  })));
663
681
  _defineProperty(_assertThisInitialized(_this), "getFinalAcknowledgedState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
664
- var _this$analyticsHelper23, currentState, measure, _this$analyticsHelper24, _this$analyticsHelper25, _this$metadata$title2, _measure2;
682
+ var _this$analyticsHelper26, currentState, measure, _this$analyticsHelper27, _this$analyticsHelper28, _measure2;
665
683
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
666
684
  while (1) {
667
685
  switch (_context6.prev = _context6.next) {
668
686
  case 0:
669
- // Moved these out of the try catch to maintain the current logic for throwing / not throwing errors
687
+ _context6.prev = 0;
670
688
  startMeasure(MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
671
- _context6.next = 3;
689
+ _context6.next = 4;
672
690
  return _this.commitUnconfirmedSteps();
673
- case 3:
674
- _context6.prev = 3;
691
+ case 4:
675
692
  _context6.next = 6;
676
693
  return _this.getCurrentState();
677
694
  case 6:
678
695
  currentState = _context6.sent;
679
696
  measure = stopMeasure(MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
680
- (_this$analyticsHelper23 = _this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 ? void 0 : _this$analyticsHelper23.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.SUCCESS, {
697
+ (_this$analyticsHelper26 = _this.analyticsHelper) === null || _this$analyticsHelper26 === void 0 ? void 0 : _this$analyticsHelper26.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.SUCCESS, {
681
698
  latency: measure === null || measure === void 0 ? void 0 : measure.duration
682
699
  });
683
700
  return _context6.abrupt("return", currentState);
684
701
  case 12:
685
702
  _context6.prev = 12;
686
- _context6.t0 = _context6["catch"](3);
687
- _measure2 = stopMeasure(MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
688
- (_this$analyticsHelper24 = _this.analyticsHelper) === null || _this$analyticsHelper24 === void 0 ? void 0 : _this$analyticsHelper24.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.FAILURE, {
703
+ _context6.t0 = _context6["catch"](0);
704
+ _measure2 = stopMeasure(MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
705
+ (_this$analyticsHelper27 = _this.analyticsHelper) === null || _this$analyticsHelper27 === void 0 ? void 0 : _this$analyticsHelper27.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.FAILURE, {
689
706
  latency: _measure2 === null || _measure2 === void 0 ? void 0 : _measure2.duration
690
707
  });
691
- (_this$analyticsHelper25 = _this.analyticsHelper) === null || _this$analyticsHelper25 === void 0 ? void 0 : _this$analyticsHelper25.sendErrorEvent(_context6.t0, 'Error while returning ADF version of the final draft document');
692
- // TODO: We should likely throw here after we stop using this for draft sync, there is no way of knowing what happened otherwise, but this is what it was doing before
693
- return _context6.abrupt("return", {
694
- content: undefined,
695
- title: (_this$metadata$title2 = _this.metadata.title) === null || _this$metadata$title2 === void 0 ? void 0 : _this$metadata$title2.toString(),
696
- stepVersion: getVersion(_this.getState())
697
- });
708
+ (_this$analyticsHelper28 = _this.analyticsHelper) === null || _this$analyticsHelper28 === void 0 ? void 0 : _this$analyticsHelper28.sendErrorEvent(_context6.t0, 'Error while returning ADF version of the final draft document');
709
+ throw _context6.t0;
698
710
  case 18:
699
711
  case "end":
700
712
  return _context6.stop();
701
713
  }
702
714
  }
703
- }, _callee6, null, [[3, 12]]);
715
+ }, _callee6, null, [[0, 12]]);
704
716
  })));
705
717
  _defineProperty(_assertThisInitialized(_this), "onNamespaceStatusChanged", /*#__PURE__*/function () {
706
718
  var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(data) {
@@ -780,8 +792,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
780
792
  this.isChannelInitialized = true;
781
793
  }
782
794
  } catch (initError) {
783
- var _this$analyticsHelper26;
784
- (_this$analyticsHelper26 = this.analyticsHelper) === null || _this$analyticsHelper26 === void 0 ? void 0 : _this$analyticsHelper26.sendErrorEvent(initError, 'Error while initialising the provider');
795
+ var _this$analyticsHelper29;
796
+ (_this$analyticsHelper29 = this.analyticsHelper) === null || _this$analyticsHelper29 === void 0 ? void 0 : _this$analyticsHelper29.sendErrorEvent(initError, 'Error while initialising the provider');
785
797
  // Throw error so consumers are aware the initialisation failed when initialising themselves
786
798
  throw initError;
787
799
  }
@@ -904,9 +916,9 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
904
916
  }, 100);
905
917
  }
906
918
  } catch (error) {
907
- var _this$analyticsHelper27;
919
+ var _this$analyticsHelper30;
908
920
  logger("Processing steps failed with error: ".concat(error, ". Triggering catch up call."));
909
- (_this$analyticsHelper27 = this.analyticsHelper) === null || _this$analyticsHelper27 === void 0 ? void 0 : _this$analyticsHelper27.sendErrorEvent(error, 'Error while processing steps');
921
+ (_this$analyticsHelper30 = this.analyticsHelper) === null || _this$analyticsHelper30 === void 0 ? void 0 : _this$analyticsHelper30.sendErrorEvent(error, 'Error while processing steps');
910
922
  this.throttledCatchup();
911
923
  }
912
924
  }
@@ -929,9 +941,9 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
929
941
  var callback = telepointerCallback(this.config.documentAri);
930
942
  this.channel.broadcast('participant:telepointer', payload, callback);
931
943
  } catch (error) {
932
- var _this$analyticsHelper28;
944
+ var _this$analyticsHelper31;
933
945
  // We don't want to throw errors for Presence features as they tend to self-restore
934
- (_this$analyticsHelper28 = this.analyticsHelper) === null || _this$analyticsHelper28 === void 0 ? void 0 : _this$analyticsHelper28.sendErrorEvent(error, 'Error while sending message - telepointer');
946
+ (_this$analyticsHelper31 = this.analyticsHelper) === null || _this$analyticsHelper31 === void 0 ? void 0 : _this$analyticsHelper31.sendErrorEvent(error, 'Error while sending message - telepointer');
935
947
  }
936
948
  }
937
949
  }
@@ -947,11 +959,13 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
947
959
  }
948
960
  });
949
961
  } catch (error) {
950
- var _this$analyticsHelper29;
962
+ var _this$analyticsHelper32;
951
963
  // We don't want to throw errors for Presence features as they tend to self-restore
952
- (_this$analyticsHelper29 = this.analyticsHelper) === null || _this$analyticsHelper29 === void 0 ? void 0 : _this$analyticsHelper29.sendErrorEvent(error, 'Error while emitting telepointers from steps');
964
+ (_this$analyticsHelper32 = this.analyticsHelper) === null || _this$analyticsHelper32 === void 0 ? void 0 : _this$analyticsHelper32.sendErrorEvent(error, 'Error while emitting telepointers from steps');
953
965
  }
954
966
  }
967
+
968
+ // Note: this gets triggered on page reload for Firefox (not other browsers) because of closeOnBeforeunload: false
955
969
  }, {
956
970
  key: "destroy",
957
971
  value: function destroy() {
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/collab-provider";
2
- export var version = "8.3.0";
2
+ export var version = "8.4.0";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "8.3.0",
3
+ "version": "8.4.0",
4
4
  "sideEffects": false
5
5
  }
@@ -3,7 +3,8 @@ export declare enum MEASURE_NAME {
3
3
  SOCKET_CONNECT = "socketConnect",
4
4
  DOCUMENT_INIT = "documentInit",
5
5
  COMMIT_UNCONFIRMED_STEPS = "commitUnconfirmedSteps",
6
- PUBLISH_PAGE = "publishPage"
6
+ PUBLISH_PAGE = "publishPage",
7
+ GET_CURRENT_STATE = "getCurrentState"
7
8
  }
8
9
  export declare function startMeasure(measureName: MEASURE_NAME, analyticsHelper: AnalyticsHelper | undefined): void;
9
10
  export declare function stopMeasure(measureName: MEASURE_NAME, analyticsHelper: AnalyticsHelper | undefined, onMeasureComplete?: (duration: number, startTime: number) => void): {
@@ -10,15 +10,20 @@ export declare class Channel extends Emitter<ChannelEvent> {
10
10
  private initialized;
11
11
  private analyticsHelper?;
12
12
  private initExperience?;
13
+ private token?;
13
14
  private network;
14
15
  constructor(config: Config, analyticsHelper: AnalyticsHelper);
15
16
  getInitialized: () => boolean;
16
17
  getConnected: () => boolean;
17
18
  getSocket: () => Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap> | null;
19
+ getToken: () => string | undefined;
20
+ private setToken;
21
+ private unsetToken;
18
22
  /**
19
23
  * Connect to collab service using websockets
20
24
  */
21
25
  connect(): void;
26
+ private handlePermissionInvalidateToken;
22
27
  private onConnectError;
23
28
  private onReconnectError;
24
29
  private onConnect;
@@ -1,4 +1,4 @@
1
- import type { CollabErrorPayload, ErrorPayload } from './types';
1
+ import type { CollabErrorPayload, ErrorPayload } from '../types';
2
2
  export declare const ErrorCodeMapper: {
3
3
  noPermissionError: {
4
4
  code: string;
@@ -0,0 +1,8 @@
1
+ export declare class NotConnectedError extends Error {
2
+ name: string;
3
+ constructor(message: string);
4
+ }
5
+ export declare class NotInitializedError extends Error {
6
+ name: string;
7
+ constructor(message: string);
8
+ }
@@ -1,18 +1,16 @@
1
1
  import type { CollabErrorPayload } from '../types';
2
2
  export declare enum EVENT_ACTION {
3
3
  CONNECTION = "connection",
4
- RECONNECTION = "reconnection",
5
4
  CATCHUP = "catchup",
6
5
  DOCUMENT_INIT = "documentInit",
7
6
  ADD_STEPS = "addSteps",
8
7
  UPDATE_PARTICIPANTS = "updateParticipants",
9
8
  COMMIT_UNCONFIRMED_STEPS = "commitUnconfirmedSteps",
10
9
  REINITIALISE_DOCUMENT = "reinitialiseDocument",
11
- INIT_PROVIDER = "initProvider",
12
10
  ERROR = "error",
13
- MEASURE_PERFORMANCE = "measurePerformance",
14
- INIT_UFO_EXPERIENCE = "initUFOExperience",
15
- PUBLISH_PAGE = "publishPage"
11
+ PUBLISH_PAGE = "publishPage",
12
+ GET_CURRENT_STATE = "getCurrentState",
13
+ INVALIDATE_TOKEN = "invalidateToken"
16
14
  }
17
15
  export declare enum EVENT_STATUS {
18
16
  SUCCESS = "SUCCESS",
@@ -27,6 +25,7 @@ export declare type ErrorAnalyticsEvent = {
27
25
  eventAction: EVENT_ACTION.ERROR;
28
26
  attributes: {
29
27
  errorMessage: string;
28
+ errorName?: string;
30
29
  documentAri?: string;
31
30
  mappedError?: CollabErrorPayload;
32
31
  };
@@ -34,6 +33,14 @@ export declare type ErrorAnalyticsEvent = {
34
33
  error: unknown;
35
34
  };
36
35
  };
36
+ declare type InvalidateTokenAnalyticsEvent = {
37
+ eventAction: EVENT_ACTION.INVALIDATE_TOKEN;
38
+ attributes: {
39
+ eventStatus: EVENT_STATUS.SUCCESS;
40
+ reason?: string;
41
+ usedCachedToken?: boolean;
42
+ };
43
+ };
37
44
  declare type AddStepsSuccessAnalyticsEvent = {
38
45
  eventAction: EVENT_ACTION.ADD_STEPS;
39
46
  attributes: {
@@ -155,7 +162,23 @@ declare type PublishPageFailureAnalyticsEvent = {
155
162
  latency?: number;
156
163
  };
157
164
  };
158
- export declare type ActionAnalyticsEvent = AddStepsSuccessAnalyticsEvent | AddStepsFailureAnalyticsEvent | ReInitDocFailAnalyticsEvent | ReInitDocSuccessAnalyticsEvent | ConnectionSuccessAnalyticsEvent | ConnectionFailureAnalyticsEvent | CatchUpSuccessAnalyticsEvent | CatchUpFailureAnalyticsEvent | DocumentInitSuccessAnalyticsEvent | UpdateParticipantsSuccessAnalyticsEvent | CommitUnconfirmedStepsSuccessAnalyticsEvent | CommitUnconfirmedStepsFailureAnalyticsEvent | PublishPageSuccessAnalyticsEvent | PublishPageFailureAnalyticsEvent;
165
+ declare type GetCurrentStateSuccessAnalyticsEvent = {
166
+ eventAction: EVENT_ACTION.GET_CURRENT_STATE;
167
+ attributes: {
168
+ documentAri: string;
169
+ eventStatus: EVENT_STATUS.SUCCESS;
170
+ latency?: number;
171
+ };
172
+ };
173
+ declare type GetCurrentStateFailureAnalyticsEvent = {
174
+ eventAction: EVENT_ACTION.GET_CURRENT_STATE;
175
+ attributes: {
176
+ documentAri: string;
177
+ eventStatus: EVENT_STATUS.FAILURE;
178
+ latency?: number;
179
+ };
180
+ };
181
+ export declare type ActionAnalyticsEvent = AddStepsSuccessAnalyticsEvent | AddStepsFailureAnalyticsEvent | ReInitDocFailAnalyticsEvent | ReInitDocSuccessAnalyticsEvent | ConnectionSuccessAnalyticsEvent | ConnectionFailureAnalyticsEvent | CatchUpSuccessAnalyticsEvent | CatchUpFailureAnalyticsEvent | DocumentInitSuccessAnalyticsEvent | UpdateParticipantsSuccessAnalyticsEvent | CommitUnconfirmedStepsSuccessAnalyticsEvent | CommitUnconfirmedStepsFailureAnalyticsEvent | PublishPageSuccessAnalyticsEvent | PublishPageFailureAnalyticsEvent | GetCurrentStateSuccessAnalyticsEvent | GetCurrentStateFailureAnalyticsEvent | InvalidateTokenAnalyticsEvent;
159
182
  export declare const ACK_MAX_TRY = 30;
160
183
  export declare const CONFLUENCE = "confluence";
161
184
  export {};
@@ -1,9 +1,23 @@
1
+ /// <reference types="lodash" />
1
2
  import type { EditorState, Transaction } from 'prosemirror-state';
3
+ import type { Step as ProseMirrorStep } from 'prosemirror-transform';
2
4
  import { Emitter } from '../emitter';
5
+ import { Channel } from '../channel';
3
6
  import type { CollabEditProvider, CollabParticipant, ResolvedEditorState } from '@atlaskit/editor-common/collab';
4
- import type { CollabEvents, Config, Metadata } from '../types';
7
+ import type { CollabEvents, Config, ErrorPayload, Metadata, StepsPayload } from '../types';
8
+ import AnalyticsHelper from '../analytics';
5
9
  import type { SyncUpErrorFunction } from '@atlaskit/editor-common/types';
6
10
  export declare const MAX_STEP_REJECTED_ERROR = 15;
11
+ export declare const throttledCommitStep: import("lodash").DebouncedFunc<({ channel, steps, version, userId, clientId, onStepsAdded, onErrorHandled, analyticsHelper, }: {
12
+ channel: Channel;
13
+ steps: readonly ProseMirrorStep<any>[];
14
+ version: number;
15
+ userId: string;
16
+ clientId: string | number;
17
+ onStepsAdded: (data: StepsPayload) => void;
18
+ onErrorHandled: (error: ErrorPayload) => void;
19
+ analyticsHelper?: AnalyticsHelper | undefined;
20
+ }) => void>;
7
21
  declare type BaseEvents = Pick<CollabEditProvider<CollabEvents>, 'setup' | 'send' | 'sendMessage'>;
8
22
  export declare type ParticipantsMap = Map<string, CollabParticipant & {
9
23
  userId: string;
@@ -1,5 +1,5 @@
1
1
  import { Provider } from './provider';
2
2
  import { Socket } from 'socket.io-client';
3
- import { Config, ProductInformation } from './types';
4
- export declare function createSocketIOSocket(url: string, auth?: (cb: (data: object) => void) => void, productInfo?: ProductInformation): Socket;
3
+ import { Config, ProductInformation, InitAndAuthData, AuthCallback } from './types';
4
+ export declare function createSocketIOSocket(url: string, auth?: AuthCallback | InitAndAuthData, productInfo?: ProductInformation): Socket;
5
5
  export declare function createSocketIOCollabProvider(config: Omit<Config, 'createSocket'>): Provider;
@@ -15,7 +15,7 @@ export interface Config {
15
15
  lifecycle?: Lifecycle;
16
16
  storage?: Storage;
17
17
  need404?: boolean;
18
- createSocket: (path: string, auth?: (cb: (data: object) => void) => void, productInfo?: ProductInformation) => Socket;
18
+ createSocket: (path: string, auth?: AuthCallback | InitAndAuthData, productInfo?: ProductInformation) => Socket;
19
19
  analyticsClient?: AnalyticsWebClient;
20
20
  featureFlags?: {
21
21
  [key: string]: boolean;
@@ -23,9 +23,24 @@ export interface Config {
23
23
  getUser?(userId: string): Promise<Pick<CollabParticipant, 'avatar' | 'email' | 'name'> & {
24
24
  userId: string;
25
25
  }>;
26
+ /**
27
+ * If provided, permissionTokenRefresh is called whenever a new JWT token is required.
28
+ */
26
29
  permissionTokenRefresh?: () => Promise<string | null>;
30
+ cacheToken?: boolean;
27
31
  productInfo?: ProductInformation;
32
+ /**
33
+ * Throws errors when trying to send data to collab but the client is not offline.
34
+ * This can lead to potential dataloss and retrying should be considered. Without this flag the provider silently drops the requests.
35
+ */
36
+ throwOnNotConnected?: boolean;
28
37
  }
38
+ export interface InitAndAuthData {
39
+ initialized: boolean;
40
+ need404?: boolean;
41
+ token?: string;
42
+ }
43
+ export declare type AuthCallback = (cb: (data: InitAndAuthData) => void) => void;
29
44
  interface SimpleEventEmitter {
30
45
  on(event: string, fn: Function): SimpleEventEmitter;
31
46
  }
@@ -127,14 +142,14 @@ declare type SliceJson = {
127
142
  openEnd: number;
128
143
  };
129
144
  export declare type StepJson = {
145
+ stepType?: string;
130
146
  from?: number;
131
147
  to?: number;
132
- stepType?: string;
148
+ slice?: SliceJson;
133
149
  clientId: number | string;
134
150
  userId: string;
135
151
  createdAt?: number;
136
152
  structure?: boolean;
137
- slice?: SliceJson;
138
153
  };
139
154
  export declare enum AcknowledgementResponseTypes {
140
155
  SUCCESS = "SUCCESS",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "8.3.0",
3
+ "version": "8.4.0",
4
4
  "description": "A provider for collaborative editing.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@atlaskit/analytics-gas-types": "^5.0.10",
25
25
  "@atlaskit/analytics-listeners": "^8.5.0",
26
- "@atlaskit/editor-common": "^72.5.0",
26
+ "@atlaskit/editor-common": "^72.6.0",
27
27
  "@atlaskit/editor-json-transformer": "^8.8.0",
28
28
  "@atlaskit/prosemirror-collab": "^0.1.0",
29
29
  "@atlaskit/ufo": "^0.1.4",
@@ -51,7 +51,7 @@
51
51
  "devDependencies": {
52
52
  "@atlaskit/adf-schema": "^25.3.0",
53
53
  "@atlaskit/analytics-listeners": "^8.5.0",
54
- "@atlaskit/editor-test-helpers": "^18.0.0",
54
+ "@atlaskit/editor-test-helpers": "^18.1.0",
55
55
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
56
56
  "@types/prosemirror-model": "^1.11.0",
57
57
  "@types/prosemirror-state": "^1.2.0",