@atlaskit/collab-provider 9.6.4 → 9.7.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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/provider/index.js +88 -69
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/provider/index.js +77 -57
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/provider/index.js +88 -69
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/provider/index.d.ts +8 -2
- package/dist/types-ts4.5/provider/index.d.ts +8 -2
- package/package.json +1 -1
- package/report.api.md +2 -2
- package/tmp/api-report-tmp.d.ts +0 -581
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/collab-provider
|
|
2
2
|
|
|
3
|
+
## 9.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`3265cccb965`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3265cccb965) - resolving editor state before updating document/metadata during early provider initialization
|
|
8
|
+
|
|
3
9
|
## 9.6.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -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
|
|
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.
|
|
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 (
|
|
72
|
-
var sid =
|
|
73
|
-
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
|
-
|
|
93
|
-
//
|
|
94
|
-
|
|
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 (
|
|
118
|
-
var doc =
|
|
119
|
-
version =
|
|
120
|
-
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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$
|
|
162
|
-
(_this$
|
|
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$
|
|
167
|
-
(_this$
|
|
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 (
|
|
174
|
-
var 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$
|
|
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$
|
|
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$
|
|
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$
|
|
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.
|
|
265
|
-
_this.
|
|
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(
|
|
300
|
-
var getState =
|
|
301
|
-
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
|
|
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$
|
|
333
|
-
(_this$
|
|
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$
|
|
362
|
+
var _this$analyticsHelper7;
|
|
344
363
|
var initError = new _errorTypes.ProviderInitialisationError('Cookies are not enabled. Please enable cookies to use collaborative editing.');
|
|
345
|
-
(_this$
|
|
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$
|
|
384
|
-
(_this$
|
|
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$
|
|
431
|
+
var _this$analyticsHelper9;
|
|
413
432
|
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
414
|
-
(_this$
|
|
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$
|
|
454
|
-
(_this$
|
|
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$
|
|
475
|
-
(_this$
|
|
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$
|
|
494
|
-
(_this$
|
|
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$
|
|
511
|
-
(_this$
|
|
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
|
}
|
|
@@ -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.
|
|
9
|
+
var version = "9.7.0";
|
|
10
10
|
exports.version = version;
|
|
11
11
|
var nextMajorVersion = function nextMajorVersion() {
|
|
12
12
|
return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
|
package/dist/cjs/version.json
CHANGED
|
@@ -30,14 +30,39 @@ export class Provider extends Emitter {
|
|
|
30
30
|
* @param data - Event data to emit to subscribers
|
|
31
31
|
*/
|
|
32
32
|
_defineProperty(this, "emitCallback", (evt, data) => {
|
|
33
|
-
// When the provider is initialized early, we want the editor state
|
|
33
|
+
// When the provider is initialized early, we want to ensure the editor state exists after setup is called before emitting events
|
|
34
34
|
// to ensure that it is ready to listen to the events fired by NCS
|
|
35
35
|
if (this.isPreinitializing) {
|
|
36
|
-
this.
|
|
36
|
+
this.onSetupPromise.then(() => this.emit(evt, data));
|
|
37
37
|
} else {
|
|
38
38
|
this.emit(evt, data);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
+
/**
|
|
42
|
+
* Wrapper to update document and metadata.
|
|
43
|
+
* Catches and logs any errors thrown by document service's updateDocument and updateMetadata methods and destroys the provider in case of errors.
|
|
44
|
+
* Passing the document, metadata, version (either from the initial draft or from collab service)
|
|
45
|
+
*/
|
|
46
|
+
_defineProperty(this, "updateDocumentAndMetadata", ({
|
|
47
|
+
doc,
|
|
48
|
+
version,
|
|
49
|
+
metadata
|
|
50
|
+
}) => {
|
|
51
|
+
try {
|
|
52
|
+
this.documentService.updateDocument({
|
|
53
|
+
doc,
|
|
54
|
+
version,
|
|
55
|
+
metadata
|
|
56
|
+
});
|
|
57
|
+
this.metadataService.updateMetadata(metadata);
|
|
58
|
+
this.isProviderInitialized = true;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
var _this$analyticsHelper;
|
|
61
|
+
(_this$analyticsHelper = this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(e, 'Failed to update with the init document, destroying provider');
|
|
62
|
+
// Stop events and connections to step us trying to talk to the backend with an invalid state.
|
|
63
|
+
this.destroy();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
41
66
|
_defineProperty(this, "initializeChannel", () => {
|
|
42
67
|
this.emit('connecting', {
|
|
43
68
|
initial: true
|
|
@@ -66,22 +91,24 @@ export class Provider extends Emitter {
|
|
|
66
91
|
version,
|
|
67
92
|
metadata
|
|
68
93
|
} = this.initialDraft;
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
|
|
94
|
+
if (this.isPreinitializing) {
|
|
95
|
+
// 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
|
|
96
|
+
// The `isPreinitializing` check is an extra precaution behind a FF - if the state is already resolved, onSetupPromise will resolve immediately
|
|
97
|
+
this.onSetupPromise.then(() => {
|
|
98
|
+
this.updateDocumentAndMetadata({
|
|
99
|
+
doc: document,
|
|
100
|
+
version,
|
|
101
|
+
metadata
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
this.updateDocumentAndMetadata({
|
|
72
106
|
doc: document,
|
|
73
107
|
version,
|
|
74
108
|
metadata
|
|
75
109
|
});
|
|
76
|
-
} catch (e) {
|
|
77
|
-
var _this$analyticsHelper;
|
|
78
|
-
(_this$analyticsHelper = this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(e, 'Failed to update the document on reconnect, destroying provider');
|
|
79
|
-
// Stop events and connections to step us trying to talk to the backend with an invalid state.
|
|
80
|
-
this.destroy();
|
|
81
110
|
}
|
|
82
|
-
this.metadataService.updateMetadata(metadata);
|
|
83
111
|
}
|
|
84
|
-
this.isProviderInitialized = true;
|
|
85
112
|
}
|
|
86
113
|
// If already initialized, `connected` means reconnected
|
|
87
114
|
if (initialized && this.disconnectedAt &&
|
|
@@ -97,20 +124,11 @@ export class Provider extends Emitter {
|
|
|
97
124
|
metadata
|
|
98
125
|
}) => {
|
|
99
126
|
// Initial document and version
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
this.metadataService.updateMetadata(metadata);
|
|
107
|
-
this.isProviderInitialized = true;
|
|
108
|
-
} catch (e) {
|
|
109
|
-
var _this$analyticsHelper2;
|
|
110
|
-
(_this$analyticsHelper2 = this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(e, 'Failed to update with the init document, destroying provider');
|
|
111
|
-
// Stop events and connections to step us trying to talk to the backend with an invalid state.
|
|
112
|
-
this.destroy();
|
|
113
|
-
}
|
|
127
|
+
this.updateDocumentAndMetadata({
|
|
128
|
+
doc,
|
|
129
|
+
version,
|
|
130
|
+
metadata
|
|
131
|
+
});
|
|
114
132
|
}).on('restore', this.documentService.onRestore).on('steps:added', this.documentService.onStepsAdded).on('metadata:changed', this.metadataService.onMetadataChanged).on('participant:telepointer', payload => this.participantsService.onParticipantTelepointer(payload, this.sessionId)).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(this)).on('error', this.onErrorHandled).on('status', this.namespaceService.onNamespaceStatusChanged).connect(shouldInitialize);
|
|
115
133
|
});
|
|
116
134
|
_defineProperty(this, "setUserId", id => {
|
|
@@ -134,13 +152,13 @@ export class Provider extends Emitter {
|
|
|
134
152
|
if (((_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.code) === NCS_ERROR_CODE.HEAD_VERSION_UPDATE_FAILED || ((_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.code) === NCS_ERROR_CODE.VERSION_NUMBER_ALREADY_EXISTS) {
|
|
135
153
|
this.documentService.onStepRejectedError();
|
|
136
154
|
} else {
|
|
137
|
-
var _this$
|
|
138
|
-
(_this$
|
|
155
|
+
var _this$analyticsHelper2;
|
|
156
|
+
(_this$analyticsHelper2 = this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(error, 'Error handled');
|
|
139
157
|
const mappedError = errorCodeMapper(error);
|
|
140
158
|
// Temporarily only emit errors to Confluence very intentionally because they will disconnect the collab provider
|
|
141
159
|
if (mappedError) {
|
|
142
|
-
var _this$
|
|
143
|
-
(_this$
|
|
160
|
+
var _this$analyticsHelper3;
|
|
161
|
+
(_this$analyticsHelper3 = this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(mappedError, 'Error emitted');
|
|
144
162
|
this.emitCallback('error', mappedError);
|
|
145
163
|
}
|
|
146
164
|
}
|
|
@@ -167,8 +185,8 @@ export class Provider extends Emitter {
|
|
|
167
185
|
try {
|
|
168
186
|
return await this.documentService.getCurrentState();
|
|
169
187
|
} catch (error) {
|
|
170
|
-
var _this$
|
|
171
|
-
(_this$
|
|
188
|
+
var _this$analyticsHelper4;
|
|
189
|
+
(_this$analyticsHelper4 = this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(error, 'Error while returning ADF version of current draft document');
|
|
172
190
|
throw new GetCurrentStateError('Error while returning the current state of the draft document', error); // Reject the promise so the consumer can react to it failing
|
|
173
191
|
}
|
|
174
192
|
});
|
|
@@ -181,8 +199,8 @@ export class Provider extends Emitter {
|
|
|
181
199
|
try {
|
|
182
200
|
return await this.documentService.getFinalAcknowledgedState();
|
|
183
201
|
} catch (error) {
|
|
184
|
-
var _this$
|
|
185
|
-
(_this$
|
|
202
|
+
var _this$analyticsHelper5;
|
|
203
|
+
(_this$analyticsHelper5 = this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(error, 'Error while returning ADF version of the final draft document');
|
|
186
204
|
throw new GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', error); // Reject the promise so the consumer can react to it failing
|
|
187
205
|
}
|
|
188
206
|
});
|
|
@@ -212,8 +230,8 @@ export class Provider extends Emitter {
|
|
|
212
230
|
this.participantsService = new ParticipantsService(this.analyticsHelper, undefined, this.emitCallback, this.config.getUser, this.channel.broadcast, this.channel.sendPresenceJoined, this.getPresenceData, this.setUserId);
|
|
213
231
|
this.metadataService = new MetadataService(this.emitCallback, this.channel.sendMetadata);
|
|
214
232
|
this.documentService = new DocumentService(this.participantsService, this.analyticsHelper, this.channel.fetchCatchup, this.emitCallback, this.channel.broadcast, () => this.userId, this.onErrorHandled, this.metadataService, this.config.failedStepLimitBeforeCatchupOnPublish, this.config.enableErrorOnFailedDocumentApply);
|
|
215
|
-
this.
|
|
216
|
-
this.
|
|
233
|
+
this.onSetupPromise = new Promise(resolve => {
|
|
234
|
+
this.resolveOnSetupPromise = resolve;
|
|
217
235
|
});
|
|
218
236
|
this.namespaceService = new NamespaceService();
|
|
219
237
|
}
|
|
@@ -247,16 +265,12 @@ export class Provider extends Emitter {
|
|
|
247
265
|
}) {
|
|
248
266
|
this.checkForCookies();
|
|
249
267
|
try {
|
|
250
|
-
// if setup is called with no
|
|
268
|
+
// if setup is called with no getState and the initial draft is already provided
|
|
251
269
|
// set a flag to mark early provider setup
|
|
252
270
|
if (!getState && this.initialDraft) {
|
|
253
271
|
this.isPreinitializing = true;
|
|
254
272
|
}
|
|
255
273
|
if (getState) {
|
|
256
|
-
// if provider has already been initialized earlier, resolve the state once it is available
|
|
257
|
-
if (this.isPreinitializing) {
|
|
258
|
-
this.getStatePromiseResolve();
|
|
259
|
-
}
|
|
260
274
|
const collabPlugin = getState().plugins.find(p => p.key === 'collab$');
|
|
261
275
|
if (collabPlugin === undefined) {
|
|
262
276
|
throw new ProviderInitialisationError('Collab provider attempted to initialise, but Editor state is missing collab plugin');
|
|
@@ -267,14 +281,20 @@ export class Provider extends Emitter {
|
|
|
267
281
|
onSyncUpError,
|
|
268
282
|
clientId: this.clientId
|
|
269
283
|
});
|
|
284
|
+
|
|
285
|
+
// if provider has already been initialized earlier, resolve the setup promise once setup has been called with
|
|
286
|
+
// a defined getState (ie editor state is ready) AND after documentService sets the editor state
|
|
287
|
+
if (this.isPreinitializing) {
|
|
288
|
+
this.resolveOnSetupPromise();
|
|
289
|
+
}
|
|
270
290
|
}
|
|
271
291
|
if (!this.isChannelInitialized) {
|
|
272
292
|
this.initializeChannel();
|
|
273
293
|
this.isChannelInitialized = true;
|
|
274
294
|
}
|
|
275
295
|
} catch (initError) {
|
|
276
|
-
var _this$
|
|
277
|
-
(_this$
|
|
296
|
+
var _this$analyticsHelper6;
|
|
297
|
+
(_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(initError, 'Error while initialising the provider');
|
|
278
298
|
// Throw error so consumers are aware the initialisation failed when initialising themselves
|
|
279
299
|
throw new ProviderInitialisationError('Provider initialisation error', initError);
|
|
280
300
|
}
|
|
@@ -282,9 +302,9 @@ export class Provider extends Emitter {
|
|
|
282
302
|
}
|
|
283
303
|
checkForCookies() {
|
|
284
304
|
if (!global.navigator.cookieEnabled) {
|
|
285
|
-
var _this$
|
|
305
|
+
var _this$analyticsHelper7;
|
|
286
306
|
const initError = new ProviderInitialisationError('Cookies are not enabled. Please enable cookies to use collaborative editing.');
|
|
287
|
-
(_this$
|
|
307
|
+
(_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
|
|
288
308
|
throw new ProviderInitialisationError('Provider initialisation error - cookies disabled', initError);
|
|
289
309
|
}
|
|
290
310
|
}
|
|
@@ -318,8 +338,8 @@ export class Provider extends Emitter {
|
|
|
318
338
|
}
|
|
319
339
|
this.documentService.send(_tr, _oldState, newState);
|
|
320
340
|
} catch (error) {
|
|
321
|
-
var _this$
|
|
322
|
-
(_this$
|
|
341
|
+
var _this$analyticsHelper8;
|
|
342
|
+
(_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(error, 'Error while sending steps for a transaction');
|
|
323
343
|
throw new SendTransactionError('Error while sending steps for a transaction', error);
|
|
324
344
|
}
|
|
325
345
|
}
|
|
@@ -344,9 +364,9 @@ export class Provider extends Emitter {
|
|
|
344
364
|
this.channel.broadcast('participant:telepointer', payload, callback);
|
|
345
365
|
}
|
|
346
366
|
} catch (error) {
|
|
347
|
-
var _this$
|
|
367
|
+
var _this$analyticsHelper9;
|
|
348
368
|
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
349
|
-
(_this$
|
|
369
|
+
(_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(error, 'Error while sending message - telepointer');
|
|
350
370
|
}
|
|
351
371
|
}
|
|
352
372
|
/**
|
|
@@ -378,8 +398,8 @@ export class Provider extends Emitter {
|
|
|
378
398
|
super.unsubscribeAll();
|
|
379
399
|
this.channel.disconnect();
|
|
380
400
|
} catch (error) {
|
|
381
|
-
var _this$
|
|
382
|
-
(_this$
|
|
401
|
+
var _this$analyticsHelper10;
|
|
402
|
+
(_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(error, 'Error while shutting down the collab provider');
|
|
383
403
|
throw new DestroyError('Error while shutting down the collab provider', error);
|
|
384
404
|
}
|
|
385
405
|
this.clearTimers();
|
|
@@ -397,8 +417,8 @@ export class Provider extends Emitter {
|
|
|
397
417
|
try {
|
|
398
418
|
this.metadataService.setTitle(title, broadcast);
|
|
399
419
|
} catch (error) {
|
|
400
|
-
var _this$
|
|
401
|
-
(_this$
|
|
420
|
+
var _this$analyticsHelper11;
|
|
421
|
+
(_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, 'Error while setting title');
|
|
402
422
|
throw new SetTitleError('Error while setting title', error);
|
|
403
423
|
}
|
|
404
424
|
}
|
|
@@ -414,8 +434,8 @@ export class Provider extends Emitter {
|
|
|
414
434
|
try {
|
|
415
435
|
this.metadataService.setEditorWidth(editorWidth, broadcast);
|
|
416
436
|
} catch (error) {
|
|
417
|
-
var _this$
|
|
418
|
-
(_this$
|
|
437
|
+
var _this$analyticsHelper12;
|
|
438
|
+
(_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while setting editor width');
|
|
419
439
|
throw new SetEditorWidthError('Error while setting editor width', error);
|
|
420
440
|
}
|
|
421
441
|
}
|
|
@@ -429,8 +449,8 @@ export class Provider extends Emitter {
|
|
|
429
449
|
try {
|
|
430
450
|
this.metadataService.setMetadata(metadata);
|
|
431
451
|
} catch (error) {
|
|
432
|
-
var _this$
|
|
433
|
-
(_this$
|
|
452
|
+
var _this$analyticsHelper13;
|
|
453
|
+
(_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(error, 'Error while setting metadata');
|
|
434
454
|
throw new SetMetadataError('Error while setting metadata', error);
|
|
435
455
|
}
|
|
436
456
|
}
|
package/dist/es2019/version.json
CHANGED