@atlaskit/collab-provider 9.0.1 → 9.2.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 +13 -0
- package/dist/cjs/document/document-service.js +30 -15
- package/dist/cjs/helpers/const.js +3 -0
- package/dist/cjs/provider/commit-step.js +22 -1
- package/dist/cjs/provider/index.js +37 -14
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/document/document-service.js +20 -6
- package/dist/es2019/helpers/const.js +3 -0
- package/dist/es2019/provider/commit-step.js +22 -1
- package/dist/es2019/provider/index.js +36 -15
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/document/document-service.js +30 -15
- package/dist/esm/helpers/const.js +3 -0
- package/dist/esm/provider/commit-step.js +22 -1
- package/dist/esm/provider/index.js +37 -14
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/document/document-service.d.ts +5 -2
- package/dist/types/helpers/const.d.ts +20 -2
- package/dist/types/provider/commit-step.d.ts +5 -3
- package/dist/types/provider/index.d.ts +6 -0
- package/dist/types/types.d.ts +11 -0
- package/dist/types-ts4.5/document/document-service.d.ts +5 -2
- package/dist/types-ts4.5/helpers/const.d.ts +20 -2
- package/dist/types-ts4.5/provider/commit-step.d.ts +5 -3
- package/dist/types-ts4.5/provider/index.d.ts +6 -0
- package/dist/types-ts4.5/types.d.ts +11 -0
- package/package.json +3 -3
- package/report.api.md +11 -0
- package/tmp/api-report-tmp.d.ts +564 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/collab-provider
|
|
2
2
|
|
|
3
|
+
## 9.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`ef726a72028`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ef726a72028) - adding provider catchup when initial draft timestamp exceeds stale timeout
|
|
8
|
+
|
|
9
|
+
## 9.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`2c0c19cc14b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2c0c19cc14b) - ESS-3609: add step commit status events for confl save indicator feature
|
|
14
|
+
- [`470c3a7e8c6`](https://bitbucket.org/atlassian/atlassian-frontend/commits/470c3a7e8c6) - ESS-3644: allow max steps retry param to be passed thru collab provider to allow getFinalAcknowledgeState to catch up sooner on publish
|
|
15
|
+
|
|
3
16
|
## 9.0.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -37,16 +37,19 @@ var DocumentService = /*#__PURE__*/function () {
|
|
|
37
37
|
* @param analyticsHelper - Helper for analytics events
|
|
38
38
|
* @param fetchCatchup - Function to fetch "catchup" data, data required to rebase current steps to the latest version.
|
|
39
39
|
* @param providerEmitCallback - Callback for emitting events to listeners on the provider
|
|
40
|
-
* @param broadcastMetadata - Callback for broadcasting metadata changes to other clients
|
|
41
40
|
* @param broadcast - Callback for broadcasting events to other clients
|
|
42
41
|
* @param getUserId - Callback to fetch the current user's ID
|
|
43
42
|
* @param onErrorHandled - Callback to handle
|
|
43
|
+
* @param metadataService
|
|
44
|
+
* @param failedStepsBeforeCatchupOnPublish - Control MAX_STEP_REJECTED_ERROR during page publishes.
|
|
44
45
|
*/
|
|
45
46
|
function DocumentService(participantsService, analyticsHelper, fetchCatchup, providerEmitCallback, broadcast, getUserId, onErrorHandled, metadataService) {
|
|
46
47
|
var _this = this;
|
|
48
|
+
var failedStepsBeforeCatchupOnPublish = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : _provider.MAX_STEP_REJECTED_ERROR;
|
|
47
49
|
(0, _classCallCheck2.default)(this, DocumentService);
|
|
48
50
|
// Fires analytics to editor when collab editor cannot sync up
|
|
49
51
|
(0, _defineProperty2.default)(this, "stepRejectCounter", 0);
|
|
52
|
+
(0, _defineProperty2.default)(this, "aggressiveCatchup", false);
|
|
50
53
|
/**
|
|
51
54
|
* To prevent calling catchup to often, use lodash throttle to reduce the frequency
|
|
52
55
|
*/
|
|
@@ -281,34 +284,37 @@ var DocumentService = /*#__PURE__*/function () {
|
|
|
281
284
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
282
285
|
while (1) switch (_context3.prev = _context3.next) {
|
|
283
286
|
case 0:
|
|
284
|
-
|
|
287
|
+
_this.aggressiveCatchup = true;
|
|
288
|
+
_context3.prev = 1;
|
|
285
289
|
(0, _performance.startMeasure)(_performance.MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
|
|
286
|
-
_context3.next =
|
|
290
|
+
_context3.next = 5;
|
|
287
291
|
return _this.commitUnconfirmedSteps();
|
|
288
|
-
case
|
|
289
|
-
_context3.next =
|
|
292
|
+
case 5:
|
|
293
|
+
_context3.next = 7;
|
|
290
294
|
return _this.getCurrentState();
|
|
291
|
-
case
|
|
295
|
+
case 7:
|
|
292
296
|
currentState = _context3.sent;
|
|
293
297
|
measure = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
|
|
294
298
|
(_this$analyticsHelper14 = _this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendActionEvent(_const.EVENT_ACTION.PUBLISH_PAGE, _const.EVENT_STATUS.SUCCESS, {
|
|
295
299
|
latency: measure === null || measure === void 0 ? void 0 : measure.duration
|
|
296
300
|
});
|
|
301
|
+
_this.aggressiveCatchup = false;
|
|
297
302
|
return _context3.abrupt("return", currentState);
|
|
298
|
-
case
|
|
299
|
-
_context3.prev =
|
|
300
|
-
_context3.t0 = _context3["catch"](
|
|
303
|
+
case 14:
|
|
304
|
+
_context3.prev = 14;
|
|
305
|
+
_context3.t0 = _context3["catch"](1);
|
|
306
|
+
_this.aggressiveCatchup = false;
|
|
301
307
|
_measure2 = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.PUBLISH_PAGE, _this.analyticsHelper);
|
|
302
308
|
(_this$analyticsHelper15 = _this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 ? void 0 : _this$analyticsHelper15.sendActionEvent(_const.EVENT_ACTION.PUBLISH_PAGE, _const.EVENT_STATUS.FAILURE, {
|
|
303
309
|
latency: _measure2 === null || _measure2 === void 0 ? void 0 : _measure2.duration
|
|
304
310
|
});
|
|
305
311
|
(_this$analyticsHelper16 = _this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 ? void 0 : _this$analyticsHelper16.sendErrorEvent(_context3.t0, 'Error while returning ADF version of the final draft document');
|
|
306
312
|
throw _context3.t0;
|
|
307
|
-
case
|
|
313
|
+
case 21:
|
|
308
314
|
case "end":
|
|
309
315
|
return _context3.stop();
|
|
310
316
|
}
|
|
311
|
-
}, _callee3, null, [[
|
|
317
|
+
}, _callee3, null, [[1, 14]]);
|
|
312
318
|
})));
|
|
313
319
|
(0, _defineProperty2.default)(this, "updateDocument", function (_ref6) {
|
|
314
320
|
var doc = _ref6.doc,
|
|
@@ -409,10 +415,17 @@ var DocumentService = /*#__PURE__*/function () {
|
|
|
409
415
|
}, _callee4, null, [[1, 23]]);
|
|
410
416
|
})));
|
|
411
417
|
(0, _defineProperty2.default)(this, "onStepRejectedError", function () {
|
|
418
|
+
var _this$analyticsHelper20;
|
|
412
419
|
_this.stepRejectCounter++;
|
|
413
420
|
logger("Steps rejected (tries=".concat(_this.stepRejectCounter, ")"));
|
|
414
|
-
|
|
421
|
+
(_this$analyticsHelper20 = _this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 ? void 0 : _this$analyticsHelper20.sendActionEvent(_const.EVENT_ACTION.SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO, {
|
|
422
|
+
count: _this.stepRejectCounter
|
|
423
|
+
});
|
|
424
|
+
var maxRetries = _this.aggressiveCatchup ? _this.failedStepsBeforeCatchupOnPublish : _provider.MAX_STEP_REJECTED_ERROR;
|
|
425
|
+
if (_this.stepRejectCounter >= maxRetries) {
|
|
426
|
+
var _this$analyticsHelper21;
|
|
415
427
|
logger("The steps were rejected too many times (tries=".concat(_this.stepRejectCounter, ", limit=").concat(_provider.MAX_STEP_REJECTED_ERROR, "). Trying to catch-up."));
|
|
428
|
+
(_this$analyticsHelper21 = _this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 ? void 0 : _this$analyticsHelper21.sendActionEvent(_const.EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, _const.EVENT_STATUS.INFO);
|
|
416
429
|
_this.throttledCatchup();
|
|
417
430
|
} else {
|
|
418
431
|
// If committing steps failed try again automatically in 1s
|
|
@@ -432,6 +445,7 @@ var DocumentService = /*#__PURE__*/function () {
|
|
|
432
445
|
this.getUserId = getUserId;
|
|
433
446
|
this.onErrorHandled = onErrorHandled;
|
|
434
447
|
this.metadataService = metadataService;
|
|
448
|
+
this.failedStepsBeforeCatchupOnPublish = failedStepsBeforeCatchupOnPublish;
|
|
435
449
|
this.stepQueue = new _stepQueueState.StepQueueState();
|
|
436
450
|
}
|
|
437
451
|
(0, _createClass2.default)(DocumentService, [{
|
|
@@ -483,9 +497,9 @@ var DocumentService = /*#__PURE__*/function () {
|
|
|
483
497
|
}, 100);
|
|
484
498
|
}
|
|
485
499
|
} catch (error) {
|
|
486
|
-
var _this$
|
|
500
|
+
var _this$analyticsHelper22;
|
|
487
501
|
logger("Processing steps failed with error: ".concat(error, ". Triggering catch up call."));
|
|
488
|
-
(_this$
|
|
502
|
+
(_this$analyticsHelper22 = this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 ? void 0 : _this$analyticsHelper22.sendErrorEvent(error, 'Error while processing steps');
|
|
489
503
|
this.throttledCatchup();
|
|
490
504
|
}
|
|
491
505
|
}
|
|
@@ -550,7 +564,8 @@ var DocumentService = /*#__PURE__*/function () {
|
|
|
550
564
|
version: version,
|
|
551
565
|
onStepsAdded: this.onStepsAdded,
|
|
552
566
|
onErrorHandled: this.onErrorHandled,
|
|
553
|
-
analyticsHelper: this.analyticsHelper
|
|
567
|
+
analyticsHelper: this.analyticsHelper,
|
|
568
|
+
emit: this.providerEmitCallback
|
|
554
569
|
});
|
|
555
570
|
}
|
|
556
571
|
}]);
|
|
@@ -16,6 +16,8 @@ var EVENT_ACTION = /*#__PURE__*/function (EVENT_ACTION) {
|
|
|
16
16
|
EVENT_ACTION["PUBLISH_PAGE"] = "publishPage";
|
|
17
17
|
EVENT_ACTION["GET_CURRENT_STATE"] = "getCurrentState";
|
|
18
18
|
EVENT_ACTION["INVALIDATE_TOKEN"] = "invalidateToken";
|
|
19
|
+
EVENT_ACTION["SEND_STEPS_RETRY"] = "sendStepsRetry";
|
|
20
|
+
EVENT_ACTION["CATCHUP_AFTER_MAX_SEND_STEPS_RETRY"] = "catchupAfterMaxSendStepsRetry";
|
|
19
21
|
EVENT_ACTION["DROPPED_STEPS"] = "droppedStepInCatchup";
|
|
20
22
|
return EVENT_ACTION;
|
|
21
23
|
}({});
|
|
@@ -23,6 +25,7 @@ exports.EVENT_ACTION = EVENT_ACTION;
|
|
|
23
25
|
var EVENT_STATUS = /*#__PURE__*/function (EVENT_STATUS) {
|
|
24
26
|
EVENT_STATUS["SUCCESS"] = "SUCCESS";
|
|
25
27
|
EVENT_STATUS["FAILURE"] = "FAILURE";
|
|
28
|
+
EVENT_STATUS["INFO"] = "INFO";
|
|
26
29
|
return EVENT_STATUS;
|
|
27
30
|
}({});
|
|
28
31
|
exports.EVENT_STATUS = EVENT_STATUS;
|
|
@@ -23,7 +23,8 @@ var commitStep = function commitStep(_ref) {
|
|
|
23
23
|
clientId = _ref.clientId,
|
|
24
24
|
onStepsAdded = _ref.onStepsAdded,
|
|
25
25
|
onErrorHandled = _ref.onErrorHandled,
|
|
26
|
-
analyticsHelper = _ref.analyticsHelper
|
|
26
|
+
analyticsHelper = _ref.analyticsHelper,
|
|
27
|
+
emit = _ref.emit;
|
|
27
28
|
var stepsWithClientAndUserId = steps.map(function (step) {
|
|
28
29
|
return _objectSpread(_objectSpread({}, step.toJSON()), {}, {
|
|
29
30
|
clientId: clientId,
|
|
@@ -31,6 +32,10 @@ var commitStep = function commitStep(_ref) {
|
|
|
31
32
|
});
|
|
32
33
|
});
|
|
33
34
|
var start = new Date().getTime();
|
|
35
|
+
emit('commit-status', {
|
|
36
|
+
status: 'attempt',
|
|
37
|
+
version: version
|
|
38
|
+
});
|
|
34
39
|
try {
|
|
35
40
|
broadcast('steps:commit', {
|
|
36
41
|
steps: stepsWithClientAndUserId,
|
|
@@ -50,6 +55,10 @@ var commitStep = function commitStep(_ref) {
|
|
|
50
55
|
return stepWithClientAndUserId.stepType;
|
|
51
56
|
})
|
|
52
57
|
});
|
|
58
|
+
emit('commit-status', {
|
|
59
|
+
status: 'success',
|
|
60
|
+
version: response.version
|
|
61
|
+
});
|
|
53
62
|
} else if (response.type === _types.AcknowledgementResponseTypes.ERROR) {
|
|
54
63
|
onErrorHandled(response.error);
|
|
55
64
|
analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendActionEvent(_const.EVENT_ACTION.ADD_STEPS, _const.EVENT_STATUS.FAILURE, {
|
|
@@ -60,14 +69,26 @@ var commitStep = function commitStep(_ref) {
|
|
|
60
69
|
latency: latency
|
|
61
70
|
});
|
|
62
71
|
analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(response.error, 'Error while adding steps - Acknowledgement Error');
|
|
72
|
+
emit('commit-status', {
|
|
73
|
+
status: 'failure',
|
|
74
|
+
version: version
|
|
75
|
+
});
|
|
63
76
|
} else {
|
|
64
77
|
analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(
|
|
65
78
|
// @ts-expect-error We didn't type the invalid type case
|
|
66
79
|
new Error("Response type: ".concat((response === null || response === void 0 ? void 0 : response.type) || 'No response type')), 'Error while adding steps - Invalid Acknowledgement');
|
|
80
|
+
emit('commit-status', {
|
|
81
|
+
status: 'failure',
|
|
82
|
+
version: version
|
|
83
|
+
});
|
|
67
84
|
}
|
|
68
85
|
});
|
|
69
86
|
} catch (error) {
|
|
70
87
|
analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(error, 'Error while adding steps - Broadcast threw exception');
|
|
88
|
+
emit('commit-status', {
|
|
89
|
+
status: 'failure',
|
|
90
|
+
version: version
|
|
91
|
+
});
|
|
71
92
|
}
|
|
72
93
|
};
|
|
73
94
|
exports.commitStep = commitStep;
|
|
@@ -30,6 +30,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
30
30
|
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; } }
|
|
31
31
|
var logger = (0, _utils.createLogger)('Provider', 'black');
|
|
32
32
|
var OUT_OF_SYNC_PERIOD = 3 * 1000; // 3 seconds
|
|
33
|
+
var PRELOAD_DRAFT_SYNC_PERIOD = 15 * 1000; // 15 seconds
|
|
33
34
|
|
|
34
35
|
var MAX_STEP_REJECTED_ERROR = 15;
|
|
35
36
|
exports.MAX_STEP_REJECTED_ERROR = MAX_STEP_REJECTED_ERROR;
|
|
@@ -75,20 +76,27 @@ var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
75
76
|
sid: sid,
|
|
76
77
|
initial: !initialized
|
|
77
78
|
});
|
|
78
|
-
|
|
79
|
-
//
|
|
79
|
+
|
|
80
|
+
// Early initialization with initial draft passed via provider
|
|
80
81
|
if (_this.initialDraft && initialized && !_this.isProviderInitialized) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
// Call catchup if the draft has become stale since being passed to provider
|
|
83
|
+
if (_this.isDraftTimestampStale()) {
|
|
84
|
+
_this.documentService.throttledCatchup();
|
|
85
|
+
}
|
|
86
|
+
// If the initial draft is already up to date, update the document with that of the initial draft
|
|
87
|
+
else {
|
|
88
|
+
var _this$initialDraft = _this.initialDraft,
|
|
89
|
+
document = _this$initialDraft.document,
|
|
90
|
+
version = _this$initialDraft.version,
|
|
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
|
+
});
|
|
98
|
+
_this.metadataService.updateMetadata(metadata);
|
|
99
|
+
}
|
|
92
100
|
_this.isProviderInitialized = true;
|
|
93
101
|
}
|
|
94
102
|
// If already initialized, `connected` means reconnected
|
|
@@ -229,7 +237,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
229
237
|
_this.metadataService = new _metadataService.MetadataService(_this.emitCallback, _this.channel.sendMetadata);
|
|
230
238
|
_this.documentService = new _documentService.DocumentService(_this.participantsService, _this.analyticsHelper, _this.channel.fetchCatchup, _this.emitCallback, _this.channel.broadcast, function () {
|
|
231
239
|
return _this.userId;
|
|
232
|
-
}, _this.onErrorHandled, _this.metadataService);
|
|
240
|
+
}, _this.onErrorHandled, _this.metadataService, _this.config.failedStepLimitBeforeCatchupOnPublish);
|
|
233
241
|
_this.getStatePromise = new Promise(function (resolve) {
|
|
234
242
|
_this.getStatePromiseResolve = resolve;
|
|
235
243
|
});
|
|
@@ -316,6 +324,21 @@ var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
316
324
|
}
|
|
317
325
|
}
|
|
318
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Checks the provider's initial draft timestamp to determine if it is stale.
|
|
329
|
+
* Returns true only if the time elapsed since the draft timestamp is greater than or
|
|
330
|
+
* equal to a predetermined timeout. Returns false in all other cases.
|
|
331
|
+
*/
|
|
332
|
+
}, {
|
|
333
|
+
key: "isDraftTimestampStale",
|
|
334
|
+
value: function isDraftTimestampStale() {
|
|
335
|
+
var _this$initialDraft2;
|
|
336
|
+
if (!((_this$initialDraft2 = this.initialDraft) !== null && _this$initialDraft2 !== void 0 && _this$initialDraft2.timestamp)) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
return Date.now() - this.initialDraft.timestamp >= PRELOAD_DRAFT_SYNC_PERIOD;
|
|
340
|
+
}
|
|
341
|
+
|
|
319
342
|
/**
|
|
320
343
|
* Send steps from transaction to NCS (and as a consequence to other participants), called from the collab-edit plugin in the editor
|
|
321
344
|
* @param {Transaction} _tr Deprecated, included to keep API consistent with Synchrony provider
|
|
@@ -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.0
|
|
9
|
+
var version = "9.2.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
|
@@ -24,14 +24,16 @@ export class DocumentService {
|
|
|
24
24
|
* @param analyticsHelper - Helper for analytics events
|
|
25
25
|
* @param fetchCatchup - Function to fetch "catchup" data, data required to rebase current steps to the latest version.
|
|
26
26
|
* @param providerEmitCallback - Callback for emitting events to listeners on the provider
|
|
27
|
-
* @param broadcastMetadata - Callback for broadcasting metadata changes to other clients
|
|
28
27
|
* @param broadcast - Callback for broadcasting events to other clients
|
|
29
28
|
* @param getUserId - Callback to fetch the current user's ID
|
|
30
29
|
* @param onErrorHandled - Callback to handle
|
|
30
|
+
* @param metadataService
|
|
31
|
+
* @param failedStepsBeforeCatchupOnPublish - Control MAX_STEP_REJECTED_ERROR during page publishes.
|
|
31
32
|
*/
|
|
32
|
-
constructor(participantsService, analyticsHelper, fetchCatchup, providerEmitCallback, broadcast, getUserId, onErrorHandled, metadataService) {
|
|
33
|
+
constructor(participantsService, analyticsHelper, fetchCatchup, providerEmitCallback, broadcast, getUserId, onErrorHandled, metadataService, failedStepsBeforeCatchupOnPublish = MAX_STEP_REJECTED_ERROR) {
|
|
33
34
|
// Fires analytics to editor when collab editor cannot sync up
|
|
34
35
|
_defineProperty(this, "stepRejectCounter", 0);
|
|
36
|
+
_defineProperty(this, "aggressiveCatchup", false);
|
|
35
37
|
/**
|
|
36
38
|
* To prevent calling catchup to often, use lodash throttle to reduce the frequency
|
|
37
39
|
*/
|
|
@@ -236,6 +238,7 @@ export class DocumentService {
|
|
|
236
238
|
}
|
|
237
239
|
});
|
|
238
240
|
_defineProperty(this, "getFinalAcknowledgedState", async () => {
|
|
241
|
+
this.aggressiveCatchup = true;
|
|
239
242
|
try {
|
|
240
243
|
var _this$analyticsHelper14;
|
|
241
244
|
startMeasure(MEASURE_NAME.PUBLISH_PAGE, this.analyticsHelper);
|
|
@@ -245,9 +248,11 @@ export class DocumentService {
|
|
|
245
248
|
(_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.SUCCESS, {
|
|
246
249
|
latency: measure === null || measure === void 0 ? void 0 : measure.duration
|
|
247
250
|
});
|
|
251
|
+
this.aggressiveCatchup = false;
|
|
248
252
|
return currentState;
|
|
249
253
|
} catch (error) {
|
|
250
254
|
var _this$analyticsHelper15, _this$analyticsHelper16;
|
|
255
|
+
this.aggressiveCatchup = false;
|
|
251
256
|
const measure = stopMeasure(MEASURE_NAME.PUBLISH_PAGE, this.analyticsHelper);
|
|
252
257
|
(_this$analyticsHelper15 = this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 ? void 0 : _this$analyticsHelper15.sendActionEvent(EVENT_ACTION.PUBLISH_PAGE, EVENT_STATUS.FAILURE, {
|
|
253
258
|
latency: measure === null || measure === void 0 ? void 0 : measure.duration
|
|
@@ -332,10 +337,17 @@ export class DocumentService {
|
|
|
332
337
|
}
|
|
333
338
|
});
|
|
334
339
|
_defineProperty(this, "onStepRejectedError", () => {
|
|
340
|
+
var _this$analyticsHelper20;
|
|
335
341
|
this.stepRejectCounter++;
|
|
336
342
|
logger(`Steps rejected (tries=${this.stepRejectCounter})`);
|
|
337
|
-
|
|
343
|
+
(_this$analyticsHelper20 = this.analyticsHelper) === null || _this$analyticsHelper20 === void 0 ? void 0 : _this$analyticsHelper20.sendActionEvent(EVENT_ACTION.SEND_STEPS_RETRY, EVENT_STATUS.INFO, {
|
|
344
|
+
count: this.stepRejectCounter
|
|
345
|
+
});
|
|
346
|
+
let maxRetries = this.aggressiveCatchup ? this.failedStepsBeforeCatchupOnPublish : MAX_STEP_REJECTED_ERROR;
|
|
347
|
+
if (this.stepRejectCounter >= maxRetries) {
|
|
348
|
+
var _this$analyticsHelper21;
|
|
338
349
|
logger(`The steps were rejected too many times (tries=${this.stepRejectCounter}, limit=${MAX_STEP_REJECTED_ERROR}). Trying to catch-up.`);
|
|
350
|
+
(_this$analyticsHelper21 = this.analyticsHelper) === null || _this$analyticsHelper21 === void 0 ? void 0 : _this$analyticsHelper21.sendActionEvent(EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY, EVENT_STATUS.INFO);
|
|
339
351
|
this.throttledCatchup();
|
|
340
352
|
} else {
|
|
341
353
|
// If committing steps failed try again automatically in 1s
|
|
@@ -353,6 +365,7 @@ export class DocumentService {
|
|
|
353
365
|
this.getUserId = getUserId;
|
|
354
366
|
this.onErrorHandled = onErrorHandled;
|
|
355
367
|
this.metadataService = metadataService;
|
|
368
|
+
this.failedStepsBeforeCatchupOnPublish = failedStepsBeforeCatchupOnPublish;
|
|
356
369
|
this.stepQueue = new StepQueueState();
|
|
357
370
|
}
|
|
358
371
|
processQueue() {
|
|
@@ -398,9 +411,9 @@ export class DocumentService {
|
|
|
398
411
|
setTimeout(() => this.sendStepsFromCurrentState(), 100);
|
|
399
412
|
}
|
|
400
413
|
} catch (error) {
|
|
401
|
-
var _this$
|
|
414
|
+
var _this$analyticsHelper22;
|
|
402
415
|
logger(`Processing steps failed with error: ${error}. Triggering catch up call.`);
|
|
403
|
-
(_this$
|
|
416
|
+
(_this$analyticsHelper22 = this.analyticsHelper) === null || _this$analyticsHelper22 === void 0 ? void 0 : _this$analyticsHelper22.sendErrorEvent(error, 'Error while processing steps');
|
|
404
417
|
this.throttledCatchup();
|
|
405
418
|
}
|
|
406
419
|
}
|
|
@@ -459,7 +472,8 @@ export class DocumentService {
|
|
|
459
472
|
version,
|
|
460
473
|
onStepsAdded: this.onStepsAdded,
|
|
461
474
|
onErrorHandled: this.onErrorHandled,
|
|
462
|
-
analyticsHelper: this.analyticsHelper
|
|
475
|
+
analyticsHelper: this.analyticsHelper,
|
|
476
|
+
emit: this.providerEmitCallback
|
|
463
477
|
});
|
|
464
478
|
}
|
|
465
479
|
}
|
|
@@ -10,12 +10,15 @@ export let EVENT_ACTION = /*#__PURE__*/function (EVENT_ACTION) {
|
|
|
10
10
|
EVENT_ACTION["PUBLISH_PAGE"] = "publishPage";
|
|
11
11
|
EVENT_ACTION["GET_CURRENT_STATE"] = "getCurrentState";
|
|
12
12
|
EVENT_ACTION["INVALIDATE_TOKEN"] = "invalidateToken";
|
|
13
|
+
EVENT_ACTION["SEND_STEPS_RETRY"] = "sendStepsRetry";
|
|
14
|
+
EVENT_ACTION["CATCHUP_AFTER_MAX_SEND_STEPS_RETRY"] = "catchupAfterMaxSendStepsRetry";
|
|
13
15
|
EVENT_ACTION["DROPPED_STEPS"] = "droppedStepInCatchup";
|
|
14
16
|
return EVENT_ACTION;
|
|
15
17
|
}({});
|
|
16
18
|
export let EVENT_STATUS = /*#__PURE__*/function (EVENT_STATUS) {
|
|
17
19
|
EVENT_STATUS["SUCCESS"] = "SUCCESS";
|
|
18
20
|
EVENT_STATUS["FAILURE"] = "FAILURE";
|
|
21
|
+
EVENT_STATUS["INFO"] = "INFO";
|
|
19
22
|
return EVENT_STATUS;
|
|
20
23
|
}({});
|
|
21
24
|
export let ADD_STEPS_TYPE = /*#__PURE__*/function (ADD_STEPS_TYPE) {
|
|
@@ -13,7 +13,8 @@ export const commitStep = ({
|
|
|
13
13
|
clientId,
|
|
14
14
|
onStepsAdded,
|
|
15
15
|
onErrorHandled,
|
|
16
|
-
analyticsHelper
|
|
16
|
+
analyticsHelper,
|
|
17
|
+
emit
|
|
17
18
|
}) => {
|
|
18
19
|
const stepsWithClientAndUserId = steps.map(step => ({
|
|
19
20
|
...step.toJSON(),
|
|
@@ -21,6 +22,10 @@ export const commitStep = ({
|
|
|
21
22
|
userId
|
|
22
23
|
}));
|
|
23
24
|
const start = new Date().getTime();
|
|
25
|
+
emit('commit-status', {
|
|
26
|
+
status: 'attempt',
|
|
27
|
+
version
|
|
28
|
+
});
|
|
24
29
|
try {
|
|
25
30
|
broadcast('steps:commit', {
|
|
26
31
|
steps: stepsWithClientAndUserId,
|
|
@@ -38,6 +43,10 @@ export const commitStep = ({
|
|
|
38
43
|
latency,
|
|
39
44
|
stepType: countBy(stepsWithClientAndUserId, stepWithClientAndUserId => stepWithClientAndUserId.stepType)
|
|
40
45
|
});
|
|
46
|
+
emit('commit-status', {
|
|
47
|
+
status: 'success',
|
|
48
|
+
version: response.version
|
|
49
|
+
});
|
|
41
50
|
} else if (response.type === AcknowledgementResponseTypes.ERROR) {
|
|
42
51
|
onErrorHandled(response.error);
|
|
43
52
|
analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendActionEvent(EVENT_ACTION.ADD_STEPS, EVENT_STATUS.FAILURE, {
|
|
@@ -48,14 +57,26 @@ export const commitStep = ({
|
|
|
48
57
|
latency
|
|
49
58
|
});
|
|
50
59
|
analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(response.error, 'Error while adding steps - Acknowledgement Error');
|
|
60
|
+
emit('commit-status', {
|
|
61
|
+
status: 'failure',
|
|
62
|
+
version
|
|
63
|
+
});
|
|
51
64
|
} else {
|
|
52
65
|
analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(
|
|
53
66
|
// @ts-expect-error We didn't type the invalid type case
|
|
54
67
|
new Error(`Response type: ${(response === null || response === void 0 ? void 0 : response.type) || 'No response type'}`), 'Error while adding steps - Invalid Acknowledgement');
|
|
68
|
+
emit('commit-status', {
|
|
69
|
+
status: 'failure',
|
|
70
|
+
version
|
|
71
|
+
});
|
|
55
72
|
}
|
|
56
73
|
});
|
|
57
74
|
} catch (error) {
|
|
58
75
|
analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(error, 'Error while adding steps - Broadcast threw exception');
|
|
76
|
+
emit('commit-status', {
|
|
77
|
+
status: 'failure',
|
|
78
|
+
version
|
|
79
|
+
});
|
|
59
80
|
}
|
|
60
81
|
};
|
|
61
82
|
export const throttledCommitStep = throttle(commitStep, SEND_STEPS_THROTTLE, {
|
|
@@ -12,6 +12,7 @@ import { ParticipantsService } from '../participants/participants-service';
|
|
|
12
12
|
import { errorCodeMapper } from '../errors/error-code-mapper';
|
|
13
13
|
const logger = createLogger('Provider', 'black');
|
|
14
14
|
const OUT_OF_SYNC_PERIOD = 3 * 1000; // 3 seconds
|
|
15
|
+
const PRELOAD_DRAFT_SYNC_PERIOD = 15 * 1000; // 15 seconds
|
|
15
16
|
|
|
16
17
|
export const MAX_STEP_REJECTED_ERROR = 15;
|
|
17
18
|
export class Provider extends Emitter {
|
|
@@ -51,21 +52,28 @@ export class Provider extends Emitter {
|
|
|
51
52
|
sid,
|
|
52
53
|
initial: !initialized
|
|
53
54
|
});
|
|
54
|
-
|
|
55
|
-
//
|
|
55
|
+
|
|
56
|
+
// Early initialization with initial draft passed via provider
|
|
56
57
|
if (this.initialDraft && initialized && !this.isProviderInitialized) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
// Call catchup if the draft has become stale since being passed to provider
|
|
59
|
+
if (this.isDraftTimestampStale()) {
|
|
60
|
+
this.documentService.throttledCatchup();
|
|
61
|
+
}
|
|
62
|
+
// If the initial draft is already up to date, update the document with that of the initial draft
|
|
63
|
+
else {
|
|
64
|
+
const {
|
|
65
|
+
document,
|
|
66
|
+
version,
|
|
67
|
+
metadata
|
|
68
|
+
} = this.initialDraft;
|
|
69
|
+
// Initial document, version, metadata from initial draft
|
|
70
|
+
this.documentService.updateDocument({
|
|
71
|
+
doc: document,
|
|
72
|
+
version,
|
|
73
|
+
metadata
|
|
74
|
+
});
|
|
75
|
+
this.metadataService.updateMetadata(metadata);
|
|
76
|
+
}
|
|
69
77
|
this.isProviderInitialized = true;
|
|
70
78
|
}
|
|
71
79
|
// If already initialized, `connected` means reconnected
|
|
@@ -183,7 +191,7 @@ export class Provider extends Emitter {
|
|
|
183
191
|
this.isPreinitializing = false;
|
|
184
192
|
this.participantsService = new ParticipantsService(this.analyticsHelper, undefined, this.emitCallback, this.config.getUser, this.channel.broadcast, this.channel.sendPresenceJoined, this.getPresenceData, this.setUserId);
|
|
185
193
|
this.metadataService = new MetadataService(this.emitCallback, this.channel.sendMetadata);
|
|
186
|
-
this.documentService = new DocumentService(this.participantsService, this.analyticsHelper, this.channel.fetchCatchup, this.emitCallback, this.channel.broadcast, () => this.userId, this.onErrorHandled, this.metadataService);
|
|
194
|
+
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);
|
|
187
195
|
this.getStatePromise = new Promise(resolve => {
|
|
188
196
|
this.getStatePromiseResolve = resolve;
|
|
189
197
|
});
|
|
@@ -261,6 +269,19 @@ export class Provider extends Emitter {
|
|
|
261
269
|
}
|
|
262
270
|
}
|
|
263
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Checks the provider's initial draft timestamp to determine if it is stale.
|
|
274
|
+
* Returns true only if the time elapsed since the draft timestamp is greater than or
|
|
275
|
+
* equal to a predetermined timeout. Returns false in all other cases.
|
|
276
|
+
*/
|
|
277
|
+
isDraftTimestampStale() {
|
|
278
|
+
var _this$initialDraft;
|
|
279
|
+
if (!((_this$initialDraft = this.initialDraft) !== null && _this$initialDraft !== void 0 && _this$initialDraft.timestamp)) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
return Date.now() - this.initialDraft.timestamp >= PRELOAD_DRAFT_SYNC_PERIOD;
|
|
283
|
+
}
|
|
284
|
+
|
|
264
285
|
/**
|
|
265
286
|
* Send steps from transaction to NCS (and as a consequence to other participants), called from the collab-edit plugin in the editor
|
|
266
287
|
* @param {Transaction} _tr Deprecated, included to keep API consistent with Synchrony provider
|
package/dist/es2019/version.json
CHANGED