@atlaskit/collab-provider 9.37.7 → 9.38.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,26 @@
1
1
  # @atlaskit/collab-provider
2
2
 
3
+ ## 9.38.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#136958](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/136958)
8
+ [`e1fd99410b2a7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e1fd99410b2a7) -
9
+ Adding reasons for BE catchup calls
10
+ - Updated dependencies
11
+
12
+ ## 9.38.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#137505](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/137505)
17
+ [`ed3b11d42c169`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ed3b11d42c169) -
18
+ add ability to target a clientId for restore
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies
23
+
3
24
  ## 9.37.7
4
25
 
5
26
  ### Patch Changes
@@ -305,7 +305,7 @@ var Channel = exports.Channel = /*#__PURE__*/function (_Emitter) {
305
305
  };
306
306
  }());
307
307
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "fetchCatchupv2", /*#__PURE__*/function () {
308
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(fromVersion, clientId, catchUpOutofSync) {
308
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(fromVersion, clientId, catchUpOutofSync, reason) {
309
309
  var _yield$utils$requestS2, steps, metadata, errorNotFound, errorCatchupv2;
310
310
  return _regenerator.default.wrap(function _callee3$(_context3) {
311
311
  while (1) switch (_context3.prev = _context3.next) {
@@ -317,7 +317,8 @@ var Channel = exports.Channel = /*#__PURE__*/function (_Emitter) {
317
317
  _context3.t3 = {
318
318
  version: fromVersion,
319
319
  clientId: clientId,
320
- catchUpOutofSync: catchUpOutofSync
320
+ catchUpOutofSync: catchUpOutofSync,
321
+ reason: reason
321
322
  };
322
323
  _context3.next = 7;
323
324
  return _this.commonHeaders();
@@ -374,7 +375,7 @@ var Channel = exports.Channel = /*#__PURE__*/function (_Emitter) {
374
375
  }
375
376
  }, _callee3, null, [[0, 18]]);
376
377
  }));
377
- return function (_x3, _x4, _x5) {
378
+ return function (_x3, _x4, _x5, _x6) {
378
379
  return _ref3.apply(this, arguments);
379
380
  };
380
381
  }());
@@ -432,7 +433,7 @@ var Channel = exports.Channel = /*#__PURE__*/function (_Emitter) {
432
433
  }
433
434
  }, _callee4, null, [[0, 24]]);
434
435
  }));
435
- return function (_x6, _x7) {
436
+ return function (_x7, _x8) {
436
437
  return _ref4.apply(this, arguments);
437
438
  };
438
439
  }());
@@ -567,7 +568,7 @@ var Channel = exports.Channel = /*#__PURE__*/function (_Emitter) {
567
568
  }
568
569
  }, _callee5, null, [[1, 9]]);
569
570
  }));
570
- return function auth(_x8) {
571
+ return function auth(_x9) {
571
572
  return _ref5.apply(this, arguments);
572
573
  };
573
574
  }();
@@ -592,7 +593,7 @@ var Channel = exports.Channel = /*#__PURE__*/function (_Emitter) {
592
593
  }
593
594
  }, _callee6);
594
595
  }));
595
- return function auth(_x9) {
596
+ return function auth(_x10) {
596
597
  return _ref6.apply(this, arguments);
597
598
  };
598
599
  }();
@@ -687,7 +688,7 @@ var Channel = exports.Channel = /*#__PURE__*/function (_Emitter) {
687
688
  }
688
689
  }, _callee7);
689
690
  }));
690
- return function (_x10) {
691
+ return function (_x11) {
691
692
  return _ref11.apply(this, arguments);
692
693
  };
693
694
  }());
@@ -18,7 +18,7 @@ var catchupv2 = exports.catchupv2 = /*#__PURE__*/function () {
18
18
  fromVersion = opt.getCurrentPmVersion();
19
19
  _context.prev = 1;
20
20
  _context.next = 4;
21
- return opt.fetchCatchupv2(fromVersion, opt.clientId, opt.catchUpOutofSync);
21
+ return opt.fetchCatchupv2(fromVersion, opt.clientId, opt.catchUpOutofSync, opt.reason);
22
22
  case 4:
23
23
  _yield$opt$fetchCatch = _context.sent;
24
24
  steps = _yield$opt$fetchCatch.steps;
@@ -129,9 +129,10 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
129
129
  })));
130
130
  /**
131
131
  * To prevent calling catchup to often, use lodash throttle to reduce the frequency
132
+ * @param reason - optional reason to attach.
132
133
  */
133
- (0, _defineProperty2.default)(this, "throttledCatchupv2", (0, _throttle.default)(function () {
134
- return _this.catchupv2();
134
+ (0, _defineProperty2.default)(this, "throttledCatchupv2", (0, _throttle.default)(function (reason) {
135
+ return _this.catchupv2(reason);
135
136
  }, CATCHUP_THROTTLE, {
136
137
  leading: false,
137
138
  // TODO: why shouldn't this be leading?
@@ -141,67 +142,74 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
141
142
  * Called when:
142
143
  * * session established(offline -> online)
143
144
  * * try to accept steps but version is behind.
145
+ * @param reason - optional reason to attach.
144
146
  */
145
- (0, _defineProperty2.default)(this, "catchupv2", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
146
- var start, _this$analyticsHelper3, latency, _this$analyticsHelper4, _latency2;
147
- return _regenerator.default.wrap(function _callee2$(_context2) {
148
- while (1) switch (_context2.prev = _context2.next) {
149
- case 0:
150
- start = new Date().getTime(); // if the queue is already paused, we are busy with something else, so don't proceed.
151
- if (!_this.stepQueue.isPaused()) {
152
- _context2.next = 4;
153
- break;
154
- }
155
- logger("Queue is paused. Aborting.");
156
- return _context2.abrupt("return");
157
- case 4:
158
- if (!_this.isNameSpaceLocked()) {
159
- _context2.next = 7;
147
+ (0, _defineProperty2.default)(this, "catchupv2", /*#__PURE__*/function () {
148
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(reason) {
149
+ var start, _this$analyticsHelper3, latency, _this$analyticsHelper4, _latency2;
150
+ return _regenerator.default.wrap(function _callee2$(_context2) {
151
+ while (1) switch (_context2.prev = _context2.next) {
152
+ case 0:
153
+ start = new Date().getTime(); // if the queue is already paused, we are busy with something else, so don't proceed.
154
+ if (!_this.stepQueue.isPaused()) {
155
+ _context2.next = 4;
156
+ break;
157
+ }
158
+ logger("Queue is paused. Aborting.");
159
+ return _context2.abrupt("return");
160
+ case 4:
161
+ if (!_this.isNameSpaceLocked()) {
162
+ _context2.next = 7;
163
+ break;
164
+ }
165
+ logger("catchupv2: Document is locked. Aborting.");
166
+ return _context2.abrupt("return");
167
+ case 7:
168
+ _this.stepQueue.pauseQueue();
169
+ _context2.prev = 8;
170
+ _context2.next = 11;
171
+ return (0, _catchupv.catchupv2)({
172
+ getCurrentPmVersion: _this.getCurrentPmVersion,
173
+ fetchCatchupv2: _this.fetchCatchupv2,
174
+ updateMetadata: _this.metadataService.updateMetadata,
175
+ analyticsHelper: _this.analyticsHelper,
176
+ clientId: _this.clientId,
177
+ onStepsAdded: _this.onStepsAdded,
178
+ catchUpOutofSync: _this.catchUpOutofSync,
179
+ reason: reason
180
+ });
181
+ case 11:
182
+ _this.catchUpOutofSync = _context2.sent;
183
+ latency = new Date().getTime() - start;
184
+ (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 || _this$analyticsHelper3.sendActionEvent(_const.EVENT_ACTION.CATCHUP, _const.EVENT_STATUS.SUCCESS, {
185
+ latency: latency
186
+ });
187
+ _context2.next = 20;
160
188
  break;
161
- }
162
- logger("catchupv2: Document is locked. Aborting.");
163
- return _context2.abrupt("return");
164
- case 7:
165
- _this.stepQueue.pauseQueue();
166
- _context2.prev = 8;
167
- _context2.next = 11;
168
- return (0, _catchupv.catchupv2)({
169
- getCurrentPmVersion: _this.getCurrentPmVersion,
170
- fetchCatchupv2: _this.fetchCatchupv2,
171
- updateMetadata: _this.metadataService.updateMetadata,
172
- analyticsHelper: _this.analyticsHelper,
173
- clientId: _this.clientId,
174
- onStepsAdded: _this.onStepsAdded,
175
- catchUpOutofSync: _this.catchUpOutofSync
176
- });
177
- case 11:
178
- _this.catchUpOutofSync = _context2.sent;
179
- latency = new Date().getTime() - start;
180
- (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 || _this$analyticsHelper3.sendActionEvent(_const.EVENT_ACTION.CATCHUP, _const.EVENT_STATUS.SUCCESS, {
181
- latency: latency
182
- });
183
- _context2.next = 20;
184
- break;
185
- case 16:
186
- _context2.prev = 16;
187
- _context2.t0 = _context2["catch"](8);
188
- _latency2 = new Date().getTime() - start;
189
- (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendActionEvent(_const.EVENT_ACTION.CATCHUP, _const.EVENT_STATUS.FAILURE, {
190
- latency: _latency2
191
- });
192
- case 20:
193
- _context2.prev = 20;
194
- _this.stepQueue.resumeQueue();
195
- _this.processQueue();
196
- _this.sendStepsFromCurrentState(); // this will eventually retry catchup as it calls throttledCommitStep which will either catchup on onStepsAdded or onErrorHandled
197
- _this.stepRejectCounter = 0;
198
- return _context2.finish(20);
199
- case 26:
200
- case "end":
201
- return _context2.stop();
202
- }
203
- }, _callee2, null, [[8, 16, 20, 26]]);
204
- })));
189
+ case 16:
190
+ _context2.prev = 16;
191
+ _context2.t0 = _context2["catch"](8);
192
+ _latency2 = new Date().getTime() - start;
193
+ (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendActionEvent(_const.EVENT_ACTION.CATCHUP, _const.EVENT_STATUS.FAILURE, {
194
+ latency: _latency2
195
+ });
196
+ case 20:
197
+ _context2.prev = 20;
198
+ _this.stepQueue.resumeQueue();
199
+ _this.processQueue();
200
+ _this.sendStepsFromCurrentState(); // this will eventually retry catchup as it calls throttledCommitStep which will either catchup on onStepsAdded or onErrorHandled
201
+ _this.stepRejectCounter = 0;
202
+ return _context2.finish(20);
203
+ case 26:
204
+ case "end":
205
+ return _context2.stop();
206
+ }
207
+ }, _callee2, null, [[8, 16, 20, 26]]);
208
+ }));
209
+ return function (_x) {
210
+ return _ref2.apply(this, arguments);
211
+ };
212
+ }());
205
213
  (0, _defineProperty2.default)(this, "getCurrentPmVersion", function () {
206
214
  var _this$getState;
207
215
  var state = (_this$getState = _this.getState) === null || _this$getState === void 0 ? void 0 : _this$getState.call(_this);
@@ -299,7 +307,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
299
307
  } else if (data.version > expectedVersion) {
300
308
  logger("Version too high. Expected \"".concat(expectedVersion, "\" but got \"").concat(data.version, ". Current local version is ").concat(currentVersion, "."));
301
309
  _this.stepQueue.queueSteps(data);
302
- _this.throttledCatchupv2();
310
+ _this.throttledCatchupv2(_const.CatchupEventReason.STEPS_ADDED);
303
311
  }
304
312
  _this.participantsService.updateLastActive(data.steps.map(function (_ref4) {
305
313
  var userId = _ref4.userId;
@@ -321,20 +329,26 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
321
329
  // Triggered when page recovery has emitted an 'init' event on a page client is currently connected to.
322
330
  (0, _defineProperty2.default)(this, "onRestore", /*#__PURE__*/function () {
323
331
  var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(_ref5) {
324
- var doc, version, metadata, unconfirmedSteps, currentState, useReconcile, _this$analyticsHelper13, _this$analyticsHelper14, _this$analyticsHelper15;
332
+ var doc, version, metadata, targetClientId, unconfirmedSteps, currentState, useReconcile, _this$analyticsHelper13, _this$analyticsHelper14, _this$analyticsHelper15;
325
333
  return _regenerator.default.wrap(function _callee4$(_context4) {
326
334
  while (1) switch (_context4.prev = _context4.next) {
327
335
  case 0:
328
- doc = _ref5.doc, version = _ref5.version, metadata = _ref5.metadata;
336
+ doc = _ref5.doc, version = _ref5.version, metadata = _ref5.metadata, targetClientId = _ref5.targetClientId;
337
+ if (!(targetClientId && _this.clientId !== targetClientId)) {
338
+ _context4.next = 3;
339
+ break;
340
+ }
341
+ return _context4.abrupt("return");
342
+ case 3:
329
343
  // We preserve these as they will be lost apon this.updateDocument. This is because we are using document recovery.
330
344
  // We can then reconcile the document with the preserved state.
331
345
  unconfirmedSteps = _this.getUnconfirmedSteps();
332
- _context4.next = 4;
346
+ _context4.next = 6;
333
347
  return _this.getCurrentState();
334
- case 4:
348
+ case 6:
335
349
  currentState = _context4.sent;
336
350
  useReconcile = Boolean((unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length) && currentState);
337
- _context4.prev = 6;
351
+ _context4.prev = 8;
338
352
  // Reset the editor,
339
353
  // - Replace the document, keep in sync with the server
340
354
  // - Replace the version number, so editor is in sync with NCS server and can commit new changes.
@@ -351,29 +365,29 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
351
365
 
352
366
  // If there are unconfirmed steps, attempt to reconcile our current state with with recovered document
353
367
  if (!(useReconcile && currentState)) {
354
- _context4.next = 14;
368
+ _context4.next = 16;
355
369
  break;
356
370
  }
357
- _context4.next = 12;
371
+ _context4.next = 14;
358
372
  return _this.fetchReconcile(JSON.stringify(currentState.content), 'fe-restore');
359
- case 12:
360
- _context4.next = 15;
361
- break;
362
373
  case 14:
374
+ _context4.next = 17;
375
+ break;
376
+ case 16:
363
377
  if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
364
378
  _this.applyLocalSteps(unconfirmedSteps);
365
379
  }
366
- case 15:
380
+ case 17:
367
381
  (_this$analyticsHelper13 = _this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 || _this$analyticsHelper13.sendActionEvent(_const.EVENT_ACTION.REINITIALISE_DOCUMENT, _const.EVENT_STATUS.SUCCESS, {
368
382
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length,
369
383
  hasTitle: !!(metadata !== null && metadata !== void 0 && metadata.title),
370
384
  useReconcile: useReconcile
371
385
  });
372
- _context4.next = 23;
386
+ _context4.next = 25;
373
387
  break;
374
- case 18:
375
- _context4.prev = 18;
376
- _context4.t0 = _context4["catch"](6);
388
+ case 20:
389
+ _context4.prev = 20;
390
+ _context4.t0 = _context4["catch"](8);
377
391
  (_this$analyticsHelper14 = _this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 || _this$analyticsHelper14.sendActionEvent(_const.EVENT_ACTION.REINITIALISE_DOCUMENT, _const.EVENT_STATUS.FAILURE, {
378
392
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length,
379
393
  useReconcile: useReconcile
@@ -387,13 +401,13 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
387
401
  code: _internalErrors.INTERNAL_ERROR_CODE.DOCUMENT_RESTORE_ERROR
388
402
  }
389
403
  });
390
- case 23:
404
+ case 25:
391
405
  case "end":
392
406
  return _context4.stop();
393
407
  }
394
- }, _callee4, null, [[6, 18]]);
408
+ }, _callee4, null, [[8, 20]]);
395
409
  }));
396
- return function (_x) {
410
+ return function (_x2) {
397
411
  return _ref6.apply(this, arguments);
398
412
  };
399
413
  }());
@@ -638,7 +652,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
638
652
  var _this$analyticsHelper27;
639
653
  logger("The steps were rejected too many times (tries=".concat(_this.stepRejectCounter, ", limit=").concat(_provider.MAX_STEP_REJECTED_ERROR, "). Trying to catch-up."));
640
654
  (_this$analyticsHelper27 = _this.analyticsHelper) === null || _this$analyticsHelper27 === void 0 || _this$analyticsHelper27.sendActionEvent(_const.EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO);
641
- _this.throttledCatchupv2();
655
+ _this.throttledCatchupv2(_const.CatchupEventReason.STEPS_REJECTED);
642
656
  } else {
643
657
  // If committing steps failed try again automatically in 1s
644
658
  // This makes it more likely that unconfirmed steps trigger a catch-up
@@ -716,7 +730,7 @@ var DocumentService = exports.DocumentService = /*#__PURE__*/function () {
716
730
  var _this$analyticsHelper28;
717
731
  logger("Processing steps failed with error: ".concat(error, ". Triggering catch up call."));
718
732
  (_this$analyticsHelper28 = this.analyticsHelper) === null || _this$analyticsHelper28 === void 0 || _this$analyticsHelper28.sendErrorEvent(error, 'Error while processing steps');
719
- this.throttledCatchupv2();
733
+ this.throttledCatchupv2(_const.CatchupEventReason.PROCESS_STEPS);
720
734
  }
721
735
  }
722
736
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.EVENT_STATUS = exports.EVENT_ACTION = exports.CONFLUENCE = exports.ADD_STEPS_TYPE = exports.ACK_MAX_TRY = void 0;
6
+ exports.EVENT_STATUS = exports.EVENT_ACTION = exports.CatchupEventReason = exports.CONFLUENCE = exports.ADD_STEPS_TYPE = exports.ACK_MAX_TRY = void 0;
7
7
  var EVENT_ACTION = exports.EVENT_ACTION = /*#__PURE__*/function (EVENT_ACTION) {
8
8
  EVENT_ACTION["CONNECTION"] = "connection";
9
9
  EVENT_ACTION["CATCHUP"] = "catchup";
@@ -40,4 +40,13 @@ var ADD_STEPS_TYPE = exports.ADD_STEPS_TYPE = /*#__PURE__*/function (ADD_STEPS_T
40
40
  return ADD_STEPS_TYPE;
41
41
  }({});
42
42
  var ACK_MAX_TRY = exports.ACK_MAX_TRY = 60;
43
- var CONFLUENCE = exports.CONFLUENCE = 'confluence';
43
+ var CONFLUENCE = exports.CONFLUENCE = 'confluence';
44
+
45
+ /** Enumerable for attaching a reason to catchup (v2) call(s) */
46
+ var CatchupEventReason = exports.CatchupEventReason = /*#__PURE__*/function (CatchupEventReason) {
47
+ CatchupEventReason["STEPS_ADDED"] = "onStepsAdded";
48
+ CatchupEventReason["STEPS_REJECTED"] = "onStepsRejected";
49
+ CatchupEventReason["PROCESS_STEPS"] = "processSteps";
50
+ CatchupEventReason["RECONNECTED"] = "reconnected";
51
+ return CatchupEventReason;
52
+ }({});
@@ -135,7 +135,7 @@ var Provider = exports.Provider = /*#__PURE__*/function (_Emitter) {
135
135
  if (initialized && _this.disconnectedAt &&
136
136
  // Offline longer than `OUT_OF_SYNC_PERIOD`
137
137
  Date.now() - _this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
138
- _this.documentService.throttledCatchupv2();
138
+ _this.documentService.throttledCatchupv2(_const.CatchupEventReason.RECONNECTED);
139
139
  }
140
140
  _this.participantsService.startInactiveRemover(_this.sessionId);
141
141
  _this.disconnectedAt = undefined;
@@ -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.37.7";
8
+ var version = exports.version = "9.38.1";
9
9
  var nextMajorVersion = exports.nextMajorVersion = function nextMajorVersion() {
10
10
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
11
11
  };
@@ -209,7 +209,7 @@ export class Channel extends Emitter {
209
209
  throw error;
210
210
  }
211
211
  });
212
- _defineProperty(this, "fetchCatchupv2", async (fromVersion, clientId, catchUpOutofSync) => {
212
+ _defineProperty(this, "fetchCatchupv2", async (fromVersion, clientId, catchUpOutofSync, reason) => {
213
213
  try {
214
214
  const {
215
215
  steps,
@@ -219,7 +219,8 @@ export class Channel extends Emitter {
219
219
  queryParams: {
220
220
  version: fromVersion,
221
221
  clientId: clientId,
222
- catchUpOutofSync
222
+ catchUpOutofSync,
223
+ reason
223
224
  },
224
225
  requestInit: {
225
226
  headers: await this.commonHeaders()
@@ -8,7 +8,7 @@ export const catchupv2 = async opt => {
8
8
  ({
9
9
  steps,
10
10
  metadata
11
- } = await opt.fetchCatchupv2(fromVersion, opt.clientId, opt.catchUpOutofSync));
11
+ } = await opt.fetchCatchupv2(fromVersion, opt.clientId, opt.catchUpOutofSync, opt.reason));
12
12
  } catch (error) {
13
13
  var _opt$analyticsHelper;
14
14
  (_opt$analyticsHelper = opt.analyticsHelper) === null || _opt$analyticsHelper === void 0 ? void 0 : _opt$analyticsHelper.sendErrorEvent(error, 'Error while fetching catchupv2 from server');
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { ACK_MAX_TRY, EVENT_ACTION, EVENT_STATUS } from '../helpers/const';
2
+ import { ACK_MAX_TRY, EVENT_ACTION, EVENT_STATUS, CatchupEventReason } from '../helpers/const';
3
3
  import { getVersion, sendableSteps } from '@atlaskit/prosemirror-collab';
4
4
  import { JSONTransformer } from '@atlaskit/editor-json-transformer';
5
5
  import throttle from 'lodash/throttle';
@@ -94,8 +94,9 @@ export class DocumentService {
94
94
  });
95
95
  /**
96
96
  * To prevent calling catchup to often, use lodash throttle to reduce the frequency
97
+ * @param reason - optional reason to attach.
97
98
  */
98
- _defineProperty(this, "throttledCatchupv2", throttle(() => this.catchupv2(), CATCHUP_THROTTLE, {
99
+ _defineProperty(this, "throttledCatchupv2", throttle(reason => this.catchupv2(reason), CATCHUP_THROTTLE, {
99
100
  leading: false,
100
101
  // TODO: why shouldn't this be leading?
101
102
  trailing: true
@@ -104,8 +105,9 @@ export class DocumentService {
104
105
  * Called when:
105
106
  * * session established(offline -> online)
106
107
  * * try to accept steps but version is behind.
108
+ * @param reason - optional reason to attach.
107
109
  */
108
- _defineProperty(this, "catchupv2", async () => {
110
+ _defineProperty(this, "catchupv2", async reason => {
109
111
  const start = new Date().getTime();
110
112
  // if the queue is already paused, we are busy with something else, so don't proceed.
111
113
  if (this.stepQueue.isPaused()) {
@@ -149,7 +151,8 @@ export class DocumentService {
149
151
  analyticsHelper: this.analyticsHelper,
150
152
  clientId: this.clientId,
151
153
  onStepsAdded: this.onStepsAdded,
152
- catchUpOutofSync: this.catchUpOutofSync
154
+ catchUpOutofSync: this.catchUpOutofSync,
155
+ reason
153
156
  });
154
157
  const latency = new Date().getTime() - start;
155
158
  (_this$analyticsHelper3 = this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendActionEvent(EVENT_ACTION.CATCHUP, EVENT_STATUS.SUCCESS, {
@@ -258,7 +261,7 @@ export class DocumentService {
258
261
  } else if (data.version > expectedVersion) {
259
262
  logger(`Version too high. Expected "${expectedVersion}" but got "${data.version}. Current local version is ${currentVersion}.`);
260
263
  this.stepQueue.queueSteps(data);
261
- this.throttledCatchupv2();
264
+ this.throttledCatchupv2(CatchupEventReason.STEPS_ADDED);
262
265
  }
263
266
  this.participantsService.updateLastActive(data.steps.map(({
264
267
  userId
@@ -280,8 +283,12 @@ export class DocumentService {
280
283
  _defineProperty(this, "onRestore", async ({
281
284
  doc,
282
285
  version,
283
- metadata
286
+ metadata,
287
+ targetClientId
284
288
  }) => {
289
+ if (targetClientId && this.clientId !== targetClientId) {
290
+ return;
291
+ }
285
292
  // We preserve these as they will be lost apon this.updateDocument. This is because we are using document recovery.
286
293
  // We can then reconcile the document with the preserved state.
287
294
  const unconfirmedSteps = this.getUnconfirmedSteps();
@@ -526,7 +533,7 @@ export class DocumentService {
526
533
  var _this$analyticsHelper27;
527
534
  logger(`The steps were rejected too many times (tries=${this.stepRejectCounter}, limit=${MAX_STEP_REJECTED_ERROR}). Trying to catch-up.`);
528
535
  (_this$analyticsHelper27 = this.analyticsHelper) === null || _this$analyticsHelper27 === void 0 ? void 0 : _this$analyticsHelper27.sendActionEvent(EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, EVENT_STATUS.INFO);
529
- this.throttledCatchupv2();
536
+ this.throttledCatchupv2(CatchupEventReason.STEPS_REJECTED);
530
537
  } else {
531
538
  // If committing steps failed try again automatically in 1s
532
539
  // This makes it more likely that unconfirmed steps trigger a catch-up
@@ -596,7 +603,7 @@ export class DocumentService {
596
603
  var _this$analyticsHelper28;
597
604
  logger(`Processing steps failed with error: ${error}. Triggering catch up call.`);
598
605
  (_this$analyticsHelper28 = this.analyticsHelper) === null || _this$analyticsHelper28 === void 0 ? void 0 : _this$analyticsHelper28.sendErrorEvent(error, 'Error while processing steps');
599
- this.throttledCatchupv2();
606
+ this.throttledCatchupv2(CatchupEventReason.PROCESS_STEPS);
600
607
  }
601
608
  }
602
609
  }
@@ -34,4 +34,13 @@ export let ADD_STEPS_TYPE = /*#__PURE__*/function (ADD_STEPS_TYPE) {
34
34
  return ADD_STEPS_TYPE;
35
35
  }({});
36
36
  export const ACK_MAX_TRY = 60;
37
- export const CONFLUENCE = 'confluence';
37
+ export const CONFLUENCE = 'confluence';
38
+
39
+ /** Enumerable for attaching a reason to catchup (v2) call(s) */
40
+ export let CatchupEventReason = /*#__PURE__*/function (CatchupEventReason) {
41
+ CatchupEventReason["STEPS_ADDED"] = "onStepsAdded";
42
+ CatchupEventReason["STEPS_REJECTED"] = "onStepsRejected";
43
+ CatchupEventReason["PROCESS_STEPS"] = "processSteps";
44
+ CatchupEventReason["RECONNECTED"] = "reconnected";
45
+ return CatchupEventReason;
46
+ }({});
@@ -13,7 +13,7 @@ import { NamespaceService } from '../namespace/namespace-service';
13
13
  import { ParticipantsService } from '../participants/participants-service';
14
14
  import { errorCodeMapper } from '../errors/error-code-mapper';
15
15
  import { INTERNAL_ERROR_CODE } from '../errors/internal-errors';
16
- import { EVENT_ACTION, EVENT_STATUS } from '../helpers/const';
16
+ import { EVENT_ACTION, EVENT_STATUS, CatchupEventReason } from '../helpers/const';
17
17
  import { getCollabProviderFeatureFlag } from '../feature-flags';
18
18
  import { Api } from '../api/api';
19
19
  import { shouldTelepointerBeSampled } from '../analytics/performance';
@@ -112,7 +112,7 @@ export class Provider extends Emitter {
112
112
  if (initialized && this.disconnectedAt &&
113
113
  // Offline longer than `OUT_OF_SYNC_PERIOD`
114
114
  Date.now() - this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
115
- this.documentService.throttledCatchupv2();
115
+ this.documentService.throttledCatchupv2(CatchupEventReason.RECONNECTED);
116
116
  }
117
117
  this.participantsService.startInactiveRemover(this.sessionId);
118
118
  this.disconnectedAt = undefined;
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/collab-provider";
2
- export const version = "9.37.7";
2
+ export const version = "9.38.1";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -298,7 +298,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
298
298
  };
299
299
  }());
300
300
  _defineProperty(_assertThisInitialized(_this), "fetchCatchupv2", /*#__PURE__*/function () {
301
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(fromVersion, clientId, catchUpOutofSync) {
301
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(fromVersion, clientId, catchUpOutofSync, reason) {
302
302
  var _yield$utils$requestS2, steps, metadata, errorNotFound, errorCatchupv2;
303
303
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
304
304
  while (1) switch (_context3.prev = _context3.next) {
@@ -310,7 +310,8 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
310
310
  _context3.t3 = {
311
311
  version: fromVersion,
312
312
  clientId: clientId,
313
- catchUpOutofSync: catchUpOutofSync
313
+ catchUpOutofSync: catchUpOutofSync,
314
+ reason: reason
314
315
  };
315
316
  _context3.next = 7;
316
317
  return _this.commonHeaders();
@@ -367,7 +368,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
367
368
  }
368
369
  }, _callee3, null, [[0, 18]]);
369
370
  }));
370
- return function (_x3, _x4, _x5) {
371
+ return function (_x3, _x4, _x5, _x6) {
371
372
  return _ref3.apply(this, arguments);
372
373
  };
373
374
  }());
@@ -425,7 +426,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
425
426
  }
426
427
  }, _callee4, null, [[0, 24]]);
427
428
  }));
428
- return function (_x6, _x7) {
429
+ return function (_x7, _x8) {
429
430
  return _ref4.apply(this, arguments);
430
431
  };
431
432
  }());
@@ -560,7 +561,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
560
561
  }
561
562
  }, _callee5, null, [[1, 9]]);
562
563
  }));
563
- return function auth(_x8) {
564
+ return function auth(_x9) {
564
565
  return _ref5.apply(this, arguments);
565
566
  };
566
567
  }();
@@ -585,7 +586,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
585
586
  }
586
587
  }, _callee6);
587
588
  }));
588
- return function auth(_x9) {
589
+ return function auth(_x10) {
589
590
  return _ref6.apply(this, arguments);
590
591
  };
591
592
  }();
@@ -680,7 +681,7 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
680
681
  }
681
682
  }, _callee7);
682
683
  }));
683
- return function (_x10) {
684
+ return function (_x11) {
684
685
  return _ref11.apply(this, arguments);
685
686
  };
686
687
  }());
@@ -11,7 +11,7 @@ export var catchupv2 = /*#__PURE__*/function () {
11
11
  fromVersion = opt.getCurrentPmVersion();
12
12
  _context.prev = 1;
13
13
  _context.next = 4;
14
- return opt.fetchCatchupv2(fromVersion, opt.clientId, opt.catchUpOutofSync);
14
+ return opt.fetchCatchupv2(fromVersion, opt.clientId, opt.catchUpOutofSync, opt.reason);
15
15
  case 4:
16
16
  _yield$opt$fetchCatch = _context.sent;
17
17
  steps = _yield$opt$fetchCatch.steps;
@@ -5,7 +5,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
- import { ACK_MAX_TRY, EVENT_ACTION, EVENT_STATUS } from '../helpers/const';
8
+ import { ACK_MAX_TRY, EVENT_ACTION, EVENT_STATUS, CatchupEventReason } from '../helpers/const';
9
9
  import { getVersion, sendableSteps } from '@atlaskit/prosemirror-collab';
10
10
  import { JSONTransformer } from '@atlaskit/editor-json-transformer';
11
11
  import throttle from 'lodash/throttle';
@@ -122,9 +122,10 @@ export var DocumentService = /*#__PURE__*/function () {
122
122
  })));
123
123
  /**
124
124
  * To prevent calling catchup to often, use lodash throttle to reduce the frequency
125
+ * @param reason - optional reason to attach.
125
126
  */
126
- _defineProperty(this, "throttledCatchupv2", throttle(function () {
127
- return _this.catchupv2();
127
+ _defineProperty(this, "throttledCatchupv2", throttle(function (reason) {
128
+ return _this.catchupv2(reason);
128
129
  }, CATCHUP_THROTTLE, {
129
130
  leading: false,
130
131
  // TODO: why shouldn't this be leading?
@@ -134,67 +135,74 @@ export var DocumentService = /*#__PURE__*/function () {
134
135
  * Called when:
135
136
  * * session established(offline -> online)
136
137
  * * try to accept steps but version is behind.
138
+ * @param reason - optional reason to attach.
137
139
  */
138
- _defineProperty(this, "catchupv2", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
139
- var start, _this$analyticsHelper3, latency, _this$analyticsHelper4, _latency2;
140
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
141
- while (1) switch (_context2.prev = _context2.next) {
142
- case 0:
143
- start = new Date().getTime(); // if the queue is already paused, we are busy with something else, so don't proceed.
144
- if (!_this.stepQueue.isPaused()) {
145
- _context2.next = 4;
146
- break;
147
- }
148
- logger("Queue is paused. Aborting.");
149
- return _context2.abrupt("return");
150
- case 4:
151
- if (!_this.isNameSpaceLocked()) {
152
- _context2.next = 7;
140
+ _defineProperty(this, "catchupv2", /*#__PURE__*/function () {
141
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(reason) {
142
+ var start, _this$analyticsHelper3, latency, _this$analyticsHelper4, _latency2;
143
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
144
+ while (1) switch (_context2.prev = _context2.next) {
145
+ case 0:
146
+ start = new Date().getTime(); // if the queue is already paused, we are busy with something else, so don't proceed.
147
+ if (!_this.stepQueue.isPaused()) {
148
+ _context2.next = 4;
149
+ break;
150
+ }
151
+ logger("Queue is paused. Aborting.");
152
+ return _context2.abrupt("return");
153
+ case 4:
154
+ if (!_this.isNameSpaceLocked()) {
155
+ _context2.next = 7;
156
+ break;
157
+ }
158
+ logger("catchupv2: Document is locked. Aborting.");
159
+ return _context2.abrupt("return");
160
+ case 7:
161
+ _this.stepQueue.pauseQueue();
162
+ _context2.prev = 8;
163
+ _context2.next = 11;
164
+ return catchupv2({
165
+ getCurrentPmVersion: _this.getCurrentPmVersion,
166
+ fetchCatchupv2: _this.fetchCatchupv2,
167
+ updateMetadata: _this.metadataService.updateMetadata,
168
+ analyticsHelper: _this.analyticsHelper,
169
+ clientId: _this.clientId,
170
+ onStepsAdded: _this.onStepsAdded,
171
+ catchUpOutofSync: _this.catchUpOutofSync,
172
+ reason: reason
173
+ });
174
+ case 11:
175
+ _this.catchUpOutofSync = _context2.sent;
176
+ latency = new Date().getTime() - start;
177
+ (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 || _this$analyticsHelper3.sendActionEvent(EVENT_ACTION.CATCHUP, EVENT_STATUS.SUCCESS, {
178
+ latency: latency
179
+ });
180
+ _context2.next = 20;
153
181
  break;
154
- }
155
- logger("catchupv2: Document is locked. Aborting.");
156
- return _context2.abrupt("return");
157
- case 7:
158
- _this.stepQueue.pauseQueue();
159
- _context2.prev = 8;
160
- _context2.next = 11;
161
- return catchupv2({
162
- getCurrentPmVersion: _this.getCurrentPmVersion,
163
- fetchCatchupv2: _this.fetchCatchupv2,
164
- updateMetadata: _this.metadataService.updateMetadata,
165
- analyticsHelper: _this.analyticsHelper,
166
- clientId: _this.clientId,
167
- onStepsAdded: _this.onStepsAdded,
168
- catchUpOutofSync: _this.catchUpOutofSync
169
- });
170
- case 11:
171
- _this.catchUpOutofSync = _context2.sent;
172
- latency = new Date().getTime() - start;
173
- (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 || _this$analyticsHelper3.sendActionEvent(EVENT_ACTION.CATCHUP, EVENT_STATUS.SUCCESS, {
174
- latency: latency
175
- });
176
- _context2.next = 20;
177
- break;
178
- case 16:
179
- _context2.prev = 16;
180
- _context2.t0 = _context2["catch"](8);
181
- _latency2 = new Date().getTime() - start;
182
- (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendActionEvent(EVENT_ACTION.CATCHUP, EVENT_STATUS.FAILURE, {
183
- latency: _latency2
184
- });
185
- case 20:
186
- _context2.prev = 20;
187
- _this.stepQueue.resumeQueue();
188
- _this.processQueue();
189
- _this.sendStepsFromCurrentState(); // this will eventually retry catchup as it calls throttledCommitStep which will either catchup on onStepsAdded or onErrorHandled
190
- _this.stepRejectCounter = 0;
191
- return _context2.finish(20);
192
- case 26:
193
- case "end":
194
- return _context2.stop();
195
- }
196
- }, _callee2, null, [[8, 16, 20, 26]]);
197
- })));
182
+ case 16:
183
+ _context2.prev = 16;
184
+ _context2.t0 = _context2["catch"](8);
185
+ _latency2 = new Date().getTime() - start;
186
+ (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendActionEvent(EVENT_ACTION.CATCHUP, EVENT_STATUS.FAILURE, {
187
+ latency: _latency2
188
+ });
189
+ case 20:
190
+ _context2.prev = 20;
191
+ _this.stepQueue.resumeQueue();
192
+ _this.processQueue();
193
+ _this.sendStepsFromCurrentState(); // this will eventually retry catchup as it calls throttledCommitStep which will either catchup on onStepsAdded or onErrorHandled
194
+ _this.stepRejectCounter = 0;
195
+ return _context2.finish(20);
196
+ case 26:
197
+ case "end":
198
+ return _context2.stop();
199
+ }
200
+ }, _callee2, null, [[8, 16, 20, 26]]);
201
+ }));
202
+ return function (_x) {
203
+ return _ref2.apply(this, arguments);
204
+ };
205
+ }());
198
206
  _defineProperty(this, "getCurrentPmVersion", function () {
199
207
  var _this$getState;
200
208
  var state = (_this$getState = _this.getState) === null || _this$getState === void 0 ? void 0 : _this$getState.call(_this);
@@ -292,7 +300,7 @@ export var DocumentService = /*#__PURE__*/function () {
292
300
  } else if (data.version > expectedVersion) {
293
301
  logger("Version too high. Expected \"".concat(expectedVersion, "\" but got \"").concat(data.version, ". Current local version is ").concat(currentVersion, "."));
294
302
  _this.stepQueue.queueSteps(data);
295
- _this.throttledCatchupv2();
303
+ _this.throttledCatchupv2(CatchupEventReason.STEPS_ADDED);
296
304
  }
297
305
  _this.participantsService.updateLastActive(data.steps.map(function (_ref4) {
298
306
  var userId = _ref4.userId;
@@ -314,20 +322,26 @@ export var DocumentService = /*#__PURE__*/function () {
314
322
  // Triggered when page recovery has emitted an 'init' event on a page client is currently connected to.
315
323
  _defineProperty(this, "onRestore", /*#__PURE__*/function () {
316
324
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref5) {
317
- var doc, version, metadata, unconfirmedSteps, currentState, useReconcile, _this$analyticsHelper13, _this$analyticsHelper14, _this$analyticsHelper15;
325
+ var doc, version, metadata, targetClientId, unconfirmedSteps, currentState, useReconcile, _this$analyticsHelper13, _this$analyticsHelper14, _this$analyticsHelper15;
318
326
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
319
327
  while (1) switch (_context4.prev = _context4.next) {
320
328
  case 0:
321
- doc = _ref5.doc, version = _ref5.version, metadata = _ref5.metadata;
329
+ doc = _ref5.doc, version = _ref5.version, metadata = _ref5.metadata, targetClientId = _ref5.targetClientId;
330
+ if (!(targetClientId && _this.clientId !== targetClientId)) {
331
+ _context4.next = 3;
332
+ break;
333
+ }
334
+ return _context4.abrupt("return");
335
+ case 3:
322
336
  // We preserve these as they will be lost apon this.updateDocument. This is because we are using document recovery.
323
337
  // We can then reconcile the document with the preserved state.
324
338
  unconfirmedSteps = _this.getUnconfirmedSteps();
325
- _context4.next = 4;
339
+ _context4.next = 6;
326
340
  return _this.getCurrentState();
327
- case 4:
341
+ case 6:
328
342
  currentState = _context4.sent;
329
343
  useReconcile = Boolean((unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length) && currentState);
330
- _context4.prev = 6;
344
+ _context4.prev = 8;
331
345
  // Reset the editor,
332
346
  // - Replace the document, keep in sync with the server
333
347
  // - Replace the version number, so editor is in sync with NCS server and can commit new changes.
@@ -344,29 +358,29 @@ export var DocumentService = /*#__PURE__*/function () {
344
358
 
345
359
  // If there are unconfirmed steps, attempt to reconcile our current state with with recovered document
346
360
  if (!(useReconcile && currentState)) {
347
- _context4.next = 14;
361
+ _context4.next = 16;
348
362
  break;
349
363
  }
350
- _context4.next = 12;
364
+ _context4.next = 14;
351
365
  return _this.fetchReconcile(JSON.stringify(currentState.content), 'fe-restore');
352
- case 12:
353
- _context4.next = 15;
354
- break;
355
366
  case 14:
367
+ _context4.next = 17;
368
+ break;
369
+ case 16:
356
370
  if (unconfirmedSteps !== null && unconfirmedSteps !== void 0 && unconfirmedSteps.length) {
357
371
  _this.applyLocalSteps(unconfirmedSteps);
358
372
  }
359
- case 15:
373
+ case 17:
360
374
  (_this$analyticsHelper13 = _this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 || _this$analyticsHelper13.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.SUCCESS, {
361
375
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length,
362
376
  hasTitle: !!(metadata !== null && metadata !== void 0 && metadata.title),
363
377
  useReconcile: useReconcile
364
378
  });
365
- _context4.next = 23;
379
+ _context4.next = 25;
366
380
  break;
367
- case 18:
368
- _context4.prev = 18;
369
- _context4.t0 = _context4["catch"](6);
381
+ case 20:
382
+ _context4.prev = 20;
383
+ _context4.t0 = _context4["catch"](8);
370
384
  (_this$analyticsHelper14 = _this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 || _this$analyticsHelper14.sendActionEvent(EVENT_ACTION.REINITIALISE_DOCUMENT, EVENT_STATUS.FAILURE, {
371
385
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length,
372
386
  useReconcile: useReconcile
@@ -380,13 +394,13 @@ export var DocumentService = /*#__PURE__*/function () {
380
394
  code: INTERNAL_ERROR_CODE.DOCUMENT_RESTORE_ERROR
381
395
  }
382
396
  });
383
- case 23:
397
+ case 25:
384
398
  case "end":
385
399
  return _context4.stop();
386
400
  }
387
- }, _callee4, null, [[6, 18]]);
401
+ }, _callee4, null, [[8, 20]]);
388
402
  }));
389
- return function (_x) {
403
+ return function (_x2) {
390
404
  return _ref6.apply(this, arguments);
391
405
  };
392
406
  }());
@@ -631,7 +645,7 @@ export var DocumentService = /*#__PURE__*/function () {
631
645
  var _this$analyticsHelper27;
632
646
  logger("The steps were rejected too many times (tries=".concat(_this.stepRejectCounter, ", limit=").concat(MAX_STEP_REJECTED_ERROR, "). Trying to catch-up."));
633
647
  (_this$analyticsHelper27 = _this.analyticsHelper) === null || _this$analyticsHelper27 === void 0 || _this$analyticsHelper27.sendActionEvent(EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, EVENT_STATUS.INFO);
634
- _this.throttledCatchupv2();
648
+ _this.throttledCatchupv2(CatchupEventReason.STEPS_REJECTED);
635
649
  } else {
636
650
  // If committing steps failed try again automatically in 1s
637
651
  // This makes it more likely that unconfirmed steps trigger a catch-up
@@ -709,7 +723,7 @@ export var DocumentService = /*#__PURE__*/function () {
709
723
  var _this$analyticsHelper28;
710
724
  logger("Processing steps failed with error: ".concat(error, ". Triggering catch up call."));
711
725
  (_this$analyticsHelper28 = this.analyticsHelper) === null || _this$analyticsHelper28 === void 0 || _this$analyticsHelper28.sendErrorEvent(error, 'Error while processing steps');
712
- this.throttledCatchupv2();
726
+ this.throttledCatchupv2(CatchupEventReason.PROCESS_STEPS);
713
727
  }
714
728
  }
715
729
  }
@@ -34,4 +34,13 @@ export var ADD_STEPS_TYPE = /*#__PURE__*/function (ADD_STEPS_TYPE) {
34
34
  return ADD_STEPS_TYPE;
35
35
  }({});
36
36
  export var ACK_MAX_TRY = 60;
37
- export var CONFLUENCE = 'confluence';
37
+ export var CONFLUENCE = 'confluence';
38
+
39
+ /** Enumerable for attaching a reason to catchup (v2) call(s) */
40
+ export var CatchupEventReason = /*#__PURE__*/function (CatchupEventReason) {
41
+ CatchupEventReason["STEPS_ADDED"] = "onStepsAdded";
42
+ CatchupEventReason["STEPS_REJECTED"] = "onStepsRejected";
43
+ CatchupEventReason["PROCESS_STEPS"] = "processSteps";
44
+ CatchupEventReason["RECONNECTED"] = "reconnected";
45
+ return CatchupEventReason;
46
+ }({});
@@ -26,7 +26,7 @@ import { NamespaceService } from '../namespace/namespace-service';
26
26
  import { ParticipantsService } from '../participants/participants-service';
27
27
  import { errorCodeMapper } from '../errors/error-code-mapper';
28
28
  import { INTERNAL_ERROR_CODE } from '../errors/internal-errors';
29
- import { EVENT_ACTION, EVENT_STATUS } from '../helpers/const';
29
+ import { EVENT_ACTION, EVENT_STATUS, CatchupEventReason } from '../helpers/const';
30
30
  import { getCollabProviderFeatureFlag } from '../feature-flags';
31
31
  import { Api } from '../api/api';
32
32
  import { shouldTelepointerBeSampled } from '../analytics/performance';
@@ -128,7 +128,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
128
128
  if (initialized && _this.disconnectedAt &&
129
129
  // Offline longer than `OUT_OF_SYNC_PERIOD`
130
130
  Date.now() - _this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
131
- _this.documentService.throttledCatchupv2();
131
+ _this.documentService.throttledCatchupv2(CatchupEventReason.RECONNECTED);
132
132
  }
133
133
  _this.participantsService.startInactiveRemover(_this.sessionId);
134
134
  _this.disconnectedAt = undefined;
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/collab-provider";
2
- export var version = "9.37.7";
2
+ export var version = "9.38.1";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,6 @@
1
1
  import { Emitter } from './emitter';
2
2
  import type { Config, ChannelEvent, CatchupResponse, Catchupv2Response, ReconcileResponse } from './types';
3
+ import { type CatchupEventReason } from './helpers/const';
3
4
  import type { Socket } from 'socket.io-client';
4
5
  import type AnalyticsHelper from './analytics/analytics-helper';
5
6
  import type { Metadata } from '@atlaskit/editor-common/collab';
@@ -40,7 +41,7 @@ export declare class Channel extends Emitter<ChannelEvent> {
40
41
  private onConnect;
41
42
  private onReceiveData;
42
43
  fetchCatchup: (fromVersion: number, clientId: number | string | undefined) => Promise<CatchupResponse>;
43
- fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean | undefined) => Promise<Catchupv2Response>;
44
+ fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean | undefined, reason?: CatchupEventReason) => Promise<Catchupv2Response>;
44
45
  fetchReconcile: (currentStateDoc: string, reason: string) => Promise<ReconcileResponse>;
45
46
  /**
46
47
  * Send message to the back-end service over the channel. Timestamp will be added server side.
@@ -1,6 +1,7 @@
1
1
  import type { ResolvedEditorState, SyncUpErrorFunction } from '@atlaskit/editor-common/collab';
2
2
  import type { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
3
3
  import type AnalyticsHelper from '../analytics/analytics-helper';
4
+ import { CatchupEventReason } from '../helpers/const';
4
5
  import type { MetadataService } from '../metadata/metadata-service';
5
6
  import type { CatchupResponse, Catchupv2Response, ChannelEvent, ReconcileResponse, StepsPayload } from '../types';
6
7
  import type { CollabEvents, CollabInitPayload } from '@atlaskit/editor-common/collab';
@@ -58,12 +59,14 @@ export declare class DocumentService {
58
59
  private catchup;
59
60
  /**
60
61
  * To prevent calling catchup to often, use lodash throttle to reduce the frequency
62
+ * @param reason - optional reason to attach.
61
63
  */
62
- throttledCatchupv2: import("lodash").DebouncedFunc<() => Promise<void>>;
64
+ throttledCatchupv2: import("lodash").DebouncedFunc<(reason?: CatchupEventReason) => Promise<void>>;
63
65
  /**
64
66
  * Called when:
65
67
  * * session established(offline -> online)
66
68
  * * try to accept steps but version is behind.
69
+ * @param reason - optional reason to attach.
67
70
  */
68
71
  private catchupv2;
69
72
  getCurrentPmVersion: () => number;
@@ -77,7 +80,7 @@ export declare class DocumentService {
77
80
  * Called when we receive steps from the service
78
81
  */
79
82
  onStepsAdded: (data: StepsPayload) => void;
80
- onRestore: ({ doc, version, metadata }: CollabInitPayload) => Promise<void>;
83
+ onRestore: ({ doc, version, metadata, targetClientId }: CollabInitPayload) => Promise<void>;
81
84
  getFinalAcknowledgedState: () => Promise<ResolvedEditorState>;
82
85
  updateDocument: ({ doc, version, metadata, reserveCursor }: CollabInitPayload) => void;
83
86
  private updateDocumentAnalytics;
@@ -254,4 +254,11 @@ type UpdateDocumentAnalyticsEvent = {
254
254
  export type ActionAnalyticsEvent = AddStepsSuccessAnalyticsEvent | AddStepsFailureAnalyticsEvent | ReInitDocFailAnalyticsEvent | ReInitDocSuccessAnalyticsEvent | ConnectionSuccessAnalyticsEvent | ConnectionFailureAnalyticsEvent | CatchUpSuccessAnalyticsEvent | CatchUpFailureAnalyticsEvent | DocumentInitSuccessAnalyticsEvent | UpdateParticipantsSuccessAnalyticsEvent | CommitUnconfirmedStepsSuccessAnalyticsEvent | CommitUnconfirmedStepsFailureAnalyticsEvent | PublishPageSuccessAnalyticsEvent | PublishPageFailureAnalyticsEvent | GetCurrentStateSuccessAnalyticsEvent | GetCurrentStateFailureAnalyticsEvent | InvalidateTokenAnalyticsEvent | SendStepsRetryAnalyticsEvent | CatchupAfterMaxSendStepsRetryAnalyticsEvent | CatchUpDroppedStepsEvent | WebsocketMessageVolumeMetricEvent | ProviderInitializedAnalyticsEvent | ProviderSetupAnalyticsEvent | ProviderHasUnconfirmedStepsAnalyticsEvent | UpdateDocumentAnalyticsEvent;
255
255
  export declare const ACK_MAX_TRY = 60;
256
256
  export declare const CONFLUENCE = "confluence";
257
+ /** Enumerable for attaching a reason to catchup (v2) call(s) */
258
+ export declare enum CatchupEventReason {
259
+ STEPS_ADDED = "onStepsAdded",
260
+ STEPS_REJECTED = "onStepsRejected",
261
+ PROCESS_STEPS = "processSteps",
262
+ RECONNECTED = "reconnected"
263
+ }
257
264
  export {};
@@ -6,6 +6,7 @@ import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
6
6
  import type { GetUserType } from './participants/participants-helper';
7
7
  import type AnalyticsHelper from './analytics/analytics-helper';
8
8
  import type { CollabInitPayload, StepJson, CollabSendableSelection, Metadata, UserPermitType, Activity } from '@atlaskit/editor-common/collab';
9
+ import { type CatchupEventReason } from './helpers/const';
9
10
  export type { CollabParticipant, CollabEventInitData, CollabEventRemoteData, CollabEventConnectionData, CollabEventConnectingData, CollabEventPresenceData, ResolvedEditorState, CollabConnectedPayload, CollabConnectingPayload, CollabDisconnectedPayload, CollabInitPayload, CollabDataPayload, CollabTelepointerPayload, CollabPresencePayload, CollabMetadataPayload, CollabLocalStepsPayload, CollabCommitStatusEventPayload, CollabPermissionEventPayload, UserPermitType, CollabEvents, Metadata, StepJson, CollabEventTelepointerData, CollabSendableSelection, CollabEditProvider, NewCollabSyncUpErrorAttributes, SyncUpErrorFunction, CollabEventLocalStepData, } from '@atlaskit/editor-common/collab';
10
11
  export interface CollabEventDisconnectedData {
11
12
  sid: string;
@@ -216,12 +217,13 @@ export interface CatchupOptions {
216
217
  }
217
218
  export interface Catchupv2Options {
218
219
  getCurrentPmVersion: () => number;
219
- fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean) => Promise<Catchupv2Response>;
220
+ fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean, reason?: CatchupEventReason) => Promise<Catchupv2Response>;
220
221
  updateMetadata: (metadata: Metadata | undefined) => void;
221
222
  analyticsHelper: AnalyticsHelper | undefined;
222
223
  clientId: number | string | undefined;
223
224
  onStepsAdded: (data: StepsPayload) => void;
224
225
  catchUpOutofSync: boolean;
226
+ reason?: CatchupEventReason;
225
227
  }
226
228
  export type ProductInformation = {
227
229
  product: string;
@@ -1,5 +1,6 @@
1
1
  import { Emitter } from './emitter';
2
2
  import type { Config, ChannelEvent, CatchupResponse, Catchupv2Response, ReconcileResponse } from './types';
3
+ import { type CatchupEventReason } from './helpers/const';
3
4
  import type { Socket } from 'socket.io-client';
4
5
  import type AnalyticsHelper from './analytics/analytics-helper';
5
6
  import type { Metadata } from '@atlaskit/editor-common/collab';
@@ -40,7 +41,7 @@ export declare class Channel extends Emitter<ChannelEvent> {
40
41
  private onConnect;
41
42
  private onReceiveData;
42
43
  fetchCatchup: (fromVersion: number, clientId: number | string | undefined) => Promise<CatchupResponse>;
43
- fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean | undefined) => Promise<Catchupv2Response>;
44
+ fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean | undefined, reason?: CatchupEventReason) => Promise<Catchupv2Response>;
44
45
  fetchReconcile: (currentStateDoc: string, reason: string) => Promise<ReconcileResponse>;
45
46
  /**
46
47
  * Send message to the back-end service over the channel. Timestamp will be added server side.
@@ -1,6 +1,7 @@
1
1
  import type { ResolvedEditorState, SyncUpErrorFunction } from '@atlaskit/editor-common/collab';
2
2
  import type { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
3
3
  import type AnalyticsHelper from '../analytics/analytics-helper';
4
+ import { CatchupEventReason } from '../helpers/const';
4
5
  import type { MetadataService } from '../metadata/metadata-service';
5
6
  import type { CatchupResponse, Catchupv2Response, ChannelEvent, ReconcileResponse, StepsPayload } from '../types';
6
7
  import type { CollabEvents, CollabInitPayload } from '@atlaskit/editor-common/collab';
@@ -58,12 +59,14 @@ export declare class DocumentService {
58
59
  private catchup;
59
60
  /**
60
61
  * To prevent calling catchup to often, use lodash throttle to reduce the frequency
62
+ * @param reason - optional reason to attach.
61
63
  */
62
- throttledCatchupv2: import("lodash").DebouncedFunc<() => Promise<void>>;
64
+ throttledCatchupv2: import("lodash").DebouncedFunc<(reason?: CatchupEventReason) => Promise<void>>;
63
65
  /**
64
66
  * Called when:
65
67
  * * session established(offline -> online)
66
68
  * * try to accept steps but version is behind.
69
+ * @param reason - optional reason to attach.
67
70
  */
68
71
  private catchupv2;
69
72
  getCurrentPmVersion: () => number;
@@ -77,7 +80,7 @@ export declare class DocumentService {
77
80
  * Called when we receive steps from the service
78
81
  */
79
82
  onStepsAdded: (data: StepsPayload) => void;
80
- onRestore: ({ doc, version, metadata }: CollabInitPayload) => Promise<void>;
83
+ onRestore: ({ doc, version, metadata, targetClientId }: CollabInitPayload) => Promise<void>;
81
84
  getFinalAcknowledgedState: () => Promise<ResolvedEditorState>;
82
85
  updateDocument: ({ doc, version, metadata, reserveCursor }: CollabInitPayload) => void;
83
86
  private updateDocumentAnalytics;
@@ -254,4 +254,11 @@ type UpdateDocumentAnalyticsEvent = {
254
254
  export type ActionAnalyticsEvent = AddStepsSuccessAnalyticsEvent | AddStepsFailureAnalyticsEvent | ReInitDocFailAnalyticsEvent | ReInitDocSuccessAnalyticsEvent | ConnectionSuccessAnalyticsEvent | ConnectionFailureAnalyticsEvent | CatchUpSuccessAnalyticsEvent | CatchUpFailureAnalyticsEvent | DocumentInitSuccessAnalyticsEvent | UpdateParticipantsSuccessAnalyticsEvent | CommitUnconfirmedStepsSuccessAnalyticsEvent | CommitUnconfirmedStepsFailureAnalyticsEvent | PublishPageSuccessAnalyticsEvent | PublishPageFailureAnalyticsEvent | GetCurrentStateSuccessAnalyticsEvent | GetCurrentStateFailureAnalyticsEvent | InvalidateTokenAnalyticsEvent | SendStepsRetryAnalyticsEvent | CatchupAfterMaxSendStepsRetryAnalyticsEvent | CatchUpDroppedStepsEvent | WebsocketMessageVolumeMetricEvent | ProviderInitializedAnalyticsEvent | ProviderSetupAnalyticsEvent | ProviderHasUnconfirmedStepsAnalyticsEvent | UpdateDocumentAnalyticsEvent;
255
255
  export declare const ACK_MAX_TRY = 60;
256
256
  export declare const CONFLUENCE = "confluence";
257
+ /** Enumerable for attaching a reason to catchup (v2) call(s) */
258
+ export declare enum CatchupEventReason {
259
+ STEPS_ADDED = "onStepsAdded",
260
+ STEPS_REJECTED = "onStepsRejected",
261
+ PROCESS_STEPS = "processSteps",
262
+ RECONNECTED = "reconnected"
263
+ }
257
264
  export {};
@@ -6,6 +6,7 @@ import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
6
6
  import type { GetUserType } from './participants/participants-helper';
7
7
  import type AnalyticsHelper from './analytics/analytics-helper';
8
8
  import type { CollabInitPayload, StepJson, CollabSendableSelection, Metadata, UserPermitType, Activity } from '@atlaskit/editor-common/collab';
9
+ import { type CatchupEventReason } from './helpers/const';
9
10
  export type { CollabParticipant, CollabEventInitData, CollabEventRemoteData, CollabEventConnectionData, CollabEventConnectingData, CollabEventPresenceData, ResolvedEditorState, CollabConnectedPayload, CollabConnectingPayload, CollabDisconnectedPayload, CollabInitPayload, CollabDataPayload, CollabTelepointerPayload, CollabPresencePayload, CollabMetadataPayload, CollabLocalStepsPayload, CollabCommitStatusEventPayload, CollabPermissionEventPayload, UserPermitType, CollabEvents, Metadata, StepJson, CollabEventTelepointerData, CollabSendableSelection, CollabEditProvider, NewCollabSyncUpErrorAttributes, SyncUpErrorFunction, CollabEventLocalStepData, } from '@atlaskit/editor-common/collab';
10
11
  export interface CollabEventDisconnectedData {
11
12
  sid: string;
@@ -216,12 +217,13 @@ export interface CatchupOptions {
216
217
  }
217
218
  export interface Catchupv2Options {
218
219
  getCurrentPmVersion: () => number;
219
- fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean) => Promise<Catchupv2Response>;
220
+ fetchCatchupv2: (fromVersion: number, clientId: number | string | undefined, catchUpOutofSync: boolean, reason?: CatchupEventReason) => Promise<Catchupv2Response>;
220
221
  updateMetadata: (metadata: Metadata | undefined) => void;
221
222
  analyticsHelper: AnalyticsHelper | undefined;
222
223
  clientId: number | string | undefined;
223
224
  onStepsAdded: (data: StepsPayload) => void;
224
225
  catchUpOutofSync: boolean;
226
+ reason?: CatchupEventReason;
225
227
  }
226
228
  export type ProductInformation = {
227
229
  product: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "9.37.7",
3
+ "version": "9.38.1",
4
4
  "description": "A provider for collaborative editing.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@atlaskit/analytics-gas-types": "^5.1.0",
36
36
  "@atlaskit/analytics-listeners": "^8.11.0",
37
- "@atlaskit/editor-common": "^88.9.0",
37
+ "@atlaskit/editor-common": "^88.11.0",
38
38
  "@atlaskit/editor-json-transformer": "^8.18.0",
39
39
  "@atlaskit/editor-prosemirror": "5.0.1",
40
40
  "@atlaskit/platform-feature-flags": "^0.3.0",