@atlaskit/collab-provider 10.4.0 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-jira/tsconfig.json +6 -0
  4. package/dist/cjs/analytics/analytics-helper.js +0 -2
  5. package/dist/cjs/api/api.js +26 -14
  6. package/dist/cjs/channel.js +0 -2
  7. package/dist/cjs/document/catchupv2.js +1 -4
  8. package/dist/cjs/document/document-service.js +35 -33
  9. package/dist/cjs/helpers/utils.js +80 -1
  10. package/dist/cjs/participants/participants-service.js +3 -2
  11. package/dist/cjs/provider/commit-step.js +14 -1
  12. package/dist/cjs/provider/index.js +69 -33
  13. package/dist/cjs/version-wrapper.js +1 -1
  14. package/dist/es2019/analytics/analytics-helper.js +0 -2
  15. package/dist/es2019/api/api.js +13 -1
  16. package/dist/es2019/channel.js +0 -2
  17. package/dist/es2019/document/catchupv2.js +1 -4
  18. package/dist/es2019/document/document-service.js +8 -6
  19. package/dist/es2019/helpers/utils.js +30 -1
  20. package/dist/es2019/participants/participants-service.js +3 -2
  21. package/dist/es2019/provider/commit-step.js +15 -1
  22. package/dist/es2019/provider/index.js +40 -17
  23. package/dist/es2019/version-wrapper.js +1 -1
  24. package/dist/esm/analytics/analytics-helper.js +0 -2
  25. package/dist/esm/api/api.js +26 -14
  26. package/dist/esm/channel.js +0 -2
  27. package/dist/esm/document/catchupv2.js +1 -4
  28. package/dist/esm/document/document-service.js +35 -33
  29. package/dist/esm/helpers/utils.js +78 -1
  30. package/dist/esm/participants/participants-service.js +3 -2
  31. package/dist/esm/provider/commit-step.js +14 -1
  32. package/dist/esm/provider/index.js +71 -35
  33. package/dist/esm/version-wrapper.js +1 -1
  34. package/dist/types/document/document-service.d.ts +1 -0
  35. package/dist/types/errors/custom-errors.d.ts +1 -1
  36. package/dist/types/helpers/utils.d.ts +9 -1
  37. package/dist/types/index.d.ts +1 -1
  38. package/dist/types/participants/participants-service.d.ts +1 -0
  39. package/dist/types/provider/commit-step.d.ts +3 -1
  40. package/dist/types/types.d.ts +1 -0
  41. package/dist/types-ts4.5/document/document-service.d.ts +1 -0
  42. package/dist/types-ts4.5/errors/custom-errors.d.ts +1 -1
  43. package/dist/types-ts4.5/helpers/utils.d.ts +9 -1
  44. package/dist/types-ts4.5/index.d.ts +1 -1
  45. package/dist/types-ts4.5/participants/participants-service.d.ts +1 -0
  46. package/dist/types-ts4.5/provider/commit-step.d.ts +3 -1
  47. package/dist/types-ts4.5/types.d.ts +1 -0
  48. package/package.json +16 -6
@@ -15,6 +15,7 @@ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
15
15
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
16
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
17
  var _uuid = require("uuid");
18
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
19
  var _emitter = require("../emitter");
19
20
  var _channel = require("../channel");
20
21
  var _utils = require("../helpers/utils");
@@ -162,7 +163,29 @@ var Provider = exports.Provider = /*#__PURE__*/function (_Emitter) {
162
163
  _this.emit('permission', permit);
163
164
  }).on('steps:added', _this.documentService.onStepsAdded).on('metadata:changed', _this.metadataService.onMetadataChanged).on('participant:telepointer', function (payload) {
164
165
  return _this.participantsService.onParticipantTelepointer(payload, _this.sessionId);
165
- }).on('participant:activity-join', _this.participantsService.onParticipantActivityJoin).on('participant:activity-ack', _this.participantsService.onParticipantActivityAck).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(shouldSkipDocumentInit);
166
+ }).on('participant:activity-join', _this.participantsService.onParticipantActivityJoin).on('participant:activity-ack', _this.participantsService.onParticipantActivityAck).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', /*#__PURE__*/function () {
167
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(status) {
168
+ var isLocked;
169
+ return _regenerator.default.wrap(function _callee$(_context) {
170
+ while (1) switch (_context.prev = _context.next) {
171
+ case 0:
172
+ _context.next = 2;
173
+ return _this.namespaceService.onNamespaceStatusChanged(status);
174
+ case 2:
175
+ isLocked = _this.namespaceService.getIsNamespaceLocked();
176
+ _this.emit('namespace-lock:check', {
177
+ isLocked: isLocked
178
+ });
179
+ case 4:
180
+ case "end":
181
+ return _context.stop();
182
+ }
183
+ }, _callee);
184
+ }));
185
+ return function (_x) {
186
+ return _ref4.apply(this, arguments);
187
+ };
188
+ }()).connect(shouldSkipDocumentInit);
166
189
  });
167
190
  (0, _defineProperty2.default)(_this, "setUserId", function (id) {
168
191
  _this.userId = id;
@@ -209,8 +232,8 @@ var Provider = exports.Provider = /*#__PURE__*/function (_Emitter) {
209
232
  return _this.aiProviderActiveIds;
210
233
  });
211
234
  // Note: this gets triggered on page reload for Firefox (not other browsers) because of closeOnBeforeunload: false
212
- (0, _defineProperty2.default)(_this, "onDisconnected", function (_ref4) {
213
- var reason = _ref4.reason;
235
+ (0, _defineProperty2.default)(_this, "onDisconnected", function (_ref5) {
236
+ var reason = _ref5.reason;
214
237
  _this.disconnectedAt = Date.now();
215
238
  _this.participantsService.disconnect(reason, _this.sessionId);
216
239
  });
@@ -225,52 +248,52 @@ var Provider = exports.Provider = /*#__PURE__*/function (_Emitter) {
225
248
  * Used for draft sync, a process running every 5s for the first editor of a document to sync the document to the Confluence back-end.
226
249
  * @throws {GetCurrentStateError} Something went wrong while returning the current state
227
250
  */
228
- (0, _defineProperty2.default)(_this, "getCurrentState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
251
+ (0, _defineProperty2.default)(_this, "getCurrentState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
229
252
  var _this$analyticsHelper4;
230
- return _regenerator.default.wrap(function _callee$(_context) {
231
- while (1) switch (_context.prev = _context.next) {
253
+ return _regenerator.default.wrap(function _callee2$(_context2) {
254
+ while (1) switch (_context2.prev = _context2.next) {
232
255
  case 0:
233
- _context.prev = 0;
234
- _context.next = 3;
256
+ _context2.prev = 0;
257
+ _context2.next = 3;
235
258
  return _this.documentService.getCurrentState();
236
259
  case 3:
237
- return _context.abrupt("return", _context.sent);
260
+ return _context2.abrupt("return", _context2.sent);
238
261
  case 6:
239
- _context.prev = 6;
240
- _context.t0 = _context["catch"](0);
241
- (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendErrorEvent(_context.t0, 'Error while returning ADF version of current draft document');
242
- throw new _customErrors.GetCurrentStateError('Error while returning the current state of the draft document', _context.t0);
262
+ _context2.prev = 6;
263
+ _context2.t0 = _context2["catch"](0);
264
+ (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendErrorEvent(_context2.t0, 'Error while returning ADF version of current draft document');
265
+ throw new _customErrors.GetCurrentStateError('Error while returning the current state of the draft document', _context2.t0);
243
266
  case 10:
244
267
  case "end":
245
- return _context.stop();
268
+ return _context2.stop();
246
269
  }
247
- }, _callee, null, [[0, 6]]);
270
+ }, _callee2, null, [[0, 6]]);
248
271
  })));
249
272
  /**
250
273
  * Return the final acknowledged (by NCS) ADF version of the current draft document, together with it's title and the current step version.
251
274
  * Used when returning the document to Confluence on publish.
252
275
  * @throws {GetFinalAcknowledgedStateError} Something went wrong while returning the acknowledged state
253
276
  */
254
- (0, _defineProperty2.default)(_this, "getFinalAcknowledgedState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
277
+ (0, _defineProperty2.default)(_this, "getFinalAcknowledgedState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
255
278
  var _this$analyticsHelper5;
256
- return _regenerator.default.wrap(function _callee2$(_context2) {
257
- while (1) switch (_context2.prev = _context2.next) {
279
+ return _regenerator.default.wrap(function _callee3$(_context3) {
280
+ while (1) switch (_context3.prev = _context3.next) {
258
281
  case 0:
259
- _context2.prev = 0;
260
- _context2.next = 3;
282
+ _context3.prev = 0;
283
+ _context3.next = 3;
261
284
  return _this.documentService.getFinalAcknowledgedState();
262
285
  case 3:
263
- return _context2.abrupt("return", _context2.sent);
286
+ return _context3.abrupt("return", _context3.sent);
264
287
  case 6:
265
- _context2.prev = 6;
266
- _context2.t0 = _context2["catch"](0);
267
- (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 || _this$analyticsHelper5.sendErrorEvent(_context2.t0, 'Error while returning ADF version of the final draft document');
268
- throw new _customErrors.GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', _context2.t0);
288
+ _context3.prev = 6;
289
+ _context3.t0 = _context3["catch"](0);
290
+ (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 || _this$analyticsHelper5.sendErrorEvent(_context3.t0, 'Error while returning ADF version of the final draft document');
291
+ throw new _customErrors.GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', _context3.t0);
269
292
  case 10:
270
293
  case "end":
271
- return _context2.stop();
294
+ return _context3.stop();
272
295
  }
273
- }, _callee2, null, [[0, 6]]);
296
+ }, _callee3, null, [[0, 6]]);
274
297
  })));
275
298
  (0, _defineProperty2.default)(_this, "getUnconfirmedSteps", function () {
276
299
  return _this.documentService.getUnconfirmedSteps();
@@ -359,10 +382,10 @@ var Provider = exports.Provider = /*#__PURE__*/function (_Emitter) {
359
382
  */
360
383
  }, {
361
384
  key: "setup",
362
- value: function setup(_ref7) {
363
- var getState = _ref7.getState,
364
- editorApi = _ref7.editorApi,
365
- onSyncUpError = _ref7.onSyncUpError;
385
+ value: function setup(_ref8) {
386
+ var getState = _ref8.getState,
387
+ editorApi = _ref8.editorApi,
388
+ onSyncUpError = _ref8.onSyncUpError;
366
389
  this.checkForCookies();
367
390
  try {
368
391
  // Ignored via go/ees005
@@ -456,16 +479,29 @@ var Provider = exports.Provider = /*#__PURE__*/function (_Emitter) {
456
479
  }, {
457
480
  key: "send",
458
481
  value: function send(_tr, _oldState, newState) {
482
+ var _this2 = this;
459
483
  try {
460
484
  if (this.isViewOnly()) {
461
- var _this$analyticsHelper10;
462
485
  var error = {
463
486
  message: 'Attempted to send steps in view only mode',
464
487
  data: {
465
488
  code: _internalErrors.INTERNAL_ERROR_CODE.VIEW_ONLY_STEPS_ERROR
466
489
  }
467
490
  };
468
- (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 || _this$analyticsHelper10.sendErrorEvent(error, error.message);
491
+ if ((0, _platformFeatureFlags.fg)('log_obfuscated_steps_for_view_only')) {
492
+ (0, _utils.logObfuscatedSteps)(_oldState, newState).then(function (attributes) {
493
+ var _this2$analyticsHelpe;
494
+ var stepAttributes = attributes instanceof _customErrors.CustomError ? {} : _objectSpread({}, attributes);
495
+ var stepsError = new _customErrors.CustomError(error.message, error, _objectSpread({}, stepAttributes));
496
+ (_this2$analyticsHelpe = _this2.analyticsHelper) === null || _this2$analyticsHelpe === void 0 || _this2$analyticsHelpe.sendErrorEvent(stepsError, stepsError.message);
497
+ }).catch(function (err) {
498
+ var _this2$analyticsHelpe2;
499
+ return (_this2$analyticsHelpe2 = _this2.analyticsHelper) === null || _this2$analyticsHelpe2 === void 0 ? void 0 : _this2$analyticsHelpe2.sendErrorEvent(err, err.message);
500
+ });
501
+ } else {
502
+ var _this$analyticsHelper10;
503
+ (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 || _this$analyticsHelper10.sendErrorEvent(error, error.message);
504
+ }
469
505
  return;
470
506
  }
471
507
  // Don't send steps while the document is locked (eg. when restoring the document)
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/collab-provider";
8
- var version = exports.version = "10.4.0";
8
+ var version = exports.version = "10.5.0";
9
9
  var nextMajorVersion = exports.nextMajorVersion = function nextMajorVersion() {
10
10
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
11
11
  };
@@ -58,8 +58,6 @@ const triggerAnalyticsEvent = (analyticsEvent, analyticsClient) => {
58
58
  }
59
59
  };
60
60
  export default class AnalyticsHelper {
61
- // Ignored via go/ees005
62
- // eslint-disable-next-line @typescript-eslint/max-params
63
61
  constructor(documentAri, subProduct, analyticsClient, getAnalyticsClient) {
64
62
  this.documentAri = documentAri;
65
63
  this.subProduct = subProduct;
@@ -1,5 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { getProduct, getSubProduct, createLogger } from '../helpers/utils';
3
+ import { getActiveTraceHttpRequestHeaders } from '@atlaskit/react-ufo/experience-trace-id-context';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
5
+ import { addFeatureFlagAccessed } from '@atlaskit/react-ufo/feature-flags-accessed';
3
6
  const logger = createLogger('Api', 'blue');
4
7
  class AddCommentError extends Error {
5
8
  constructor(message, status, meta) {
@@ -27,6 +30,14 @@ export class Api {
27
30
  });
28
31
  const url = `${this.config.url}/document/${encodeURIComponent(this.config.documentAri)}/comment`;
29
32
  logger(`Request url: `, url);
33
+
34
+ //Get tracing headers from UFO
35
+ const tracingHeaderEnabled = fg('platform_collab_provider_tracingheaders');
36
+ addFeatureFlagAccessed('platform_collab_provider_tracingheaders', tracingHeaderEnabled);
37
+ let tracingHeaders = {};
38
+ if (tracingHeaderEnabled) {
39
+ tracingHeaders = getActiveTraceHttpRequestHeaders(url);
40
+ }
30
41
  const fetchOptions = {
31
42
  credentials: 'include',
32
43
  headers: {
@@ -35,7 +46,8 @@ export class Api {
35
46
  } : {}),
36
47
  'x-product': getProduct(this.config.productInfo),
37
48
  'x-subproduct': getSubProduct(this.config.productInfo),
38
- 'Content-Type': 'application/json'
49
+ 'Content-Type': 'application/json',
50
+ ...tracingHeaders
39
51
  },
40
52
  method: 'POST',
41
53
  body: reqBody
@@ -173,8 +173,6 @@ export class Channel extends Emitter {
173
173
  this.emit('steps:added', data);
174
174
  }
175
175
  });
176
- // Ignored via go/ees005
177
- // eslint-disable-next-line @typescript-eslint/max-params
178
176
  _defineProperty(this, "fetchCatchupv2", async (fromVersion, clientId, catchUpOutofSync, reason) => {
179
177
  try {
180
178
  const {
@@ -68,9 +68,6 @@ const logObfuscatedSteps = (steps, opt) => {
68
68
  * @param clientId The ID of the currently connected session (one user can have multiple if theu have multiple tabs open)
69
69
  * @returns True if we're out of sync, false if not.
70
70
  */
71
- export const isOutOfSync = (fromVersion, currentVersion, steps, clientId
72
- // Ignored via go/ees005
73
- // eslint-disable-next-line @typescript-eslint/max-params
74
- ) =>
71
+ export const isOutOfSync = (fromVersion, currentVersion, steps, clientId) =>
75
72
  // If version number hasn't increased, and steps are not from our client, we're out of sync
76
73
  Boolean(fromVersion >= currentVersion && steps.some(step => step.clientId !== clientId));
@@ -15,7 +15,7 @@ import { CantSyncUpError, UpdateDocumentError } from '../errors/custom-errors';
15
15
  const CATCHUP_THROTTLE = 1 * 1000; // 1 second
16
16
 
17
17
  const noop = () => {};
18
- const logger = createLogger('documentService', 'black');
18
+ const logger = createLogger('documentService', 'red');
19
19
  export class DocumentService {
20
20
  // ClientID is the unique ID for a prosemirror client. Used for step-rebasing.
21
21
 
@@ -34,8 +34,6 @@ export class DocumentService {
34
34
  * @param enableErrorOnFailedDocumentApply - Enable failed document update exceptions.
35
35
  * @param getConnected - if the channel is currently connected
36
36
  */
37
- // Ignored via go/ees005
38
- // eslint-disable-next-line @typescript-eslint/max-params
39
37
  constructor(participantsService, analyticsHelper, fetchCatchupv2, fetchReconcile,
40
38
  // Ignored via go/ees005
41
39
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -46,6 +44,7 @@ export class DocumentService {
46
44
  _defineProperty(this, "stepRejectCounter", 0);
47
45
  _defineProperty(this, "aggressiveCatchup", false);
48
46
  _defineProperty(this, "catchUpOutofSync", false);
47
+ _defineProperty(this, "hasRecovered", false);
49
48
  /**
50
49
  * To prevent calling catchup to often, use lodash throttle to reduce the frequency
51
50
  * @param reason - optional reason to attach.
@@ -283,6 +282,9 @@ export class DocumentService {
283
282
  metadata,
284
283
  targetClientId
285
284
  }) => {
285
+ if (!targetClientId) {
286
+ this.hasRecovered = true;
287
+ }
286
288
  if (targetClientId && this.clientId !== targetClientId) {
287
289
  return;
288
290
  }
@@ -704,8 +706,6 @@ export class DocumentService {
704
706
  * Send steps from transaction to other participants
705
707
  * It needs the superfluous arguments because we keep the interface of the send API the same as the Synchrony plugin
706
708
  */
707
- // Ignored via go/ees005
708
- // eslint-disable-next-line @typescript-eslint/max-params
709
709
  send(_tr, _oldState, newState, sendAnalyticsEvent) {
710
710
  const unconfirmedStepsData = sendableSteps(newState);
711
711
  const version = this.getVersionFromCollabState(newState, 'collab-provider: send');
@@ -763,7 +763,9 @@ export class DocumentService {
763
763
  onErrorHandled: this.onErrorHandled,
764
764
  analyticsHelper: this.analyticsHelper,
765
765
  emit: this.providerEmitCallback,
766
- __livePage: this.options.__livePage
766
+ __livePage: this.options.__livePage,
767
+ hasRecovered: this.hasRecovered,
768
+ collabMode: this.participantsService.getCollabMode()
767
769
  });
768
770
  }
769
771
  }
@@ -1,4 +1,6 @@
1
1
  import { scrubAdf } from '@atlaskit/adf-utils/scrub';
2
+ import { sendableSteps } from '@atlaskit/prosemirror-collab';
3
+ import { CustomError } from '../errors/custom-errors';
2
4
  export const createLogger = (prefix, color = 'blue') =>
3
5
  // Ignored via go/ees005
4
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -179,4 +181,31 @@ const stepToAdf = step => {
179
181
  });
180
182
  }
181
183
  return [];
182
- };
184
+ };
185
+ export async function logObfuscatedSteps(oldState, newState) {
186
+ try {
187
+ var _states$new, _states$old;
188
+ let stepsFromOldState = '',
189
+ stepsFromNewState = '';
190
+ const states = {
191
+ old: oldState ? sendableSteps(oldState) : null,
192
+ new: sendableSteps(newState)
193
+ };
194
+ if ((_states$new = states.new) !== null && _states$new !== void 0 && _states$new.steps) {
195
+ stepsFromNewState = await toObfuscatedSteps(states.new.steps);
196
+ }
197
+ if ((_states$old = states.old) !== null && _states$old !== void 0 && _states$old.steps) {
198
+ stepsFromOldState = await toObfuscatedSteps(states.old.steps);
199
+ }
200
+ return {
201
+ stepsFromOldState,
202
+ stepsFromNewState
203
+ };
204
+ } catch (err) {
205
+ return new CustomError('Failed to obfuscate steps', err);
206
+ }
207
+ }
208
+ export async function toObfuscatedSteps(steps) {
209
+ const _steps = await Promise.resolve(steps.slice().map(s => s.toJSON()));
210
+ return JSON.stringify(getObfuscatedSteps(_steps));
211
+ }
@@ -18,8 +18,6 @@ const SEND_PRESENCE_INTERVAL = 150 * 1000; // 150 seconds
18
18
  * @param sendPresenceJoined Callback to Channel class
19
19
  */
20
20
  export class ParticipantsService {
21
- // Ignored via go/ees005
22
- // eslint-disable-next-line @typescript-eslint/max-params
23
21
  constructor(analyticsHelper, participantsState = new ParticipantsState(), emit, getUser, channelBroadcast, sendPresenceJoined, getPresenceData, setUserId, getAIProviderActiveIds) {
24
22
  _defineProperty(this, "sendAIProviderChanged", payload => {
25
23
  if (payload.providerId) {
@@ -342,6 +340,9 @@ export class ParticipantsService {
342
340
  _defineProperty(this, "getAIProviderParticipants", () => {
343
341
  return this.participantsState.getAIProviderParticipants();
344
342
  });
343
+ _defineProperty(this, "getCollabMode", () => {
344
+ return this.participantsState.size() > 1 ? 'collab' : 'single';
345
+ });
345
346
  this.analyticsHelper = analyticsHelper;
346
347
  this.participantsState = participantsState;
347
348
  this.emit = emit;
@@ -17,7 +17,9 @@ export const commitStepQueue = ({
17
17
  onErrorHandled,
18
18
  analyticsHelper,
19
19
  emit,
20
- __livePage
20
+ __livePage,
21
+ hasRecovered,
22
+ collabMode
21
23
  }) => {
22
24
  if (!readyToCommit) {
23
25
  logger('Not ready to commit, skip');
@@ -60,6 +62,17 @@ export const commitStepQueue = ({
60
62
  return step;
61
63
  });
62
64
  }
65
+
66
+ // tag unconfirmed steps sent after page has been recovered during client's editing session
67
+ if (hasRecovered && fg('tag_unconfirmed_steps_after_recovery')) {
68
+ stepsWithClientAndUserId = stepsWithClientAndUserId.map(step => {
69
+ step.metadata = {
70
+ ...step.metadata,
71
+ unconfirmedStepAfterRecovery: true
72
+ };
73
+ return step;
74
+ });
75
+ }
63
76
  const start = new Date().getTime();
64
77
  emit('commit-status', {
65
78
  status: 'attempt',
@@ -67,6 +80,7 @@ export const commitStepQueue = ({
67
80
  });
68
81
  try {
69
82
  broadcast('steps:commit', {
83
+ collabMode,
70
84
  steps: stepsWithClientAndUserId,
71
85
  version,
72
86
  userId
@@ -1,11 +1,12 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { v4 as uuidv4 } from 'uuid';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { Emitter } from '../emitter';
4
5
  import { Channel } from '../channel';
5
- import { createLogger } from '../helpers/utils';
6
+ import { createLogger, logObfuscatedSteps } from '../helpers/utils';
6
7
  import AnalyticsHelper from '../analytics/analytics-helper';
7
8
  import { telepointerCallback } from '../participants/telepointers-helper';
8
- import { DestroyError, GetCurrentStateError, GetFinalAcknowledgedStateError, ProviderInitialisationError, SendTransactionError, SetEditorWidthError, SetMetadataError, SetTitleError } from '../errors/custom-errors';
9
+ import { CustomError, DestroyError, GetCurrentStateError, GetFinalAcknowledgedStateError, ProviderInitialisationError, SendTransactionError, SetEditorWidthError, SetMetadataError, SetTitleError } from '../errors/custom-errors';
9
10
  import { NCS_ERROR_CODE } from '../errors/ncs-errors';
10
11
  import { MetadataService } from '../metadata/metadata-service';
11
12
  import { DocumentService } from '../document/document-service';
@@ -140,7 +141,13 @@ export class Provider extends Emitter {
140
141
  }).on('restore', this.documentService.onRestore).on('permission', permit => {
141
142
  this.permit = Object.assign(this.permit, permit);
142
143
  this.emit('permission', permit);
143
- }).on('steps:added', this.documentService.onStepsAdded).on('metadata:changed', this.metadataService.onMetadataChanged).on('participant:telepointer', payload => this.participantsService.onParticipantTelepointer(payload, this.sessionId)).on('participant:activity-join', this.participantsService.onParticipantActivityJoin).on('participant:activity-ack', this.participantsService.onParticipantActivityAck).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(shouldSkipDocumentInit);
144
+ }).on('steps:added', this.documentService.onStepsAdded).on('metadata:changed', this.metadataService.onMetadataChanged).on('participant:telepointer', payload => this.participantsService.onParticipantTelepointer(payload, this.sessionId)).on('participant:activity-join', this.participantsService.onParticipantActivityJoin).on('participant:activity-ack', this.participantsService.onParticipantActivityAck).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', async status => {
145
+ await this.namespaceService.onNamespaceStatusChanged(status);
146
+ const isLocked = this.namespaceService.getIsNamespaceLocked();
147
+ this.emit('namespace-lock:check', {
148
+ isLocked
149
+ });
150
+ }).connect(shouldSkipDocumentInit);
144
151
  });
145
152
  _defineProperty(this, "setUserId", id => {
146
153
  this.userId = id;
@@ -398,14 +405,30 @@ export class Provider extends Emitter {
398
405
  send(_tr, _oldState, newState) {
399
406
  try {
400
407
  if (this.isViewOnly()) {
401
- var _this$analyticsHelper10;
402
408
  const error = {
403
409
  message: 'Attempted to send steps in view only mode',
404
410
  data: {
405
411
  code: INTERNAL_ERROR_CODE.VIEW_ONLY_STEPS_ERROR
406
412
  }
407
413
  };
408
- (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(error, error.message);
414
+ if (fg('log_obfuscated_steps_for_view_only')) {
415
+ logObfuscatedSteps(_oldState, newState).then(attributes => {
416
+ var _this$analyticsHelper10;
417
+ const stepAttributes = attributes instanceof CustomError ? {} : {
418
+ ...attributes
419
+ };
420
+ const stepsError = new CustomError(error.message, error, {
421
+ ...stepAttributes
422
+ });
423
+ (_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(stepsError, stepsError.message);
424
+ }).catch(err => {
425
+ var _this$analyticsHelper11;
426
+ return (_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(err, err.message);
427
+ });
428
+ } else {
429
+ var _this$analyticsHelper12;
430
+ (_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, error.message);
431
+ }
409
432
  return;
410
433
  }
411
434
  // Don't send steps while the document is locked (eg. when restoring the document)
@@ -415,8 +438,8 @@ export class Provider extends Emitter {
415
438
  }
416
439
  this.documentService.send(_tr, _oldState, newState);
417
440
  } catch (error) {
418
- var _this$analyticsHelper11;
419
- (_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, 'Error while sending steps for a transaction');
441
+ var _this$analyticsHelper13;
442
+ (_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(error, 'Error while sending steps for a transaction');
420
443
  throw new SendTransactionError('Error while sending steps for a transaction', error);
421
444
  }
422
445
  }
@@ -468,9 +491,9 @@ export class Provider extends Emitter {
468
491
  });
469
492
  }
470
493
  } catch (error) {
471
- var _this$analyticsHelper12;
494
+ var _this$analyticsHelper14;
472
495
  // We don't want to throw errors for Presence features as they tend to self-restore
473
- (_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while sending message - telepointer');
496
+ (_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendErrorEvent(error, 'Error while sending message - telepointer');
474
497
  }
475
498
  }
476
499
  setAIProviderActiveIds(ids = []) {
@@ -511,8 +534,8 @@ export class Provider extends Emitter {
511
534
  this.sendStepsTimer = undefined;
512
535
  }
513
536
  } catch (error) {
514
- var _this$analyticsHelper13;
515
- (_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(error, 'Error while shutting down the collab provider');
537
+ var _this$analyticsHelper15;
538
+ (_this$analyticsHelper15 = this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 ? void 0 : _this$analyticsHelper15.sendErrorEvent(error, 'Error while shutting down the collab provider');
516
539
  throw new DestroyError('Error while shutting down the collab provider', error);
517
540
  }
518
541
  this.clearTimers();
@@ -534,8 +557,8 @@ export class Provider extends Emitter {
534
557
  }
535
558
  this.metadataService.setTitle(title, broadcast);
536
559
  } catch (error) {
537
- var _this$analyticsHelper14;
538
- (_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendErrorEvent(error, 'Error while setting title');
560
+ var _this$analyticsHelper16;
561
+ (_this$analyticsHelper16 = this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 ? void 0 : _this$analyticsHelper16.sendErrorEvent(error, 'Error while setting title');
539
562
  throw new SetTitleError('Error while setting title', error);
540
563
  }
541
564
  }
@@ -552,8 +575,8 @@ export class Provider extends Emitter {
552
575
  try {
553
576
  this.metadataService.setEditorWidth(editorWidth, broadcast);
554
577
  } catch (error) {
555
- var _this$analyticsHelper15;
556
- (_this$analyticsHelper15 = this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 ? void 0 : _this$analyticsHelper15.sendErrorEvent(error, 'Error while setting editor width');
578
+ var _this$analyticsHelper17;
579
+ (_this$analyticsHelper17 = this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 ? void 0 : _this$analyticsHelper17.sendErrorEvent(error, 'Error while setting editor width');
557
580
  throw new SetEditorWidthError('Error while setting editor width', error);
558
581
  }
559
582
  }
@@ -570,8 +593,8 @@ export class Provider extends Emitter {
570
593
  }
571
594
  this.metadataService.setMetadata(metadata);
572
595
  } catch (error) {
573
- var _this$analyticsHelper16;
574
- (_this$analyticsHelper16 = this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 ? void 0 : _this$analyticsHelper16.sendErrorEvent(error, 'Error while setting metadata');
596
+ var _this$analyticsHelper18;
597
+ (_this$analyticsHelper18 = this.analyticsHelper) === null || _this$analyticsHelper18 === void 0 ? void 0 : _this$analyticsHelper18.sendErrorEvent(error, 'Error while setting metadata');
575
598
  throw new SetMetadataError('Error while setting metadata', error);
576
599
  }
577
600
  }
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/collab-provider";
2
- export const version = "10.4.0";
2
+ export const version = "10.5.0";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -64,8 +64,6 @@ var triggerAnalyticsEvent = function triggerAnalyticsEvent(analyticsEvent, analy
64
64
  }
65
65
  };
66
66
  var AnalyticsHelper = /*#__PURE__*/function () {
67
- // Ignored via go/ees005
68
- // eslint-disable-next-line @typescript-eslint/max-params
69
67
  function AnalyticsHelper(documentAri, subProduct, analyticsClient, getAnalyticsClient) {
70
68
  _classCallCheck(this, AnalyticsHelper);
71
69
  this.documentAri = documentAri;
@@ -12,6 +12,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
12
12
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
13
13
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
14
  import { getProduct, getSubProduct, createLogger } from '../helpers/utils';
15
+ import { getActiveTraceHttpRequestHeaders } from '@atlaskit/react-ufo/experience-trace-id-context';
16
+ import { fg } from '@atlaskit/platform-feature-flags';
17
+ import { addFeatureFlagAccessed } from '@atlaskit/react-ufo/feature-flags-accessed';
15
18
  var logger = createLogger('Api', 'blue');
16
19
  var AddCommentError = /*#__PURE__*/function (_Error) {
17
20
  function AddCommentError(message, status, meta) {
@@ -39,7 +42,7 @@ export var Api = /*#__PURE__*/function () {
39
42
  _classCallCheck(this, Api);
40
43
  _defineProperty(this, "submitComment", /*#__PURE__*/function () {
41
44
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(steps, version) {
42
- var reqBody, url, fetchOptions;
45
+ var reqBody, url, tracingHeaderEnabled, tracingHeaders, fetchOptions;
43
46
  return _regeneratorRuntime.wrap(function _callee$(_context) {
44
47
  while (1) switch (_context.prev = _context.next) {
45
48
  case 0:
@@ -50,25 +53,33 @@ export var Api = /*#__PURE__*/function () {
50
53
  });
51
54
  url = "".concat(_this2.config.url, "/document/").concat(encodeURIComponent(_this2.config.documentAri), "/comment");
52
55
  logger("Request url: ", url);
56
+
57
+ //Get tracing headers from UFO
58
+ tracingHeaderEnabled = fg('platform_collab_provider_tracingheaders');
59
+ addFeatureFlagAccessed('platform_collab_provider_tracingheaders', tracingHeaderEnabled);
60
+ tracingHeaders = {};
61
+ if (tracingHeaderEnabled) {
62
+ tracingHeaders = getActiveTraceHttpRequestHeaders(url);
63
+ }
53
64
  _context.t0 = _objectSpread;
54
65
  _context.t1 = _objectSpread;
55
66
  _context.t2 = {};
56
67
  if (!_this2.config.permissionTokenRefresh) {
57
- _context.next = 13;
68
+ _context.next = 17;
58
69
  break;
59
70
  }
60
- _context.next = 9;
71
+ _context.next = 13;
61
72
  return _this2.channel.getChannelToken();
62
- case 9:
73
+ case 13:
63
74
  _context.t4 = _context.sent;
64
75
  _context.t3 = {
65
76
  'x-token': _context.t4
66
77
  };
67
- _context.next = 14;
78
+ _context.next = 18;
68
79
  break;
69
- case 13:
80
+ case 17:
70
81
  _context.t3 = {};
71
- case 14:
82
+ case 18:
72
83
  _context.t5 = _context.t3;
73
84
  _context.t6 = (0, _context.t1)(_context.t2, _context.t5);
74
85
  _context.t7 = {};
@@ -77,19 +88,20 @@ export var Api = /*#__PURE__*/function () {
77
88
  'x-subproduct': getSubProduct(_this2.config.productInfo),
78
89
  'Content-Type': 'application/json'
79
90
  };
80
- _context.t9 = (0, _context.t0)(_context.t6, _context.t7, _context.t8);
81
- _context.t10 = reqBody;
91
+ _context.t9 = tracingHeaders;
92
+ _context.t10 = (0, _context.t0)(_context.t6, _context.t7, _context.t8, _context.t9);
93
+ _context.t11 = reqBody;
82
94
  fetchOptions = {
83
95
  credentials: 'include',
84
- headers: _context.t9,
96
+ headers: _context.t10,
85
97
  method: 'POST',
86
- body: _context.t10
98
+ body: _context.t11
87
99
  };
88
- _context.next = 23;
100
+ _context.next = 28;
89
101
  return fetch(url, fetchOptions);
90
- case 23:
102
+ case 28:
91
103
  return _context.abrupt("return", _context.sent);
92
- case 24:
104
+ case 29:
93
105
  case "end":
94
106
  return _context.stop();
95
107
  }