@atlaskit/collab-provider 9.6.4 → 9.7.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/disconnected-reason-mapper.js +8 -17
  3. package/dist/cjs/errors/error-code-mapper.js +13 -12
  4. package/dist/cjs/errors/error-types.js +2 -95
  5. package/dist/cjs/index.js +2 -2
  6. package/dist/cjs/provider/index.js +88 -69
  7. package/dist/cjs/types.js +1 -1
  8. package/dist/cjs/version-wrapper.js +1 -1
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/disconnected-reason-mapper.js +2 -9
  11. package/dist/es2019/errors/error-code-mapper.js +2 -1
  12. package/dist/es2019/errors/error-types.js +0 -94
  13. package/dist/es2019/index.js +1 -1
  14. package/dist/es2019/provider/index.js +77 -57
  15. package/dist/es2019/types.js +1 -1
  16. package/dist/es2019/version-wrapper.js +1 -1
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/disconnected-reason-mapper.js +2 -9
  19. package/dist/esm/errors/error-code-mapper.js +2 -1
  20. package/dist/esm/errors/error-types.js +0 -94
  21. package/dist/esm/index.js +1 -1
  22. package/dist/esm/provider/index.js +88 -69
  23. package/dist/esm/types.js +1 -1
  24. package/dist/esm/version-wrapper.js +1 -1
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/channel.d.ts +2 -1
  27. package/dist/types/disconnected-reason-mapper.d.ts +1 -8
  28. package/dist/types/document/document-service.d.ts +3 -2
  29. package/dist/types/errors/error-code-mapper.d.ts +2 -1
  30. package/dist/types/errors/error-types.d.ts +0 -190
  31. package/dist/types/helpers/const.d.ts +1 -1
  32. package/dist/types/index.d.ts +3 -3
  33. package/dist/types/metadata/metadata-service.d.ts +1 -1
  34. package/dist/types/participants/participants-helper.d.ts +2 -6
  35. package/dist/types/participants/participants-service.d.ts +3 -2
  36. package/dist/types/participants/participants-state.d.ts +2 -1
  37. package/dist/types/participants/telepointers-helper.d.ts +2 -2
  38. package/dist/types/provider/commit-step.d.ts +2 -1
  39. package/dist/types/provider/index.d.ts +11 -5
  40. package/dist/types/socket-io-provider.d.ts +1 -1
  41. package/dist/types/types.d.ts +2 -149
  42. package/dist/types-ts4.5/channel.d.ts +2 -1
  43. package/dist/types-ts4.5/disconnected-reason-mapper.d.ts +1 -8
  44. package/dist/types-ts4.5/document/document-service.d.ts +3 -2
  45. package/dist/types-ts4.5/errors/error-code-mapper.d.ts +2 -1
  46. package/dist/types-ts4.5/errors/error-types.d.ts +0 -190
  47. package/dist/types-ts4.5/helpers/const.d.ts +1 -1
  48. package/dist/types-ts4.5/index.d.ts +3 -3
  49. package/dist/types-ts4.5/metadata/metadata-service.d.ts +1 -1
  50. package/dist/types-ts4.5/participants/participants-helper.d.ts +2 -6
  51. package/dist/types-ts4.5/participants/participants-service.d.ts +3 -2
  52. package/dist/types-ts4.5/participants/participants-state.d.ts +2 -1
  53. package/dist/types-ts4.5/participants/telepointers-helper.d.ts +2 -2
  54. package/dist/types-ts4.5/provider/commit-step.d.ts +2 -1
  55. package/dist/types-ts4.5/provider/index.d.ts +11 -5
  56. package/dist/types-ts4.5/socket-io-provider.d.ts +1 -1
  57. package/dist/types-ts4.5/types.d.ts +2 -149
  58. package/package.json +2 -1
  59. package/report.api.md +51 -392
  60. package/tmp/api-report-tmp.d.ts +51 -375
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/collab-provider
2
2
 
3
+ ## 9.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`14224c3f8a4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/14224c3f8a4) - [ED-18162] Move the collab provider types to the editor common package to avoid circular dependencies
8
+
9
+ ## 9.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`3265cccb965`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3265cccb965) - resolving editor state before updating document/metadata during early provider initialization
14
+
3
15
  ## 9.6.4
4
16
 
5
17
  ### Patch Changes
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.socketIOReasons = exports.disconnectedReasonMapper = exports.DisconnectReason = void 0;
6
+ exports.socketIOReasons = exports.disconnectedReasonMapper = void 0;
7
+ var _collab = require("@atlaskit/editor-common/collab");
7
8
  // See https://socket.io/docs/v3/client-socket-instance#disconnect for emitted reasons
8
9
  var socketIOReasons = {
9
10
  IO_CLIENT_DISCONNECT: 'io client disconnect',
@@ -17,30 +18,20 @@ var socketIOReasons = {
17
18
  PING_TIMEOUT: 'ping timeout' // The connection has encountered an error (example: the server was killed during a HTTP long-polling cycle)
18
19
  };
19
20
  exports.socketIOReasons = socketIOReasons;
20
- var DisconnectReason = /*#__PURE__*/function (DisconnectReason) {
21
- DisconnectReason["CLIENT_DISCONNECT"] = "CLIENT_DISCONNECT";
22
- DisconnectReason["SERVER_DISCONNECT"] = "SERVER_DISCONNECT";
23
- DisconnectReason["SOCKET_CLOSED"] = "SOCKET_CLOSED";
24
- DisconnectReason["SOCKET_ERROR"] = "SOCKET_ERROR";
25
- DisconnectReason["SOCKET_TIMEOUT"] = "SOCKET_TIMEOUT";
26
- DisconnectReason["UNKNOWN_DISCONNECT"] = "UNKNOWN_DISCONNECT";
27
- return DisconnectReason;
28
- }({});
29
- exports.DisconnectReason = DisconnectReason;
30
21
  var disconnectedReasonMapper = function disconnectedReasonMapper(reason) {
31
22
  switch (reason) {
32
23
  case socketIOReasons.IO_CLIENT_DISCONNECT:
33
- return DisconnectReason.CLIENT_DISCONNECT;
24
+ return _collab.DisconnectReason.CLIENT_DISCONNECT;
34
25
  case socketIOReasons.IO_SERVER_DISCONNECT:
35
- return DisconnectReason.SERVER_DISCONNECT;
26
+ return _collab.DisconnectReason.SERVER_DISCONNECT;
36
27
  case socketIOReasons.TRANSPORT_CLOSED:
37
- return DisconnectReason.SOCKET_CLOSED;
28
+ return _collab.DisconnectReason.SOCKET_CLOSED;
38
29
  case socketIOReasons.TRANSPORT_ERROR:
39
- return DisconnectReason.SOCKET_ERROR;
30
+ return _collab.DisconnectReason.SOCKET_ERROR;
40
31
  case socketIOReasons.PING_TIMEOUT:
41
- return DisconnectReason.SOCKET_TIMEOUT;
32
+ return _collab.DisconnectReason.SOCKET_TIMEOUT;
42
33
  default:
43
- return DisconnectReason.UNKNOWN_DISCONNECT;
34
+ return _collab.DisconnectReason.UNKNOWN_DISCONNECT;
44
35
  }
45
36
  };
46
37
  exports.disconnectedReasonMapper = disconnectedReasonMapper;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.errorCodeMapper = void 0;
7
7
  var _errorTypes = require("./error-types");
8
+ var _collab = require("@atlaskit/editor-common/collab");
8
9
  /*
9
10
  * Maps internal collab provider errors to an emitted error format
10
11
  */
@@ -23,7 +24,7 @@ var errorCodeMapper = function errorCodeMapper(error) {
23
24
  case _errorTypes.NCS_ERROR_CODE.INSUFFICIENT_EDITING_PERMISSION:
24
25
  case _errorTypes.INTERNAL_ERROR_CODE.TOKEN_PERMISSION_ERROR:
25
26
  return {
26
- code: _errorTypes.PROVIDER_ERROR_CODE.NO_PERMISSION_ERROR,
27
+ code: _collab.PROVIDER_ERROR_CODE.NO_PERMISSION_ERROR,
27
28
  message: 'User does not have permissions to access this document or document is not found',
28
29
  reason: error.data.meta.reason,
29
30
  recoverable: true,
@@ -31,14 +32,14 @@ var errorCodeMapper = function errorCodeMapper(error) {
31
32
  };
32
33
  case _errorTypes.NCS_ERROR_CODE.FORBIDDEN_USER_TOKEN:
33
34
  return {
34
- code: _errorTypes.PROVIDER_ERROR_CODE.INVALID_USER_TOKEN,
35
+ code: _collab.PROVIDER_ERROR_CODE.INVALID_USER_TOKEN,
35
36
  message: 'The user token was invalid',
36
37
  recoverable: true,
37
38
  status: 403
38
39
  };
39
40
  case _errorTypes.INTERNAL_ERROR_CODE.DOCUMENT_NOT_FOUND:
40
41
  return {
41
- code: _errorTypes.PROVIDER_ERROR_CODE.DOCUMENT_NOT_FOUND,
42
+ code: _collab.PROVIDER_ERROR_CODE.DOCUMENT_NOT_FOUND,
42
43
  message: 'The requested document is not found',
43
44
  recoverable: true,
44
45
  status: 404
@@ -46,41 +47,41 @@ var errorCodeMapper = function errorCodeMapper(error) {
46
47
  case _errorTypes.NCS_ERROR_CODE.TENANT_INSTANCE_MAINTENANCE:
47
48
  case _errorTypes.NCS_ERROR_CODE.LOCKED_DOCUMENT:
48
49
  return {
49
- code: _errorTypes.PROVIDER_ERROR_CODE.LOCKED,
50
+ code: _collab.PROVIDER_ERROR_CODE.LOCKED,
50
51
  message: 'The document is currently not available, please try again later',
51
52
  recoverable: true
52
53
  };
53
54
  case _errorTypes.NCS_ERROR_CODE.DYNAMO_ERROR:
54
55
  return {
55
- code: _errorTypes.PROVIDER_ERROR_CODE.FAIL_TO_SAVE,
56
+ code: _collab.PROVIDER_ERROR_CODE.FAIL_TO_SAVE,
56
57
  message: 'Collab service is not able to save changes',
57
58
  recoverable: false,
58
59
  status: 500
59
60
  };
60
61
  case _errorTypes.INTERNAL_ERROR_CODE.DOCUMENT_RESTORE_ERROR:
61
62
  return {
62
- code: _errorTypes.PROVIDER_ERROR_CODE.DOCUMENT_RESTORE_ERROR,
63
+ code: _collab.PROVIDER_ERROR_CODE.DOCUMENT_RESTORE_ERROR,
63
64
  message: 'Collab service unable to restore document',
64
65
  recoverable: false,
65
66
  status: 500
66
67
  };
67
68
  case _errorTypes.NCS_ERROR_CODE.INIT_DATA_LOAD_FAILED:
68
69
  return {
69
- code: _errorTypes.PROVIDER_ERROR_CODE.INITIALISATION_ERROR,
70
+ code: _collab.PROVIDER_ERROR_CODE.INITIALISATION_ERROR,
70
71
  message: "The initial document couldn't be loaded from the collab service",
71
72
  recoverable: false,
72
73
  status: 500
73
74
  };
74
75
  case _errorTypes.INTERNAL_ERROR_CODE.DOCUMENT_UPDATE_ERROR:
75
76
  return {
76
- code: _errorTypes.PROVIDER_ERROR_CODE.DOCUMENT_UPDATE_ERROR,
77
+ code: _collab.PROVIDER_ERROR_CODE.DOCUMENT_UPDATE_ERROR,
77
78
  message: 'The provider failed to apply changes to the editor',
78
79
  recoverable: false,
79
80
  status: 500
80
81
  };
81
82
  case _errorTypes.INTERNAL_ERROR_CODE.RECONNECTION_NETWORK_ISSUE:
82
83
  return {
83
- code: _errorTypes.PROVIDER_ERROR_CODE.NETWORK_ISSUE,
84
+ code: _collab.PROVIDER_ERROR_CODE.NETWORK_ISSUE,
84
85
  message: "Couldn't reconnect to the collab service due to network issues",
85
86
  recoverable: true,
86
87
  status: 500
@@ -90,7 +91,7 @@ var errorCodeMapper = function errorCodeMapper(error) {
90
91
  case _errorTypes.NCS_ERROR_CODE.INVALID_DOCUMENT_ARI:
91
92
  case _errorTypes.NCS_ERROR_CODE.INVALID_CLOUD_ID:
92
93
  return {
93
- code: _errorTypes.PROVIDER_ERROR_CODE.INVALID_PROVIDER_CONFIGURATION,
94
+ code: _collab.PROVIDER_ERROR_CODE.INVALID_PROVIDER_CONFIGURATION,
94
95
  message: 'Invalid provider configuration',
95
96
  recoverable: false,
96
97
  reason: (_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.code,
@@ -100,7 +101,7 @@ var errorCodeMapper = function errorCodeMapper(error) {
100
101
  case _errorTypes.NCS_ERROR_CODE.ERROR_MAPPING_ERROR:
101
102
  case _errorTypes.NCS_ERROR_CODE.EMPTY_BROADCAST:
102
103
  return {
103
- code: _errorTypes.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
104
+ code: _collab.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
104
105
  message: 'Collab Provider experienced an unrecoverable error',
105
106
  recoverable: false,
106
107
  reason: (_error$data3 = error.data) === null || _error$data3 === void 0 ? void 0 : _error$data3.code,
@@ -108,7 +109,7 @@ var errorCodeMapper = function errorCodeMapper(error) {
108
109
  };
109
110
  case _errorTypes.INTERNAL_ERROR_CODE.CATCHUP_FAILED:
110
111
  return {
111
- code: _errorTypes.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
112
+ code: _collab.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
112
113
  message: 'Collab Provider experienced an unrecoverable error',
113
114
  recoverable: true,
114
115
  reason: (_error$data4 = error.data) === null || _error$data4 === void 0 ? void 0 : _error$data4.code,
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
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 = exports.CantSyncUpError = void 0;
7
+ exports.UpdateDocumentError = exports.SetTitleError = exports.SetMetadataError = exports.SetEditorWidthError = exports.SendTransactionError = exports.ProviderInitialisationError = exports.NotInitializedError = exports.NotConnectedError = exports.NCS_ERROR_CODE = exports.INTERNAL_ERROR_CODE = exports.GetFinalAcknowledgedStateError = exports.GetCurrentStateError = exports.DestroyError = exports.CustomError = exports.CantSyncUpError = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
@@ -63,22 +63,6 @@ var NCS_ERROR_CODE = /*#__PURE__*/function (NCS_ERROR_CODE) {
63
63
  /**
64
64
  * A union of all possible internal errors, that are mapped to another error if being emitted to the editor.
65
65
  */
66
- exports.NCS_ERROR_CODE = NCS_ERROR_CODE;
67
- // Emitted errors
68
- var PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
69
- PROVIDER_ERROR_CODE["NO_PERMISSION_ERROR"] = "NO_PERMISSION_ERROR";
70
- PROVIDER_ERROR_CODE["INVALID_USER_TOKEN"] = "INVALID_USER_TOKEN";
71
- PROVIDER_ERROR_CODE["DOCUMENT_NOT_FOUND"] = "DOCUMENT_NOT_FOUND";
72
- PROVIDER_ERROR_CODE["LOCKED"] = "LOCKED";
73
- PROVIDER_ERROR_CODE["FAIL_TO_SAVE"] = "FAIL_TO_SAVE";
74
- PROVIDER_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR";
75
- PROVIDER_ERROR_CODE["INITIALISATION_ERROR"] = "INITIALISATION_ERROR";
76
- PROVIDER_ERROR_CODE["NETWORK_ISSUE"] = "NETWORK_ISSUE";
77
- PROVIDER_ERROR_CODE["INVALID_PROVIDER_CONFIGURATION"] = "INVALID_PROVIDER_CONFIGURATION";
78
- PROVIDER_ERROR_CODE["INTERNAL_SERVICE_ERROR"] = "INTERNAL_SERVICE_ERROR";
79
- PROVIDER_ERROR_CODE["DOCUMENT_UPDATE_ERROR"] = "DOCUMENT_UPDATE_ERROR";
80
- return PROVIDER_ERROR_CODE;
81
- }({});
82
66
  /*
83
67
  * This is what a generic ProviderError type would look like:
84
68
  * type ProviderError = {
@@ -94,84 +78,7 @@ var PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
94
78
  * reason?: string;
95
79
  * }
96
80
  */
97
- /**
98
- * This occurs when the provided user token is considered invalid for the given document ARI.
99
- * It happens during initialisation of the provider.
100
- * It could mean the document has been deleted (hence not found).
101
- * @message Message returned to editor, i.e User does not have permissions to access this document or document is not found
102
- * @recoverable It is recoverable, as we will try to refresh the token.
103
- */
104
- /**
105
- * Similiar to InsufficientEditingPermission, but the user token is invalid because it has expired or been revoked.
106
- * It may also be an invalid token format.
107
- * This error is given to the provider by NCS.
108
- * @message Message returned to editor, i.e. The user token was invalid
109
- * @recoverable It is recoverable, as we will try to refresh the token.
110
- */
111
- /**
112
- * Document not found error, thrown when the provider is unable to find a document with the given ARI and user token.
113
- * It occurs during fetchCatchup, a function that fetches the latest document state during catchup.
114
- * We need to recieve a 404 from the document service to throw this error.
115
- * @message Message returned to editor, i.e. The requested document is not found
116
- * @recoverable It is recoverable, as the provider can try again later.
117
- */
118
- /**
119
- * This error is thrown when the document is locked by another user.
120
- * The error is passed to us by NCS.
121
- * @message Message returned to editor, i.e. The document is currently not available, please try again later
122
- * @recoverable It is recoverable, as the provider can try again later.
123
- */
124
- /**
125
- * This error is thrown when the provider is unable to save the document.
126
- * This can happen when the connection to dynamoDB is lost, or when we do not have sufficient permissions (DYNAMO ERROR).
127
- * This error is given to us by NCS.
128
- * @message Message returned to editor, i.e. Collab service is not able to save changes
129
- * @recoverable It is not recoverable, as we don't want the user to continue editing a document that is not being saved.
130
- */
131
- /**
132
- * This error is thrown when the provider is unable to restore the document.
133
- * It occurs during onRestore, a function that restores the document to a previous version and reapplies unconfirmed steps.
134
- * onRestore is called when page recovery has emitted an 'init' event on a page client is currently connected to.
135
- * It could mean we failed to update the page metadata, or we failed to reapply unconfirmed steps.
136
- * @message Message returned to editor, i.e. Collab service unable to restore document
137
- * @recoverable It is not recoverable, as the provider has no further options after this.
138
- * The user will need to refresh the page to try again.
139
- */
140
- /**
141
- * The initial document couldn't be loaded from the collab service.
142
- * This error is given to us by NCS.
143
- * It could indicate either a network issue, or an internal service error in NCS.
144
- * @message Message returned to editor, i.e. The initial document couldn't be loaded from the collab service
145
- * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
146
- * The user will need to refresh the page to try again.
147
- */
148
- /**
149
- * Couldn't reconnect to the collab service (NCS) due to network issues.
150
- * NCS could be down, or the user could be offline. It's also possible the url is incorrect, or the user is behind a proxy blocking the connection.
151
- * Fired upon a reconnection attempt error (from Socket.IO Manager)
152
- * @message Message returned to editor, i.e. Couldn't reconnect to the collab service due to network issues
153
- * @recoverable It is recoverable, as the provider will try to reconnect.
154
- */
155
- /**
156
- * This error is thrown when the provider has an invalid configuration.
157
- * It could happen due to these errors from NCS:
158
- * NAMESPACE_INVALID
159
- INVALID_ACTIVATION_ID
160
- INVALID_DOCUMENT_ARI
161
- INVALID_CLOUD_ID
162
- * @message Message returned to editor, i.e. Invalid provider configuration
163
- * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
164
- * The service using the provider will need to fix the configuration.
165
- */
166
- /**
167
- * This error is thrown when the provider encounters an internal service error, not otherwise accounted for.
168
- * @message Message returned to editor, i.e. Collab Provider experienced an unrecoverable error
169
- * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
170
- */
171
- /**
172
- * A union of all possible provider errors that can be emitted back to the editor.
173
- */
174
- exports.PROVIDER_ERROR_CODE = PROVIDER_ERROR_CODE;
81
+ exports.NCS_ERROR_CODE = NCS_ERROR_CODE;
175
82
  // Custom Errors
176
83
  var CustomError = /*#__PURE__*/function (_Error) {
177
84
  (0, _inherits2.default)(CustomError, _Error);
package/dist/cjs/index.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "PROVIDER_ERROR_CODE", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _errorTypes.PROVIDER_ERROR_CODE;
9
+ return _collab.PROVIDER_ERROR_CODE;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "Provider", {
@@ -16,4 +16,4 @@ Object.defineProperty(exports, "Provider", {
16
16
  }
17
17
  });
18
18
  var _provider = require("./provider");
19
- var _errorTypes = require("./errors/error-types");
19
+ var _collab = require("@atlaskit/editor-common/collab");
@@ -53,24 +53,48 @@ var Provider = /*#__PURE__*/function (_Emitter) {
53
53
  * @param data - Event data to emit to subscribers
54
54
  */
55
55
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "emitCallback", function (evt, data) {
56
- // When the provider is initialized early, we want the editor state promise to resolve before emitting events
56
+ // When the provider is initialized early, we want to ensure the editor state exists after setup is called before emitting events
57
57
  // to ensure that it is ready to listen to the events fired by NCS
58
58
  if (_this.isPreinitializing) {
59
- _this.getStatePromise.then(function () {
59
+ _this.onSetupPromise.then(function () {
60
60
  return _this.emit(evt, data);
61
61
  });
62
62
  } else {
63
63
  _this.emit(evt, data);
64
64
  }
65
65
  });
66
+ /**
67
+ * Wrapper to update document and metadata.
68
+ * Catches and logs any errors thrown by document service's updateDocument and updateMetadata methods and destroys the provider in case of errors.
69
+ * Passing the document, metadata, version (either from the initial draft or from collab service)
70
+ */
71
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateDocumentAndMetadata", function (_ref) {
72
+ var doc = _ref.doc,
73
+ version = _ref.version,
74
+ metadata = _ref.metadata;
75
+ try {
76
+ _this.documentService.updateDocument({
77
+ doc: doc,
78
+ version: version,
79
+ metadata: metadata
80
+ });
81
+ _this.metadataService.updateMetadata(metadata);
82
+ _this.isProviderInitialized = true;
83
+ } catch (e) {
84
+ var _this$analyticsHelper;
85
+ (_this$analyticsHelper = _this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(e, 'Failed to update with the init document, destroying provider');
86
+ // Stop events and connections to step us trying to talk to the backend with an invalid state.
87
+ _this.destroy();
88
+ }
89
+ });
66
90
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "initializeChannel", function () {
67
91
  _this.emit('connecting', {
68
92
  initial: true
69
93
  });
70
94
  var shouldInitialize = Boolean(_this.initialDraft) && !_this.isProviderInitialized;
71
- _this.channel.on('connected', function (_ref) {
72
- var sid = _ref.sid,
73
- initialized = _ref.initialized;
95
+ _this.channel.on('connected', function (_ref2) {
96
+ var sid = _ref2.sid,
97
+ initialized = _ref2.initialized;
74
98
  _this.sessionId = sid;
75
99
  _this.emitCallback('connected', {
76
100
  sid: sid,
@@ -89,22 +113,24 @@ var Provider = /*#__PURE__*/function (_Emitter) {
89
113
  document = _this$initialDraft.document,
90
114
  version = _this$initialDraft.version,
91
115
  metadata = _this$initialDraft.metadata;
92
- try {
93
- // Initial document, version, metadata from initial draft
94
- _this.documentService.updateDocument({
116
+ if (_this.isPreinitializing) {
117
+ // When the provider is initialized early, we wait until setup is called with a defined getState before the document is updated to ensure that the editor state exists
118
+ // The `isPreinitializing` check is an extra precaution behind a FF - if the state is already resolved, onSetupPromise will resolve immediately
119
+ _this.onSetupPromise.then(function () {
120
+ _this.updateDocumentAndMetadata({
121
+ doc: document,
122
+ version: version,
123
+ metadata: metadata
124
+ });
125
+ });
126
+ } else {
127
+ _this.updateDocumentAndMetadata({
95
128
  doc: document,
96
129
  version: version,
97
130
  metadata: metadata
98
131
  });
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
132
  }
105
- _this.metadataService.updateMetadata(metadata);
106
133
  }
107
- _this.isProviderInitialized = true;
108
134
  }
109
135
  // If already initialized, `connected` means reconnected
110
136
  if (initialized && _this.disconnectedAt &&
@@ -114,25 +140,16 @@ var Provider = /*#__PURE__*/function (_Emitter) {
114
140
  }
115
141
  _this.participantsService.startInactiveRemover(_this.sessionId);
116
142
  _this.disconnectedAt = undefined;
117
- }).on('init', function (_ref2) {
118
- var doc = _ref2.doc,
119
- version = _ref2.version,
120
- metadata = _ref2.metadata;
143
+ }).on('init', function (_ref3) {
144
+ var doc = _ref3.doc,
145
+ version = _ref3.version,
146
+ metadata = _ref3.metadata;
121
147
  // Initial document and version
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
- }
148
+ _this.updateDocumentAndMetadata({
149
+ doc: doc,
150
+ version: version,
151
+ metadata: metadata
152
+ });
136
153
  }).on('restore', _this.documentService.onRestore).on('steps:added', _this.documentService.onStepsAdded).on('metadata:changed', _this.metadataService.onMetadataChanged).on('participant:telepointer', function (payload) {
137
154
  return _this.participantsService.onParticipantTelepointer(payload, _this.sessionId);
138
155
  }).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);
@@ -158,20 +175,20 @@ var Provider = /*#__PURE__*/function (_Emitter) {
158
175
  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) {
159
176
  _this.documentService.onStepRejectedError();
160
177
  } else {
161
- var _this$analyticsHelper3;
162
- (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(error, 'Error handled');
178
+ var _this$analyticsHelper2;
179
+ (_this$analyticsHelper2 = _this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(error, 'Error handled');
163
180
  var mappedError = (0, _errorCodeMapper.errorCodeMapper)(error);
164
181
  // Temporarily only emit errors to Confluence very intentionally because they will disconnect the collab provider
165
182
  if (mappedError) {
166
- var _this$analyticsHelper4;
167
- (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(mappedError, 'Error emitted');
183
+ var _this$analyticsHelper3;
184
+ (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(mappedError, 'Error emitted');
168
185
  _this.emitCallback('error', mappedError);
169
186
  }
170
187
  }
171
188
  });
172
189
  // Note: this gets triggered on page reload for Firefox (not other browsers) because of closeOnBeforeunload: false
173
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDisconnected", function (_ref3) {
174
- var reason = _ref3.reason;
190
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDisconnected", function (_ref4) {
191
+ var reason = _ref4.reason;
175
192
  _this.disconnectedAt = Date.now();
176
193
  _this.participantsService.disconnect(reason, _this.sessionId);
177
194
  });
@@ -187,7 +204,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
187
204
  * @throws {GetCurrentStateError} Something went wrong while returning the current state
188
205
  */
189
206
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getCurrentState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
190
- var _this$analyticsHelper5;
207
+ var _this$analyticsHelper4;
191
208
  return _regenerator.default.wrap(function _callee$(_context) {
192
209
  while (1) switch (_context.prev = _context.next) {
193
210
  case 0:
@@ -199,7 +216,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
199
216
  case 6:
200
217
  _context.prev = 6;
201
218
  _context.t0 = _context["catch"](0);
202
- (_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');
219
+ (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(_context.t0, 'Error while returning ADF version of current draft document');
203
220
  throw new _errorTypes.GetCurrentStateError('Error while returning the current state of the draft document', _context.t0);
204
221
  case 10:
205
222
  case "end":
@@ -213,7 +230,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
213
230
  * @throws {GetFinalAcknowledgedStateError} Something went wrong while returning the acknowledged state
214
231
  */
215
232
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getFinalAcknowledgedState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
216
- var _this$analyticsHelper6;
233
+ var _this$analyticsHelper5;
217
234
  return _regenerator.default.wrap(function _callee2$(_context2) {
218
235
  while (1) switch (_context2.prev = _context2.next) {
219
236
  case 0:
@@ -225,7 +242,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
225
242
  case 6:
226
243
  _context2.prev = 6;
227
244
  _context2.t0 = _context2["catch"](0);
228
- (_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');
245
+ (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(_context2.t0, 'Error while returning ADF version of the final draft document');
229
246
  throw new _errorTypes.GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', _context2.t0);
230
247
  case 10:
231
248
  case "end":
@@ -261,8 +278,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
261
278
  _this.documentService = new _documentService.DocumentService(_this.participantsService, _this.analyticsHelper, _this.channel.fetchCatchup, _this.emitCallback, _this.channel.broadcast, function () {
262
279
  return _this.userId;
263
280
  }, _this.onErrorHandled, _this.metadataService, _this.config.failedStepLimitBeforeCatchupOnPublish, _this.config.enableErrorOnFailedDocumentApply);
264
- _this.getStatePromise = new Promise(function (resolve) {
265
- _this.getStatePromiseResolve = resolve;
281
+ _this.onSetupPromise = new Promise(function (resolve) {
282
+ _this.resolveOnSetupPromise = resolve;
266
283
  });
267
284
  _this.namespaceService = new _namespaceService.NamespaceService();
268
285
  return _this;
@@ -296,21 +313,17 @@ var Provider = /*#__PURE__*/function (_Emitter) {
296
313
  */
297
314
  }, {
298
315
  key: "setup",
299
- value: function setup(_ref6) {
300
- var getState = _ref6.getState,
301
- onSyncUpError = _ref6.onSyncUpError;
316
+ value: function setup(_ref7) {
317
+ var getState = _ref7.getState,
318
+ onSyncUpError = _ref7.onSyncUpError;
302
319
  this.checkForCookies();
303
320
  try {
304
- // if setup is called with no state and the initial draft is already provided
321
+ // if setup is called with no getState and the initial draft is already provided
305
322
  // set a flag to mark early provider setup
306
323
  if (!getState && this.initialDraft) {
307
324
  this.isPreinitializing = true;
308
325
  }
309
326
  if (getState) {
310
- // if provider has already been initialized earlier, resolve the state once it is available
311
- if (this.isPreinitializing) {
312
- this.getStatePromiseResolve();
313
- }
314
327
  var collabPlugin = getState().plugins.find(function (p) {
315
328
  return p.key === 'collab$';
316
329
  });
@@ -323,14 +336,20 @@ var Provider = /*#__PURE__*/function (_Emitter) {
323
336
  onSyncUpError: onSyncUpError,
324
337
  clientId: this.clientId
325
338
  });
339
+
340
+ // if provider has already been initialized earlier, resolve the setup promise once setup has been called with
341
+ // a defined getState (ie editor state is ready) AND after documentService sets the editor state
342
+ if (this.isPreinitializing) {
343
+ this.resolveOnSetupPromise();
344
+ }
326
345
  }
327
346
  if (!this.isChannelInitialized) {
328
347
  this.initializeChannel();
329
348
  this.isChannelInitialized = true;
330
349
  }
331
350
  } catch (initError) {
332
- var _this$analyticsHelper7;
333
- (_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(initError, 'Error while initialising the provider');
351
+ var _this$analyticsHelper6;
352
+ (_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(initError, 'Error while initialising the provider');
334
353
  // Throw error so consumers are aware the initialisation failed when initialising themselves
335
354
  throw new _errorTypes.ProviderInitialisationError('Provider initialisation error', initError);
336
355
  }
@@ -340,9 +359,9 @@ var Provider = /*#__PURE__*/function (_Emitter) {
340
359
  key: "checkForCookies",
341
360
  value: function checkForCookies() {
342
361
  if (!global.navigator.cookieEnabled) {
343
- var _this$analyticsHelper8;
362
+ var _this$analyticsHelper7;
344
363
  var initError = new _errorTypes.ProviderInitialisationError('Cookies are not enabled. Please enable cookies to use collaborative editing.');
345
- (_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
364
+ (_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
346
365
  throw new _errorTypes.ProviderInitialisationError('Provider initialisation error - cookies disabled', initError);
347
366
  }
348
367
  }
@@ -380,8 +399,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
380
399
  }
381
400
  this.documentService.send(_tr, _oldState, newState);
382
401
  } catch (error) {
383
- var _this$analyticsHelper9;
384
- (_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(error, 'Error while sending steps for a transaction');
402
+ var _this$analyticsHelper8;
403
+ (_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(error, 'Error while sending steps for a transaction');
385
404
  throw new _errorTypes.SendTransactionError('Error while sending steps for a transaction', error);
386
405
  }
387
406
  }
@@ -409,9 +428,9 @@ var Provider = /*#__PURE__*/function (_Emitter) {
409
428
  this.channel.broadcast('participant:telepointer', payload, callback);
410
429
  }
411
430
  } catch (error) {
412
- var _this$analyticsHelper10;
431
+ var _this$analyticsHelper9;
413
432
  // We don't want to throw errors for Presence features as they tend to self-restore
414
- (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(error, 'Error while sending message - telepointer');
433
+ (_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(error, 'Error while sending message - telepointer');
415
434
  }
416
435
  }
417
436
  }, {
@@ -450,8 +469,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
450
469
  (0, _get2.default)((0, _getPrototypeOf2.default)(Provider.prototype), "unsubscribeAll", this).call(this);
451
470
  this.channel.disconnect();
452
471
  } catch (error) {
453
- var _this$analyticsHelper11;
454
- (_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, 'Error while shutting down the collab provider');
472
+ var _this$analyticsHelper10;
473
+ (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(error, 'Error while shutting down the collab provider');
455
474
  throw new _errorTypes.DestroyError('Error while shutting down the collab provider', error);
456
475
  }
457
476
  this.clearTimers();
@@ -471,8 +490,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
471
490
  try {
472
491
  this.metadataService.setTitle(title, broadcast);
473
492
  } catch (error) {
474
- var _this$analyticsHelper12;
475
- (_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while setting title');
493
+ var _this$analyticsHelper11;
494
+ (_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, 'Error while setting title');
476
495
  throw new _errorTypes.SetTitleError('Error while setting title', error);
477
496
  }
478
497
  }
@@ -490,8 +509,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
490
509
  try {
491
510
  this.metadataService.setEditorWidth(editorWidth, broadcast);
492
511
  } catch (error) {
493
- var _this$analyticsHelper13;
494
- (_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(error, 'Error while setting editor width');
512
+ var _this$analyticsHelper12;
513
+ (_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while setting editor width');
495
514
  throw new _errorTypes.SetEditorWidthError('Error while setting editor width', error);
496
515
  }
497
516
  }
@@ -507,8 +526,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
507
526
  try {
508
527
  this.metadataService.setMetadata(metadata);
509
528
  } catch (error) {
510
- var _this$analyticsHelper14;
511
- (_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendErrorEvent(error, 'Error while setting metadata');
529
+ var _this$analyticsHelper13;
530
+ (_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(error, 'Error while setting metadata');
512
531
  throw new _errorTypes.SetMetadataError('Error while setting metadata', error);
513
532
  }
514
533
  }
package/dist/cjs/types.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AcknowledgementResponseTypes = void 0;
7
- // types from editor common
7
+ // Re-export values for the /types entry point to this package
8
8
  // types from editor common end
9
9
  // Initial draft
10
10
  // Channel
@@ -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.6.4";
9
+ var version = "9.7.1";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');