@atlaskit/collab-provider 9.3.0 → 9.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 (39) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/analytics/analytics-helper.js +7 -2
  3. package/dist/cjs/channel.js +26 -20
  4. package/dist/cjs/connectivity/network.js +4 -2
  5. package/dist/cjs/document/document-service.js +60 -11
  6. package/dist/cjs/errors/error-code-mapper.js +7 -0
  7. package/dist/cjs/errors/error-types.js +31 -5
  8. package/dist/cjs/provider/index.js +52 -38
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/cjs/version.json +1 -1
  11. package/dist/es2019/analytics/analytics-helper.js +7 -1
  12. package/dist/es2019/channel.js +13 -7
  13. package/dist/es2019/connectivity/network.js +4 -2
  14. package/dist/es2019/document/document-service.js +61 -15
  15. package/dist/es2019/errors/error-code-mapper.js +7 -0
  16. package/dist/es2019/errors/error-types.js +20 -2
  17. package/dist/es2019/provider/index.js +52 -38
  18. package/dist/es2019/version-wrapper.js +1 -1
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/esm/analytics/analytics-helper.js +7 -2
  21. package/dist/esm/channel.js +26 -20
  22. package/dist/esm/connectivity/network.js +4 -2
  23. package/dist/esm/document/document-service.js +61 -12
  24. package/dist/esm/errors/error-code-mapper.js +7 -0
  25. package/dist/esm/errors/error-types.js +30 -4
  26. package/dist/esm/provider/index.js +52 -38
  27. package/dist/esm/version-wrapper.js +1 -1
  28. package/dist/esm/version.json +1 -1
  29. package/dist/types/document/document-service.d.ts +4 -1
  30. package/dist/types/errors/error-types.d.ts +47 -7
  31. package/dist/types/helpers/const.d.ts +8 -1
  32. package/dist/types/types.d.ts +5 -0
  33. package/dist/types-ts4.5/document/document-service.d.ts +4 -1
  34. package/dist/types-ts4.5/errors/error-types.d.ts +47 -7
  35. package/dist/types-ts4.5/helpers/const.d.ts +8 -1
  36. package/dist/types-ts4.5/types.d.ts +5 -0
  37. package/package.json +2 -2
  38. package/report.api.md +13 -1
  39. package/tmp/api-report-tmp.d.ts +12 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/collab-provider
2
2
 
3
+ ## 9.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`606d4ad65fc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/606d4ad65fc) - ESS-3682 Add detection that it the editor failed to update, emit analytics as well added an option to
8
+ enable emitting fatal errors.
9
+
10
+ ### Patch Changes
11
+
12
+ - [`5eb1273509c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5eb1273509c) - ESS-3728: Fix initialized always set to false when reconnecting.
13
+
14
+ ## 9.3.1
15
+
16
+ ### Patch Changes
17
+
18
+ - [`a9350cf3831`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a9350cf3831) - Check existence of window and document variable for confluence SSR to work
19
+
3
20
  ## 9.3.0
4
21
 
5
22
  ### Minor Changes
@@ -13,6 +13,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
13
13
  var _const = require("../helpers/const");
14
14
  var _versionWrapper = require("../version-wrapper");
15
15
  var _singleton = require("../connectivity/singleton");
16
+ var _errorTypes = require("../errors/error-types");
16
17
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
18
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
19
  var EVENT_SUBJECT = 'collab';
@@ -75,13 +76,17 @@ var AnalyticsHelper = /*#__PURE__*/function () {
75
76
  (0, _createClass2.default)(AnalyticsHelper, [{
76
77
  key: "sendErrorEvent",
77
78
  value: function sendErrorEvent(error, errorMessage) {
79
+ var errorExtraAttributes = {};
80
+ if (error instanceof _errorTypes.CustomError) {
81
+ errorExtraAttributes = error.getExtraErrorEventAttributes() || {};
82
+ }
78
83
  var errorAnalyticsEvent = {
79
84
  eventAction: _const.EVENT_ACTION.ERROR,
80
- attributes: {
85
+ attributes: _objectSpread({
81
86
  documentAri: this.documentAri,
82
87
  errorMessage: errorMessage,
83
88
  errorName: error instanceof Error ? error.name : undefined
84
- },
89
+ }, errorExtraAttributes),
85
90
  nonPrivacySafeAttributes: {
86
91
  error: error
87
92
  }
@@ -397,32 +397,33 @@ var Channel = /*#__PURE__*/function (_Emitter) {
397
397
  permissionTokenRefresh = _this$config2.permissionTokenRefresh,
398
398
  cacheToken = _this$config2.cacheToken;
399
399
  var auth;
400
- var authData = {
401
- // The initialized status. If false, BE will send document, otherwise not.
402
- initialized: this.initialized,
403
- // ESS-1009 Allow to opt-in into 404 response
404
- need404: this.config.need404
405
- };
406
400
  if (permissionTokenRefresh) {
407
401
  auth = /*#__PURE__*/function () {
408
402
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(cb) {
409
- var token, _data, _data$meta, authenticationError;
403
+ var authData, token, _data, _data$meta, authenticationError;
410
404
  return _regenerator.default.wrap(function _callee2$(_context2) {
411
405
  while (1) switch (_context2.prev = _context2.next) {
412
406
  case 0:
407
+ // Rebuild authData to ensure values are current
408
+ authData = {
409
+ // The initialized status. If false, BE will send document, otherwise not.
410
+ initialized: _this2.initialized,
411
+ // ESS-1009 Allow to opt-in into 404 response
412
+ need404: _this2.config.need404
413
+ }; // use the cached token if caching in enabled and token valid
413
414
  if (!(cacheToken && _this2.token)) {
414
- _context2.next = 5;
415
+ _context2.next = 6;
415
416
  break;
416
417
  }
417
418
  authData.token = _this2.token;
418
419
  cb(authData);
419
- _context2.next = 17;
420
+ _context2.next = 18;
420
421
  break;
421
- case 5:
422
- _context2.prev = 5;
423
- _context2.next = 8;
422
+ case 6:
423
+ _context2.prev = 6;
424
+ _context2.next = 9;
424
425
  return permissionTokenRefresh();
425
- case 8:
426
+ case 9:
426
427
  token = _context2.sent;
427
428
  if (token) {
428
429
  // save token locally
@@ -433,11 +434,11 @@ var Channel = /*#__PURE__*/function (_Emitter) {
433
434
  authData.token = undefined;
434
435
  }
435
436
  cb(authData);
436
- _context2.next = 17;
437
+ _context2.next = 18;
437
438
  break;
438
- case 13:
439
- _context2.prev = 13;
440
- _context2.t0 = _context2["catch"](5);
439
+ case 14:
440
+ _context2.prev = 14;
441
+ _context2.t0 = _context2["catch"](6);
441
442
  // Pass the error back to the consumers so they can deal with exceptional cases themselves (eg. no permissions because the page was deleted)
442
443
  authenticationError = {
443
444
  message: 'Insufficient editing permissions',
@@ -453,18 +454,23 @@ var Channel = /*#__PURE__*/function (_Emitter) {
453
454
  };
454
455
 
455
456
  _this2.emit('error', authenticationError);
456
- case 17:
457
+ case 18:
457
458
  case "end":
458
459
  return _context2.stop();
459
460
  }
460
- }, _callee2, null, [[5, 13]]);
461
+ }, _callee2, null, [[6, 14]]);
461
462
  }));
462
463
  return function auth(_x2) {
463
464
  return _ref3.apply(this, arguments);
464
465
  };
465
466
  }();
466
467
  } else {
467
- auth = authData;
468
+ auth = {
469
+ // The initialized status. If false, BE will send document, otherwise not.
470
+ initialized: this.initialized,
471
+ // ESS-1009 Allow to opt-in into 404 response
472
+ need404: this.config.need404
473
+ };
468
474
  }
469
475
  this.socket = createSocket("".concat(url, "/session/").concat(documentAri), auth, this.config.productInfo);
470
476
 
@@ -33,8 +33,10 @@ var Network = /*#__PURE__*/function () {
33
33
  if (props !== null && props !== void 0 && props.onlineCallback) {
34
34
  this.onlineCallback = props.onlineCallback;
35
35
  }
36
- window.addEventListener('offline', this.offlineHandler);
37
- window.addEventListener('online', this.onlineHandler);
36
+ if (typeof window !== 'undefined') {
37
+ window.addEventListener('offline', this.offlineHandler);
38
+ window.addEventListener('online', this.onlineHandler);
39
+ }
38
40
  }
39
41
  (0, _createClass2.default)(Network, [{
40
42
  key: "getStatus",
@@ -42,10 +42,12 @@ var DocumentService = /*#__PURE__*/function () {
42
42
  * @param onErrorHandled - Callback to handle
43
43
  * @param metadataService
44
44
  * @param failedStepsBeforeCatchupOnPublish - Control MAX_STEP_REJECTED_ERROR during page publishes.
45
+ * @param enableErrorOnFailedDocumentApply - Enable failed document update exceptions.
45
46
  */
46
47
  function DocumentService(participantsService, analyticsHelper, fetchCatchup, providerEmitCallback, broadcast, getUserId, onErrorHandled, metadataService) {
47
48
  var _this = this;
48
49
  var failedStepsBeforeCatchupOnPublish = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : _provider.MAX_STEP_REJECTED_ERROR;
50
+ var enableErrorOnFailedDocumentApply = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
49
51
  (0, _classCallCheck2.default)(this, DocumentService);
50
52
  // Fires analytics to editor when collab editor cannot sync up
51
53
  (0, _defineProperty2.default)(this, "stepRejectCounter", 0);
@@ -328,13 +330,59 @@ var DocumentService = /*#__PURE__*/function () {
328
330
  }, reserveCursor ? {
329
331
  reserveCursor: reserveCursor
330
332
  } : {}));
333
+ var updatedVersion = _this.getCurrentPmVersion();
334
+ if (_this.getCurrentPmVersion() !== version) {
335
+ var _doc$content, _this$analyticsHelper17;
336
+ var isDocContentValid = _this.validatePMJSONDocument(doc);
337
+ var _error = new _errorTypes.UpdateDocumentError('Failed to update the document', {
338
+ newVersion: version,
339
+ editorVersion: updatedVersion,
340
+ isDocTruthy: !!doc,
341
+ docHasContent: (doc === null || doc === void 0 ? void 0 : (_doc$content = doc.content) === null || _doc$content === void 0 ? void 0 : _doc$content.length) >= 1,
342
+ isDocContentValid: isDocContentValid
343
+ });
344
+ (_this$analyticsHelper17 = _this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 ? void 0 : _this$analyticsHelper17.sendErrorEvent(_error, 'Failed to update the document in document service');
345
+ if (_this.enableErrorOnFailedDocumentApply) {
346
+ _this.onErrorHandled({
347
+ message: 'The provider failed to apply changes to the editor',
348
+ data: {
349
+ code: _errorTypes.INTERNAL_ERROR_CODE.DOCUMENT_UPDATE_ERROR,
350
+ meta: {
351
+ newVersion: version,
352
+ editorVersion: updatedVersion
353
+ },
354
+ status: 500
355
+ }
356
+ });
357
+ throw _error;
358
+ }
359
+ // Otherwise just fail silently for now
360
+ }
361
+ });
362
+ (0, _defineProperty2.default)(this, "validatePMJSONDocument", function (doc) {
363
+ try {
364
+ var state = _this.getState();
365
+ var content = (doc.content || []).map(function (child) {
366
+ return state.schema.nodeFromJSON(child);
367
+ });
368
+ return content.every(function (node) {
369
+ try {
370
+ node.check(); // this will throw an error if the node is invalid
371
+ } catch (error) {
372
+ return false;
373
+ }
374
+ return true;
375
+ });
376
+ } catch (e) {
377
+ return false;
378
+ }
331
379
  });
332
380
  /**
333
381
  * Commit the unconfirmed local steps to the back-end service
334
382
  * @throws {Error} Couldn't sync the steps after retrying 30 times
335
383
  */
336
384
  (0, _defineProperty2.default)(this, "commitUnconfirmedSteps", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
337
- var unconfirmedSteps, _this$analyticsHelper18, count, unconfirmedTrs, lastTr, isLastTrConfirmed, nextUnconfirmedSteps, nextUnconfirmedTrs, _this$getUnconfirmedS, _this$analyticsHelper17, state, unconfirmedStepsInfoUGCRemoved, measure, _this$analyticsHelper19, _this$analyticsHelper20, _measure3;
385
+ var unconfirmedSteps, _this$analyticsHelper19, count, unconfirmedTrs, lastTr, isLastTrConfirmed, nextUnconfirmedSteps, nextUnconfirmedTrs, _this$getUnconfirmedS, _this$analyticsHelper18, state, unconfirmedStepsInfoUGCRemoved, measure, _this$analyticsHelper20, _this$analyticsHelper21, _measure3;
338
386
  return _regenerator.default.wrap(function _callee4$(_context4) {
339
387
  while (1) switch (_context4.prev = _context4.next) {
340
388
  case 0:
@@ -387,7 +435,7 @@ var DocumentService = /*#__PURE__*/function () {
387
435
  unconfirmedStepsInfoUGCRemoved = (_this$getUnconfirmedS = _this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS === void 0 ? void 0 : _this$getUnconfirmedS.map(function (step) {
388
436
  return (0, _utils.getStepUGCFreeDetails)(step);
389
437
  });
390
- (_this$analyticsHelper17 = _this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 ? void 0 : _this$analyticsHelper17.sendErrorEvent({
438
+ (_this$analyticsHelper18 = _this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 ? void 0 : _this$analyticsHelper18.sendErrorEvent({
391
439
  unconfirmedStepsInfo: unconfirmedStepsInfoUGCRemoved
392
440
  }, "Can't sync up with Collab Service: unable to send unconfirmed steps and max retry reached");
393
441
  throw new Error("Can't sync up with Collab Service");
@@ -396,7 +444,7 @@ var DocumentService = /*#__PURE__*/function () {
396
444
  break;
397
445
  case 21:
398
446
  measure = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
399
- (_this$analyticsHelper18 = _this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 ? void 0 : _this$analyticsHelper18.sendActionEvent(_const.EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, _const.EVENT_STATUS.SUCCESS, {
447
+ (_this$analyticsHelper19 = _this.analyticsHelper) === null || _this$analyticsHelper19 === void 0 ? void 0 : _this$analyticsHelper19.sendActionEvent(_const.EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, _const.EVENT_STATUS.SUCCESS, {
400
448
  latency: measure === null || measure === void 0 ? void 0 : measure.duration,
401
449
  // upon success, emit the total number of unconfirmed steps we synced
402
450
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
@@ -408,11 +456,11 @@ var DocumentService = /*#__PURE__*/function () {
408
456
  _context4.prev = 25;
409
457
  _context4.t0 = _context4["catch"](1);
410
458
  _measure3 = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.COMMIT_UNCONFIRMED_STEPS, _this.analyticsHelper);
411
- (_this$analyticsHelper19 = _this.analyticsHelper) === null || _this$analyticsHelper19 === void 0 ? void 0 : _this$analyticsHelper19.sendActionEvent(_const.EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, _const.EVENT_STATUS.FAILURE, {
459
+ (_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 ? void 0 : _this$analyticsHelper20.sendActionEvent(_const.EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS, _const.EVENT_STATUS.FAILURE, {
412
460
  latency: _measure3 === null || _measure3 === void 0 ? void 0 : _measure3.duration,
413
461
  numUnconfirmedSteps: unconfirmedSteps === null || unconfirmedSteps === void 0 ? void 0 : unconfirmedSteps.length
414
462
  });
415
- (_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 ? void 0 : _this$analyticsHelper20.sendErrorEvent(_context4.t0, 'Error while committing unconfirmed steps');
463
+ (_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 ? void 0 : _this$analyticsHelper21.sendErrorEvent(_context4.t0, 'Error while committing unconfirmed steps');
416
464
  throw _context4.t0;
417
465
  case 31:
418
466
  case "end":
@@ -421,17 +469,17 @@ var DocumentService = /*#__PURE__*/function () {
421
469
  }, _callee4, null, [[1, 25]]);
422
470
  })));
423
471
  (0, _defineProperty2.default)(this, "onStepRejectedError", function () {
424
- var _this$analyticsHelper21;
472
+ var _this$analyticsHelper22;
425
473
  _this.stepRejectCounter++;
426
474
  logger("Steps rejected (tries=".concat(_this.stepRejectCounter, ")"));
427
- (_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 ? void 0 : _this$analyticsHelper21.sendActionEvent(_const.EVENT_ACTION.SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO, {
475
+ (_this$analyticsHelper22 = _this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 ? void 0 : _this$analyticsHelper22.sendActionEvent(_const.EVENT_ACTION.SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO, {
428
476
  count: _this.stepRejectCounter
429
477
  });
430
478
  var maxRetries = _this.aggressiveCatchup ? _this.failedStepsBeforeCatchupOnPublish : _provider.MAX_STEP_REJECTED_ERROR;
431
479
  if (_this.stepRejectCounter >= maxRetries) {
432
- var _this$analyticsHelper22;
480
+ var _this$analyticsHelper23;
433
481
  logger("The steps were rejected too many times (tries=".concat(_this.stepRejectCounter, ", limit=").concat(_provider.MAX_STEP_REJECTED_ERROR, "). Trying to catch-up."));
434
- (_this$analyticsHelper22 = _this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 ? void 0 : _this$analyticsHelper22.sendActionEvent(_const.EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO);
482
+ (_this$analyticsHelper23 = _this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 ? void 0 : _this$analyticsHelper23.sendActionEvent(_const.EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO);
435
483
  _this.throttledCatchup();
436
484
  } else {
437
485
  // If committing steps failed try again automatically in 1s
@@ -452,6 +500,7 @@ var DocumentService = /*#__PURE__*/function () {
452
500
  this.onErrorHandled = onErrorHandled;
453
501
  this.metadataService = metadataService;
454
502
  this.failedStepsBeforeCatchupOnPublish = failedStepsBeforeCatchupOnPublish;
503
+ this.enableErrorOnFailedDocumentApply = enableErrorOnFailedDocumentApply;
455
504
  this.stepQueue = new _stepQueueState.StepQueueState();
456
505
  }
457
506
  (0, _createClass2.default)(DocumentService, [{
@@ -503,9 +552,9 @@ var DocumentService = /*#__PURE__*/function () {
503
552
  }, 100);
504
553
  }
505
554
  } catch (error) {
506
- var _this$analyticsHelper23;
555
+ var _this$analyticsHelper24;
507
556
  logger("Processing steps failed with error: ".concat(error, ". Triggering catch up call."));
508
- (_this$analyticsHelper23 = this.analyticsHelper) === null || _this$analyticsHelper23 === void 0 ? void 0 : _this$analyticsHelper23.sendErrorEvent(error, 'Error while processing steps');
557
+ (_this$analyticsHelper24 = this.analyticsHelper) === null || _this$analyticsHelper24 === void 0 ? void 0 : _this$analyticsHelper24.sendErrorEvent(error, 'Error while processing steps');
509
558
  this.throttledCatchup();
510
559
  }
511
560
  }
@@ -71,6 +71,13 @@ var errorCodeMapper = function errorCodeMapper(error) {
71
71
  recoverable: false,
72
72
  status: 500
73
73
  };
74
+ case _errorTypes.INTERNAL_ERROR_CODE.DOCUMENT_UPDATE_ERROR:
75
+ return {
76
+ code: _errorTypes.PROVIDER_ERROR_CODE.DOCUMENT_UPDATE_ERROR,
77
+ message: 'The provider failed to apply changes to the editor',
78
+ recoverable: false,
79
+ status: 500
80
+ };
74
81
  case _errorTypes.INTERNAL_ERROR_CODE.RECONNECTION_NETWORK_ISSUE:
75
82
  return {
76
83
  code: _errorTypes.PROVIDER_ERROR_CODE.NETWORK_ISSUE,
@@ -4,15 +4,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.SetTitleError = exports.SetMetadataError = exports.SetEditorWidthError = exports.SendTransactionError = exports.ProviderInitialisationError = exports.PROVIDER_ERROR_CODE = exports.NotInitializedError = exports.NotConnectedError = exports.NCS_ERROR_CODE = exports.INTERNAL_ERROR_CODE = exports.GetFinalAcknowledgedStateError = exports.GetCurrentStateError = exports.DestroyError = void 0;
8
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
+ exports.UpdateDocumentError = exports.SetTitleError = exports.SetMetadataError = exports.SetEditorWidthError = exports.SendTransactionError = exports.ProviderInitialisationError = exports.PROVIDER_ERROR_CODE = exports.NotInitializedError = exports.NotConnectedError = exports.NCS_ERROR_CODE = exports.INTERNAL_ERROR_CODE = exports.GetFinalAcknowledgedStateError = exports.GetCurrentStateError = exports.DestroyError = exports.CustomError = void 0;
10
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
12
11
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
12
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
13
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
14
  var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
16
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
17
17
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
18
  // Internal error codes (generated by collab provider)
@@ -25,6 +25,7 @@ var INTERNAL_ERROR_CODE = /*#__PURE__*/function (INTERNAL_ERROR_CODE) {
25
25
  INTERNAL_ERROR_CODE["CATCHUP_FAILED"] = "CATCHUP_FAILED";
26
26
  INTERNAL_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR";
27
27
  INTERNAL_ERROR_CODE["ADD_STEPS_ERROR"] = "ADD_STEPS_ERROR";
28
+ INTERNAL_ERROR_CODE["DOCUMENT_UPDATE_ERROR"] = "DOCUMENT_UPDATE_ERROR";
28
29
  return INTERNAL_ERROR_CODE;
29
30
  }({}); // NCS error coded (generated by NCS)
30
31
  exports.INTERNAL_ERROR_CODE = INTERNAL_ERROR_CODE;
@@ -55,6 +56,10 @@ var NCS_ERROR_CODE = /*#__PURE__*/function (NCS_ERROR_CODE) {
55
56
  // - Less common back-end errors
56
57
  // Provider Errors
57
58
  // Channel Errors
59
+ /**
60
+ * When we try to apply state updates to the editor, if that fails to apply the user can enter an invalid state where no
61
+ * changes can be saved to NCS.
62
+ */
58
63
  /**
59
64
  * A union of all possible internal errors, that are mapped to another error if being emitted to the editor.
60
65
  */
@@ -71,6 +76,7 @@ var PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
71
76
  PROVIDER_ERROR_CODE["NETWORK_ISSUE"] = "NETWORK_ISSUE";
72
77
  PROVIDER_ERROR_CODE["INVALID_PROVIDER_CONFIGURATION"] = "INVALID_PROVIDER_CONFIGURATION";
73
78
  PROVIDER_ERROR_CODE["INTERNAL_SERVICE_ERROR"] = "INTERNAL_SERVICE_ERROR";
79
+ PROVIDER_ERROR_CODE["DOCUMENT_UPDATE_ERROR"] = "DOCUMENT_UPDATE_ERROR";
74
80
  return PROVIDER_ERROR_CODE;
75
81
  }({});
76
82
  /*
@@ -170,13 +176,19 @@ exports.PROVIDER_ERROR_CODE = PROVIDER_ERROR_CODE;
170
176
  var CustomError = /*#__PURE__*/function (_Error) {
171
177
  (0, _inherits2.default)(CustomError, _Error);
172
178
  var _super = _createSuper(CustomError);
173
- function CustomError(message, error) {
179
+ function CustomError(message, error, extraEventAttributes) {
174
180
  var _this;
175
181
  (0, _classCallCheck2.default)(this, CustomError);
176
182
  _this = _super.call(this, message);
183
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getExtraErrorEventAttributes", function () {
184
+ return _this.extraEventAttributes;
185
+ });
177
186
  if (typeof (error === null || error === void 0 ? void 0 : error.message) === 'string') {
178
187
  _this.message = error.message;
179
188
  }
189
+ if (extraEventAttributes) {
190
+ _this.extraEventAttributes = extraEventAttributes;
191
+ }
180
192
  return _this;
181
193
  }
182
194
  (0, _createClass2.default)(CustomError, [{
@@ -190,6 +202,7 @@ var CustomError = /*#__PURE__*/function (_Error) {
190
202
  }]);
191
203
  return CustomError;
192
204
  }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
205
+ exports.CustomError = CustomError;
193
206
  var NotConnectedError = /*#__PURE__*/function (_CustomError) {
194
207
  (0, _inherits2.default)(NotConnectedError, _CustomError);
195
208
  var _super2 = _createSuper(NotConnectedError);
@@ -349,4 +362,17 @@ var GetFinalAcknowledgedStateError = /*#__PURE__*/function (_CustomError10) {
349
362
  }
350
363
  return (0, _createClass2.default)(GetFinalAcknowledgedStateError);
351
364
  }(CustomError);
352
- exports.GetFinalAcknowledgedStateError = GetFinalAcknowledgedStateError;
365
+ exports.GetFinalAcknowledgedStateError = GetFinalAcknowledgedStateError;
366
+ var UpdateDocumentError = /*#__PURE__*/function (_CustomError11) {
367
+ (0, _inherits2.default)(UpdateDocumentError, _CustomError11);
368
+ var _super12 = _createSuper(UpdateDocumentError);
369
+ function UpdateDocumentError(message, extraAttributes) {
370
+ var _this12;
371
+ (0, _classCallCheck2.default)(this, UpdateDocumentError);
372
+ _this12 = _super12.call(this, message, undefined, extraAttributes);
373
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this12), "name", 'UpdateDocumentError');
374
+ return _this12;
375
+ }
376
+ return (0, _createClass2.default)(UpdateDocumentError);
377
+ }(CustomError);
378
+ exports.UpdateDocumentError = UpdateDocumentError;
@@ -89,12 +89,19 @@ var Provider = /*#__PURE__*/function (_Emitter) {
89
89
  document = _this$initialDraft.document,
90
90
  version = _this$initialDraft.version,
91
91
  metadata = _this$initialDraft.metadata;
92
- // Initial document, version, metadata from initial draft
93
- _this.documentService.updateDocument({
94
- doc: document,
95
- version: version,
96
- metadata: metadata
97
- });
92
+ try {
93
+ // Initial document, version, metadata from initial draft
94
+ _this.documentService.updateDocument({
95
+ doc: document,
96
+ version: version,
97
+ metadata: metadata
98
+ });
99
+ } catch (e) {
100
+ var _this$analyticsHelper;
101
+ (_this$analyticsHelper = _this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(e, 'Failed to update the document on reconnect, destroying provider');
102
+ // Stop events and connections to step us trying to talk to the backend with an invalid state.
103
+ _this.destroy();
104
+ }
98
105
  _this.metadataService.updateMetadata(metadata);
99
106
  }
100
107
  _this.isProviderInitialized = true;
@@ -112,13 +119,20 @@ var Provider = /*#__PURE__*/function (_Emitter) {
112
119
  version = _ref2.version,
113
120
  metadata = _ref2.metadata;
114
121
  // Initial document and version
115
- _this.documentService.updateDocument({
116
- doc: doc,
117
- version: version,
118
- metadata: metadata
119
- });
120
- _this.metadataService.updateMetadata(metadata);
121
- _this.isProviderInitialized = true;
122
+ try {
123
+ _this.documentService.updateDocument({
124
+ doc: doc,
125
+ version: version,
126
+ metadata: metadata
127
+ });
128
+ _this.metadataService.updateMetadata(metadata);
129
+ _this.isProviderInitialized = true;
130
+ } catch (e) {
131
+ var _this$analyticsHelper2;
132
+ (_this$analyticsHelper2 = _this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(e, 'Failed to update with the init document, destroying provider');
133
+ // Stop events and connections to step us trying to talk to the backend with an invalid state.
134
+ _this.destroy();
135
+ }
122
136
  }).on('restore', _this.documentService.onRestore).on('steps:added', _this.documentService.onStepsAdded).on('metadata:changed', _this.metadataService.onMetadataChanged).on('participant:telepointer', function (payload) {
123
137
  return _this.participantsService.onParticipantTelepointer(payload, _this.sessionId);
124
138
  }).on('presence:joined', _this.participantsService.onPresenceJoined).on('presence', _this.participantsService.onPresence).on('participant:left', _this.participantsService.onParticipantLeft).on('participant:updated', _this.participantsService.onParticipantUpdated).on('disconnect', _this.onDisconnected.bind((0, _assertThisInitialized2.default)(_this))).on('error', _this.onErrorHandled).on('status', _this.namespaceService.onNamespaceStatusChanged).connect(shouldInitialize);
@@ -144,13 +158,13 @@ var Provider = /*#__PURE__*/function (_Emitter) {
144
158
  if (((_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.code) === _errorTypes.NCS_ERROR_CODE.HEAD_VERSION_UPDATE_FAILED || ((_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.code) === _errorTypes.NCS_ERROR_CODE.VERSION_NUMBER_ALREADY_EXISTS) {
145
159
  _this.documentService.onStepRejectedError();
146
160
  } else {
147
- var _this$analyticsHelper;
148
- (_this$analyticsHelper = _this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(error, 'Error handled');
161
+ var _this$analyticsHelper3;
162
+ (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(error, 'Error handled');
149
163
  var mappedError = (0, _errorCodeMapper.errorCodeMapper)(error);
150
164
  // Temporarily only emit errors to Confluence very intentionally because they will disconnect the collab provider
151
165
  if (mappedError) {
152
- var _this$analyticsHelper2;
153
- (_this$analyticsHelper2 = _this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(mappedError, 'Error emitted');
166
+ var _this$analyticsHelper4;
167
+ (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(mappedError, 'Error emitted');
154
168
  _this.emitCallback('error', mappedError);
155
169
  }
156
170
  }
@@ -173,7 +187,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
173
187
  * @throws {GetCurrentStateError} Something went wrong while returning the current state
174
188
  */
175
189
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getCurrentState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
176
- var _this$analyticsHelper3;
190
+ var _this$analyticsHelper5;
177
191
  return _regenerator.default.wrap(function _callee$(_context) {
178
192
  while (1) switch (_context.prev = _context.next) {
179
193
  case 0:
@@ -182,7 +196,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
182
196
  case 4:
183
197
  _context.prev = 4;
184
198
  _context.t0 = _context["catch"](0);
185
- (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(_context.t0, 'Error while returning ADF version of current draft document');
199
+ (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(_context.t0, 'Error while returning ADF version of current draft document');
186
200
  throw new _errorTypes.GetCurrentStateError('Error while returning the current state of the draft document', _context.t0);
187
201
  case 8:
188
202
  case "end":
@@ -196,7 +210,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
196
210
  * @throws {GetFinalAcknowledgedStateError} Something went wrong while returning the acknowledged state
197
211
  */
198
212
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getFinalAcknowledgedState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
199
- var _this$analyticsHelper4;
213
+ var _this$analyticsHelper6;
200
214
  return _regenerator.default.wrap(function _callee2$(_context2) {
201
215
  while (1) switch (_context2.prev = _context2.next) {
202
216
  case 0:
@@ -208,7 +222,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
208
222
  case 6:
209
223
  _context2.prev = 6;
210
224
  _context2.t0 = _context2["catch"](0);
211
- (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(_context2.t0, 'Error while returning ADF version of the final draft document');
225
+ (_this$analyticsHelper6 = _this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(_context2.t0, 'Error while returning ADF version of the final draft document');
212
226
  throw new _errorTypes.GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', _context2.t0);
213
227
  case 10:
214
228
  case "end":
@@ -243,7 +257,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
243
257
  _this.metadataService = new _metadataService.MetadataService(_this.emitCallback, _this.channel.sendMetadata);
244
258
  _this.documentService = new _documentService.DocumentService(_this.participantsService, _this.analyticsHelper, _this.channel.fetchCatchup, _this.emitCallback, _this.channel.broadcast, function () {
245
259
  return _this.userId;
246
- }, _this.onErrorHandled, _this.metadataService, _this.config.failedStepLimitBeforeCatchupOnPublish);
260
+ }, _this.onErrorHandled, _this.metadataService, _this.config.failedStepLimitBeforeCatchupOnPublish, _this.config.enableErrorOnFailedDocumentApply);
247
261
  _this.getStatePromise = new Promise(function (resolve) {
248
262
  _this.getStatePromiseResolve = resolve;
249
263
  });
@@ -312,8 +326,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
312
326
  this.isChannelInitialized = true;
313
327
  }
314
328
  } catch (initError) {
315
- var _this$analyticsHelper5;
316
- (_this$analyticsHelper5 = this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(initError, 'Error while initialising the provider');
329
+ var _this$analyticsHelper7;
330
+ (_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(initError, 'Error while initialising the provider');
317
331
  // Throw error so consumers are aware the initialisation failed when initialising themselves
318
332
  throw new _errorTypes.ProviderInitialisationError('Provider initialisation error', initError);
319
333
  }
@@ -323,9 +337,9 @@ var Provider = /*#__PURE__*/function (_Emitter) {
323
337
  key: "checkForCookies",
324
338
  value: function checkForCookies() {
325
339
  if (!global.navigator.cookieEnabled) {
326
- var _this$analyticsHelper6;
340
+ var _this$analyticsHelper8;
327
341
  var initError = new _errorTypes.ProviderInitialisationError('Cookies are not enabled. Please enable cookies to use collaborative editing.');
328
- (_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
342
+ (_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
329
343
  throw new _errorTypes.ProviderInitialisationError('Provider initialisation error - cookies disabled', initError);
330
344
  }
331
345
  }
@@ -363,8 +377,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
363
377
  }
364
378
  this.documentService.send(_tr, _oldState, newState);
365
379
  } catch (error) {
366
- var _this$analyticsHelper7;
367
- (_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(error, 'Error while sending steps for a transaction');
380
+ var _this$analyticsHelper9;
381
+ (_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(error, 'Error while sending steps for a transaction');
368
382
  throw new _errorTypes.SendTransactionError('Error while sending steps for a transaction', error);
369
383
  }
370
384
  }
@@ -392,9 +406,9 @@ var Provider = /*#__PURE__*/function (_Emitter) {
392
406
  this.channel.broadcast('participant:telepointer', payload, callback);
393
407
  }
394
408
  } catch (error) {
395
- var _this$analyticsHelper8;
409
+ var _this$analyticsHelper10;
396
410
  // We don't want to throw errors for Presence features as they tend to self-restore
397
- (_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(error, 'Error while sending message - telepointer');
411
+ (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(error, 'Error while sending message - telepointer');
398
412
  }
399
413
  }
400
414
  }, {
@@ -433,8 +447,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
433
447
  (0, _get2.default)((0, _getPrototypeOf2.default)(Provider.prototype), "unsubscribeAll", this).call(this);
434
448
  this.channel.disconnect();
435
449
  } catch (error) {
436
- var _this$analyticsHelper9;
437
- (_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(error, 'Error while shutting down the collab provider');
450
+ var _this$analyticsHelper11;
451
+ (_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, 'Error while shutting down the collab provider');
438
452
  throw new _errorTypes.DestroyError('Error while shutting down the collab provider', error);
439
453
  }
440
454
  this.clearTimers();
@@ -454,8 +468,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
454
468
  try {
455
469
  this.metadataService.setTitle(title, broadcast);
456
470
  } catch (error) {
457
- var _this$analyticsHelper10;
458
- (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(error, 'Error while setting title');
471
+ var _this$analyticsHelper12;
472
+ (_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while setting title');
459
473
  throw new _errorTypes.SetTitleError('Error while setting title', error);
460
474
  }
461
475
  }
@@ -473,8 +487,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
473
487
  try {
474
488
  this.metadataService.setEditorWidth(editorWidth, broadcast);
475
489
  } catch (error) {
476
- var _this$analyticsHelper11;
477
- (_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, 'Error while setting editor width');
490
+ var _this$analyticsHelper13;
491
+ (_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(error, 'Error while setting editor width');
478
492
  throw new _errorTypes.SetEditorWidthError('Error while setting editor width', error);
479
493
  }
480
494
  }
@@ -490,8 +504,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
490
504
  try {
491
505
  this.metadataService.setMetadata(metadata);
492
506
  } catch (error) {
493
- var _this$analyticsHelper12;
494
- (_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while setting metadata');
507
+ var _this$analyticsHelper14;
508
+ (_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendErrorEvent(error, 'Error while setting metadata');
495
509
  throw new _errorTypes.SetMetadataError('Error while setting metadata', error);
496
510
  }
497
511
  }
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = "@atlaskit/collab-provider";
8
8
  exports.name = name;
9
- var version = "9.3.0";
9
+ var version = "9.4.0";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "9.3.0",
3
+ "version": "9.4.0",
4
4
  "sideEffects": false
5
5
  }