@atlaskit/collab-provider 9.7.0 → 9.7.2

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 (76) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/channel.js +12 -1
  3. package/dist/cjs/disconnected-reason-mapper.js +8 -17
  4. package/dist/cjs/errors/error-code-mapper.js +13 -12
  5. package/dist/cjs/errors/error-types.js +2 -95
  6. package/dist/cjs/feature-flags/__test__/index.unit.js +3 -2
  7. package/dist/cjs/feature-flags/index.js +4 -2
  8. package/dist/cjs/helpers/const.js +2 -1
  9. package/dist/cjs/helpers/socket-message-metrics.js +54 -0
  10. package/dist/cjs/index.js +2 -2
  11. package/dist/cjs/types.js +1 -1
  12. package/dist/cjs/version-wrapper.js +1 -1
  13. package/dist/cjs/version.json +1 -1
  14. package/dist/es2019/channel.js +11 -0
  15. package/dist/es2019/disconnected-reason-mapper.js +2 -9
  16. package/dist/es2019/errors/error-code-mapper.js +2 -1
  17. package/dist/es2019/errors/error-types.js +0 -94
  18. package/dist/es2019/feature-flags/__test__/index.unit.js +3 -2
  19. package/dist/es2019/feature-flags/index.js +4 -2
  20. package/dist/es2019/helpers/const.js +2 -1
  21. package/dist/es2019/helpers/socket-message-metrics.js +40 -0
  22. package/dist/es2019/index.js +1 -1
  23. package/dist/es2019/types.js +1 -1
  24. package/dist/es2019/version-wrapper.js +1 -1
  25. package/dist/es2019/version.json +1 -1
  26. package/dist/esm/channel.js +12 -1
  27. package/dist/esm/disconnected-reason-mapper.js +2 -9
  28. package/dist/esm/errors/error-code-mapper.js +2 -1
  29. package/dist/esm/errors/error-types.js +0 -94
  30. package/dist/esm/feature-flags/__test__/index.unit.js +3 -2
  31. package/dist/esm/feature-flags/index.js +4 -2
  32. package/dist/esm/helpers/const.js +2 -1
  33. package/dist/esm/helpers/socket-message-metrics.js +45 -0
  34. package/dist/esm/index.js +1 -1
  35. package/dist/esm/types.js +1 -1
  36. package/dist/esm/version-wrapper.js +1 -1
  37. package/dist/esm/version.json +1 -1
  38. package/dist/types/channel.d.ts +3 -1
  39. package/dist/types/disconnected-reason-mapper.d.ts +1 -8
  40. package/dist/types/document/document-service.d.ts +3 -2
  41. package/dist/types/errors/error-code-mapper.d.ts +2 -1
  42. package/dist/types/errors/error-types.d.ts +0 -190
  43. package/dist/types/feature-flags/types.d.ts +1 -0
  44. package/dist/types/helpers/const.d.ts +13 -3
  45. package/dist/types/helpers/socket-message-metrics.d.ts +14 -0
  46. package/dist/types/index.d.ts +3 -3
  47. package/dist/types/metadata/metadata-service.d.ts +1 -1
  48. package/dist/types/participants/participants-helper.d.ts +2 -6
  49. package/dist/types/participants/participants-service.d.ts +3 -2
  50. package/dist/types/participants/participants-state.d.ts +2 -1
  51. package/dist/types/participants/telepointers-helper.d.ts +2 -2
  52. package/dist/types/provider/commit-step.d.ts +2 -1
  53. package/dist/types/provider/index.d.ts +3 -3
  54. package/dist/types/socket-io-provider.d.ts +1 -1
  55. package/dist/types/types.d.ts +2 -149
  56. package/dist/types-ts4.5/channel.d.ts +3 -1
  57. package/dist/types-ts4.5/disconnected-reason-mapper.d.ts +1 -8
  58. package/dist/types-ts4.5/document/document-service.d.ts +3 -2
  59. package/dist/types-ts4.5/errors/error-code-mapper.d.ts +2 -1
  60. package/dist/types-ts4.5/errors/error-types.d.ts +0 -190
  61. package/dist/types-ts4.5/feature-flags/types.d.ts +1 -0
  62. package/dist/types-ts4.5/helpers/const.d.ts +13 -3
  63. package/dist/types-ts4.5/helpers/socket-message-metrics.d.ts +14 -0
  64. package/dist/types-ts4.5/index.d.ts +3 -3
  65. package/dist/types-ts4.5/metadata/metadata-service.d.ts +1 -1
  66. package/dist/types-ts4.5/participants/participants-helper.d.ts +2 -6
  67. package/dist/types-ts4.5/participants/participants-service.d.ts +3 -2
  68. package/dist/types-ts4.5/participants/participants-state.d.ts +2 -1
  69. package/dist/types-ts4.5/participants/telepointers-helper.d.ts +2 -2
  70. package/dist/types-ts4.5/provider/commit-step.d.ts +2 -1
  71. package/dist/types-ts4.5/provider/index.d.ts +3 -3
  72. package/dist/types-ts4.5/socket-io-provider.d.ts +1 -1
  73. package/dist/types-ts4.5/types.d.ts +2 -149
  74. package/package.json +2 -1
  75. package/report.api.md +49 -390
  76. package/tmp/api-report-tmp.d.ts +257 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/collab-provider
2
2
 
3
+ ## 9.7.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`f9735e0690e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f9735e0690e) - Using socket.onAnyOutgoing to measure and send message metrics
8
+
9
+ ## 9.7.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`14224c3f8a4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/14224c3f8a4) - [ED-18162] Move the collab provider types to the editor common package to avoid circular dependencies
14
+
3
15
  ## 9.7.0
4
16
 
5
17
  ### Minor Changes
@@ -24,6 +24,8 @@ var _ufo = require("./analytics/ufo");
24
24
  var _disconnectedReasonMapper = require("./disconnected-reason-mapper");
25
25
  var _network = _interopRequireDefault(require("./connectivity/network"));
26
26
  var _errorTypes = require("./errors/error-types");
27
+ var _socketMessageMetrics = require("./helpers/socket-message-metrics");
28
+ var _featureFlags = require("./feature-flags");
27
29
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
28
30
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
29
31
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
@@ -125,6 +127,9 @@ var Channel = /*#__PURE__*/function (_Emitter) {
125
127
  });
126
128
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onConnect", function () {
127
129
  var _this$analyticsHelper5;
130
+ if ((0, _featureFlags.getCollabProviderFeatureFlag)('socketMessageMetricsFF', _this.config.featureFlags) && _this.socketMessageMetrics) {
131
+ _this.socketMessageMetrics.setupSocketMessageMetrics();
132
+ }
128
133
  _this.connected = true;
129
134
  logger('Connected.', _this.socket.id);
130
135
  var measure = (0, _performance.stopMeasure)(_performance.MEASURE_NAME.SOCKET_CONNECT, _this.analyticsHelper);
@@ -474,6 +479,9 @@ var Channel = /*#__PURE__*/function (_Emitter) {
474
479
  };
475
480
  }
476
481
  this.socket = createSocket("".concat(url, "/session/").concat(documentAri), auth, this.config.productInfo);
482
+ if (this.socket && this.analyticsHelper) {
483
+ this.socketMessageMetrics = new _socketMessageMetrics.SocketMessageMetrics(this.socket, this.analyticsHelper);
484
+ }
477
485
 
478
486
  // Due to https://github.com/socketio/socket.io-client/issues/1473,
479
487
  // reconnect no longer fired on the socket.
@@ -525,6 +533,9 @@ var Channel = /*#__PURE__*/function (_Emitter) {
525
533
  return _regenerator.default.wrap(function _callee3$(_context3) {
526
534
  while (1) switch (_context3.prev = _context3.next) {
527
535
  case 0:
536
+ if ((0, _featureFlags.getCollabProviderFeatureFlag)('socketMessageMetricsFF', _this2.config.featureFlags) && _this2.socketMessageMetrics) {
537
+ _this2.socketMessageMetrics.closeSocketMessageMetrics();
538
+ }
528
539
  _this2.connected = false;
529
540
  logger("disconnect reason: ".concat(reason));
530
541
  _this2.emit('disconnect', {
@@ -546,7 +557,7 @@ var Channel = /*#__PURE__*/function (_Emitter) {
546
557
  _this2.emit('error', reconnectionError);
547
558
  }
548
559
  }
549
- case 4:
560
+ case 5:
550
561
  case "end":
551
562
  return _context3.stop();
552
563
  }
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.socketIOReasons = exports.disconnectedReasonMapper = exports.DisconnectReason = void 0;
6
+ exports.socketIOReasons = exports.disconnectedReasonMapper = void 0;
7
+ var _collab = require("@atlaskit/editor-common/collab");
7
8
  // See https://socket.io/docs/v3/client-socket-instance#disconnect for emitted reasons
8
9
  var socketIOReasons = {
9
10
  IO_CLIENT_DISCONNECT: 'io client disconnect',
@@ -17,30 +18,20 @@ var socketIOReasons = {
17
18
  PING_TIMEOUT: 'ping timeout' // The connection has encountered an error (example: the server was killed during a HTTP long-polling cycle)
18
19
  };
19
20
  exports.socketIOReasons = socketIOReasons;
20
- var DisconnectReason = /*#__PURE__*/function (DisconnectReason) {
21
- DisconnectReason["CLIENT_DISCONNECT"] = "CLIENT_DISCONNECT";
22
- DisconnectReason["SERVER_DISCONNECT"] = "SERVER_DISCONNECT";
23
- DisconnectReason["SOCKET_CLOSED"] = "SOCKET_CLOSED";
24
- DisconnectReason["SOCKET_ERROR"] = "SOCKET_ERROR";
25
- DisconnectReason["SOCKET_TIMEOUT"] = "SOCKET_TIMEOUT";
26
- DisconnectReason["UNKNOWN_DISCONNECT"] = "UNKNOWN_DISCONNECT";
27
- return DisconnectReason;
28
- }({});
29
- exports.DisconnectReason = DisconnectReason;
30
21
  var disconnectedReasonMapper = function disconnectedReasonMapper(reason) {
31
22
  switch (reason) {
32
23
  case socketIOReasons.IO_CLIENT_DISCONNECT:
33
- return DisconnectReason.CLIENT_DISCONNECT;
24
+ return _collab.DisconnectReason.CLIENT_DISCONNECT;
34
25
  case socketIOReasons.IO_SERVER_DISCONNECT:
35
- return DisconnectReason.SERVER_DISCONNECT;
26
+ return _collab.DisconnectReason.SERVER_DISCONNECT;
36
27
  case socketIOReasons.TRANSPORT_CLOSED:
37
- return DisconnectReason.SOCKET_CLOSED;
28
+ return _collab.DisconnectReason.SOCKET_CLOSED;
38
29
  case socketIOReasons.TRANSPORT_ERROR:
39
- return DisconnectReason.SOCKET_ERROR;
30
+ return _collab.DisconnectReason.SOCKET_ERROR;
40
31
  case socketIOReasons.PING_TIMEOUT:
41
- return DisconnectReason.SOCKET_TIMEOUT;
32
+ return _collab.DisconnectReason.SOCKET_TIMEOUT;
42
33
  default:
43
- return DisconnectReason.UNKNOWN_DISCONNECT;
34
+ return _collab.DisconnectReason.UNKNOWN_DISCONNECT;
44
35
  }
45
36
  };
46
37
  exports.disconnectedReasonMapper = disconnectedReasonMapper;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.errorCodeMapper = void 0;
7
7
  var _errorTypes = require("./error-types");
8
+ var _collab = require("@atlaskit/editor-common/collab");
8
9
  /*
9
10
  * Maps internal collab provider errors to an emitted error format
10
11
  */
@@ -23,7 +24,7 @@ var errorCodeMapper = function errorCodeMapper(error) {
23
24
  case _errorTypes.NCS_ERROR_CODE.INSUFFICIENT_EDITING_PERMISSION:
24
25
  case _errorTypes.INTERNAL_ERROR_CODE.TOKEN_PERMISSION_ERROR:
25
26
  return {
26
- code: _errorTypes.PROVIDER_ERROR_CODE.NO_PERMISSION_ERROR,
27
+ code: _collab.PROVIDER_ERROR_CODE.NO_PERMISSION_ERROR,
27
28
  message: 'User does not have permissions to access this document or document is not found',
28
29
  reason: error.data.meta.reason,
29
30
  recoverable: true,
@@ -31,14 +32,14 @@ var errorCodeMapper = function errorCodeMapper(error) {
31
32
  };
32
33
  case _errorTypes.NCS_ERROR_CODE.FORBIDDEN_USER_TOKEN:
33
34
  return {
34
- code: _errorTypes.PROVIDER_ERROR_CODE.INVALID_USER_TOKEN,
35
+ code: _collab.PROVIDER_ERROR_CODE.INVALID_USER_TOKEN,
35
36
  message: 'The user token was invalid',
36
37
  recoverable: true,
37
38
  status: 403
38
39
  };
39
40
  case _errorTypes.INTERNAL_ERROR_CODE.DOCUMENT_NOT_FOUND:
40
41
  return {
41
- code: _errorTypes.PROVIDER_ERROR_CODE.DOCUMENT_NOT_FOUND,
42
+ code: _collab.PROVIDER_ERROR_CODE.DOCUMENT_NOT_FOUND,
42
43
  message: 'The requested document is not found',
43
44
  recoverable: true,
44
45
  status: 404
@@ -46,41 +47,41 @@ var errorCodeMapper = function errorCodeMapper(error) {
46
47
  case _errorTypes.NCS_ERROR_CODE.TENANT_INSTANCE_MAINTENANCE:
47
48
  case _errorTypes.NCS_ERROR_CODE.LOCKED_DOCUMENT:
48
49
  return {
49
- code: _errorTypes.PROVIDER_ERROR_CODE.LOCKED,
50
+ code: _collab.PROVIDER_ERROR_CODE.LOCKED,
50
51
  message: 'The document is currently not available, please try again later',
51
52
  recoverable: true
52
53
  };
53
54
  case _errorTypes.NCS_ERROR_CODE.DYNAMO_ERROR:
54
55
  return {
55
- code: _errorTypes.PROVIDER_ERROR_CODE.FAIL_TO_SAVE,
56
+ code: _collab.PROVIDER_ERROR_CODE.FAIL_TO_SAVE,
56
57
  message: 'Collab service is not able to save changes',
57
58
  recoverable: false,
58
59
  status: 500
59
60
  };
60
61
  case _errorTypes.INTERNAL_ERROR_CODE.DOCUMENT_RESTORE_ERROR:
61
62
  return {
62
- code: _errorTypes.PROVIDER_ERROR_CODE.DOCUMENT_RESTORE_ERROR,
63
+ code: _collab.PROVIDER_ERROR_CODE.DOCUMENT_RESTORE_ERROR,
63
64
  message: 'Collab service unable to restore document',
64
65
  recoverable: false,
65
66
  status: 500
66
67
  };
67
68
  case _errorTypes.NCS_ERROR_CODE.INIT_DATA_LOAD_FAILED:
68
69
  return {
69
- code: _errorTypes.PROVIDER_ERROR_CODE.INITIALISATION_ERROR,
70
+ code: _collab.PROVIDER_ERROR_CODE.INITIALISATION_ERROR,
70
71
  message: "The initial document couldn't be loaded from the collab service",
71
72
  recoverable: false,
72
73
  status: 500
73
74
  };
74
75
  case _errorTypes.INTERNAL_ERROR_CODE.DOCUMENT_UPDATE_ERROR:
75
76
  return {
76
- code: _errorTypes.PROVIDER_ERROR_CODE.DOCUMENT_UPDATE_ERROR,
77
+ code: _collab.PROVIDER_ERROR_CODE.DOCUMENT_UPDATE_ERROR,
77
78
  message: 'The provider failed to apply changes to the editor',
78
79
  recoverable: false,
79
80
  status: 500
80
81
  };
81
82
  case _errorTypes.INTERNAL_ERROR_CODE.RECONNECTION_NETWORK_ISSUE:
82
83
  return {
83
- code: _errorTypes.PROVIDER_ERROR_CODE.NETWORK_ISSUE,
84
+ code: _collab.PROVIDER_ERROR_CODE.NETWORK_ISSUE,
84
85
  message: "Couldn't reconnect to the collab service due to network issues",
85
86
  recoverable: true,
86
87
  status: 500
@@ -90,7 +91,7 @@ var errorCodeMapper = function errorCodeMapper(error) {
90
91
  case _errorTypes.NCS_ERROR_CODE.INVALID_DOCUMENT_ARI:
91
92
  case _errorTypes.NCS_ERROR_CODE.INVALID_CLOUD_ID:
92
93
  return {
93
- code: _errorTypes.PROVIDER_ERROR_CODE.INVALID_PROVIDER_CONFIGURATION,
94
+ code: _collab.PROVIDER_ERROR_CODE.INVALID_PROVIDER_CONFIGURATION,
94
95
  message: 'Invalid provider configuration',
95
96
  recoverable: false,
96
97
  reason: (_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.code,
@@ -100,7 +101,7 @@ var errorCodeMapper = function errorCodeMapper(error) {
100
101
  case _errorTypes.NCS_ERROR_CODE.ERROR_MAPPING_ERROR:
101
102
  case _errorTypes.NCS_ERROR_CODE.EMPTY_BROADCAST:
102
103
  return {
103
- code: _errorTypes.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
104
+ code: _collab.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
104
105
  message: 'Collab Provider experienced an unrecoverable error',
105
106
  recoverable: false,
106
107
  reason: (_error$data3 = error.data) === null || _error$data3 === void 0 ? void 0 : _error$data3.code,
@@ -108,7 +109,7 @@ var errorCodeMapper = function errorCodeMapper(error) {
108
109
  };
109
110
  case _errorTypes.INTERNAL_ERROR_CODE.CATCHUP_FAILED:
110
111
  return {
111
- code: _errorTypes.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
112
+ code: _collab.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
112
113
  message: 'Collab Provider experienced an unrecoverable error',
113
114
  recoverable: true,
114
115
  reason: (_error$data4 = error.data) === null || _error$data4 === void 0 ? void 0 : _error$data4.code,
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.UpdateDocumentError = exports.SetTitleError = exports.SetMetadataError = exports.SetEditorWidthError = exports.SendTransactionError = exports.ProviderInitialisationError = exports.PROVIDER_ERROR_CODE = exports.NotInitializedError = exports.NotConnectedError = exports.NCS_ERROR_CODE = exports.INTERNAL_ERROR_CODE = exports.GetFinalAcknowledgedStateError = exports.GetCurrentStateError = exports.DestroyError = exports.CustomError = exports.CantSyncUpError = void 0;
7
+ exports.UpdateDocumentError = exports.SetTitleError = exports.SetMetadataError = exports.SetEditorWidthError = exports.SendTransactionError = exports.ProviderInitialisationError = exports.NotInitializedError = exports.NotConnectedError = exports.NCS_ERROR_CODE = exports.INTERNAL_ERROR_CODE = exports.GetFinalAcknowledgedStateError = exports.GetCurrentStateError = exports.DestroyError = exports.CustomError = exports.CantSyncUpError = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
@@ -63,22 +63,6 @@ var NCS_ERROR_CODE = /*#__PURE__*/function (NCS_ERROR_CODE) {
63
63
  /**
64
64
  * A union of all possible internal errors, that are mapped to another error if being emitted to the editor.
65
65
  */
66
- exports.NCS_ERROR_CODE = NCS_ERROR_CODE;
67
- // Emitted errors
68
- var PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
69
- PROVIDER_ERROR_CODE["NO_PERMISSION_ERROR"] = "NO_PERMISSION_ERROR";
70
- PROVIDER_ERROR_CODE["INVALID_USER_TOKEN"] = "INVALID_USER_TOKEN";
71
- PROVIDER_ERROR_CODE["DOCUMENT_NOT_FOUND"] = "DOCUMENT_NOT_FOUND";
72
- PROVIDER_ERROR_CODE["LOCKED"] = "LOCKED";
73
- PROVIDER_ERROR_CODE["FAIL_TO_SAVE"] = "FAIL_TO_SAVE";
74
- PROVIDER_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR";
75
- PROVIDER_ERROR_CODE["INITIALISATION_ERROR"] = "INITIALISATION_ERROR";
76
- PROVIDER_ERROR_CODE["NETWORK_ISSUE"] = "NETWORK_ISSUE";
77
- PROVIDER_ERROR_CODE["INVALID_PROVIDER_CONFIGURATION"] = "INVALID_PROVIDER_CONFIGURATION";
78
- PROVIDER_ERROR_CODE["INTERNAL_SERVICE_ERROR"] = "INTERNAL_SERVICE_ERROR";
79
- PROVIDER_ERROR_CODE["DOCUMENT_UPDATE_ERROR"] = "DOCUMENT_UPDATE_ERROR";
80
- return PROVIDER_ERROR_CODE;
81
- }({});
82
66
  /*
83
67
  * This is what a generic ProviderError type would look like:
84
68
  * type ProviderError = {
@@ -94,84 +78,7 @@ var PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
94
78
  * reason?: string;
95
79
  * }
96
80
  */
97
- /**
98
- * This occurs when the provided user token is considered invalid for the given document ARI.
99
- * It happens during initialisation of the provider.
100
- * It could mean the document has been deleted (hence not found).
101
- * @message Message returned to editor, i.e User does not have permissions to access this document or document is not found
102
- * @recoverable It is recoverable, as we will try to refresh the token.
103
- */
104
- /**
105
- * Similiar to InsufficientEditingPermission, but the user token is invalid because it has expired or been revoked.
106
- * It may also be an invalid token format.
107
- * This error is given to the provider by NCS.
108
- * @message Message returned to editor, i.e. The user token was invalid
109
- * @recoverable It is recoverable, as we will try to refresh the token.
110
- */
111
- /**
112
- * Document not found error, thrown when the provider is unable to find a document with the given ARI and user token.
113
- * It occurs during fetchCatchup, a function that fetches the latest document state during catchup.
114
- * We need to recieve a 404 from the document service to throw this error.
115
- * @message Message returned to editor, i.e. The requested document is not found
116
- * @recoverable It is recoverable, as the provider can try again later.
117
- */
118
- /**
119
- * This error is thrown when the document is locked by another user.
120
- * The error is passed to us by NCS.
121
- * @message Message returned to editor, i.e. The document is currently not available, please try again later
122
- * @recoverable It is recoverable, as the provider can try again later.
123
- */
124
- /**
125
- * This error is thrown when the provider is unable to save the document.
126
- * This can happen when the connection to dynamoDB is lost, or when we do not have sufficient permissions (DYNAMO ERROR).
127
- * This error is given to us by NCS.
128
- * @message Message returned to editor, i.e. Collab service is not able to save changes
129
- * @recoverable It is not recoverable, as we don't want the user to continue editing a document that is not being saved.
130
- */
131
- /**
132
- * This error is thrown when the provider is unable to restore the document.
133
- * It occurs during onRestore, a function that restores the document to a previous version and reapplies unconfirmed steps.
134
- * onRestore is called when page recovery has emitted an 'init' event on a page client is currently connected to.
135
- * It could mean we failed to update the page metadata, or we failed to reapply unconfirmed steps.
136
- * @message Message returned to editor, i.e. Collab service unable to restore document
137
- * @recoverable It is not recoverable, as the provider has no further options after this.
138
- * The user will need to refresh the page to try again.
139
- */
140
- /**
141
- * The initial document couldn't be loaded from the collab service.
142
- * This error is given to us by NCS.
143
- * It could indicate either a network issue, or an internal service error in NCS.
144
- * @message Message returned to editor, i.e. The initial document couldn't be loaded from the collab service
145
- * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
146
- * The user will need to refresh the page to try again.
147
- */
148
- /**
149
- * Couldn't reconnect to the collab service (NCS) due to network issues.
150
- * NCS could be down, or the user could be offline. It's also possible the url is incorrect, or the user is behind a proxy blocking the connection.
151
- * Fired upon a reconnection attempt error (from Socket.IO Manager)
152
- * @message Message returned to editor, i.e. Couldn't reconnect to the collab service due to network issues
153
- * @recoverable It is recoverable, as the provider will try to reconnect.
154
- */
155
- /**
156
- * This error is thrown when the provider has an invalid configuration.
157
- * It could happen due to these errors from NCS:
158
- * NAMESPACE_INVALID
159
- INVALID_ACTIVATION_ID
160
- INVALID_DOCUMENT_ARI
161
- INVALID_CLOUD_ID
162
- * @message Message returned to editor, i.e. Invalid provider configuration
163
- * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
164
- * The service using the provider will need to fix the configuration.
165
- */
166
- /**
167
- * This error is thrown when the provider encounters an internal service error, not otherwise accounted for.
168
- * @message Message returned to editor, i.e. Collab Provider experienced an unrecoverable error
169
- * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
170
- */
171
- /**
172
- * A union of all possible provider errors that can be emitted back to the editor.
173
- */
174
- exports.PROVIDER_ERROR_CODE = PROVIDER_ERROR_CODE;
81
+ exports.NCS_ERROR_CODE = NCS_ERROR_CODE;
175
82
  // Custom Errors
176
83
  var CustomError = /*#__PURE__*/function (_Error) {
177
84
  (0, _inherits2.default)(CustomError, _Error);
@@ -4,9 +4,10 @@ var _index = require("../index");
4
4
  describe('Feature flags', function () {
5
5
  it('getProductSpecificFeatureFlags', function () {
6
6
  var result = (0, _index.getProductSpecificFeatureFlags)({
7
- testFF: true
7
+ testFF: true,
8
+ socketMessageMetricsFF: true
8
9
  }, 'confluence');
9
- expect(result).toEqual(['confluence.fe.collab.provider.testFF']);
10
+ expect(result).toEqual(['confluence.fe.collab.provider.testFF', 'confluence.fe.collab.provider.socketMessageMetricsFF']);
10
11
  });
11
12
  it('getCollabProviderFeatureFlag return true', function () {
12
13
  var result = (0, _index.getCollabProviderFeatureFlag)('testFF', {
@@ -8,7 +8,8 @@ exports.getCollabProviderFeatureFlag = getCollabProviderFeatureFlag;
8
8
  exports.getProductSpecificFeatureFlags = void 0;
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var defaultNCSFeatureFlags = {
11
- testFF: false
11
+ testFF: false,
12
+ socketMessageMetricsFF: false
12
13
  };
13
14
 
14
15
  /**
@@ -16,7 +17,8 @@ var defaultNCSFeatureFlags = {
16
17
  */
17
18
  var productKeys = {
18
19
  confluence: {
19
- testFF: 'confluence.fe.collab.provider.testFF'
20
+ testFF: 'confluence.fe.collab.provider.testFF',
21
+ socketMessageMetricsFF: 'confluence.fe.collab.provider.socketMessageMetricsFF'
20
22
  }
21
23
  };
22
24
  var filterFeatureFlagNames = function filterFeatureFlagNames(flags) {
@@ -19,8 +19,9 @@ var EVENT_ACTION = /*#__PURE__*/function (EVENT_ACTION) {
19
19
  EVENT_ACTION["SEND_STEPS_RETRY"] = "sendStepsRetry";
20
20
  EVENT_ACTION["CATCHUP_AFTER_MAX_SEND_STEPS_RETRY"] = "catchupAfterMaxSendStepsRetry";
21
21
  EVENT_ACTION["DROPPED_STEPS"] = "droppedStepInCatchup";
22
+ EVENT_ACTION["WEBSOCKET_MESSAGE_VOLUME_METRIC"] = "websocketMessageVolumeMetric";
22
23
  return EVENT_ACTION;
23
- }({}); // https://data-portal.internal.atlassian.com/analytics/registry/53724
24
+ }({}); // https://data-portal.internal.atlassian.com/analytics/registry/53596
24
25
  exports.EVENT_ACTION = EVENT_ACTION;
25
26
  var EVENT_STATUS = /*#__PURE__*/function (EVENT_STATUS) {
26
27
  EVENT_STATUS["SUCCESS"] = "SUCCESS";
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.WEBSOCKET_MESSAGE_VOLUME_METRIC_SEND_INTERVAL_MS = exports.SocketMessageMetrics = void 0;
8
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
9
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _const = require("./const");
12
+ var _utils = require("./utils");
13
+ var logger = (0, _utils.createLogger)('SocketMessageMetrics', 'green');
14
+ var WEBSOCKET_MESSAGE_VOLUME_METRIC_SEND_INTERVAL_MS = 60000;
15
+ exports.WEBSOCKET_MESSAGE_VOLUME_METRIC_SEND_INTERVAL_MS = WEBSOCKET_MESSAGE_VOLUME_METRIC_SEND_INTERVAL_MS;
16
+ var SocketMessageMetrics = /*#__PURE__*/(0, _createClass2.default)(function SocketMessageMetrics(socket, analyticsHelper) {
17
+ var _this = this;
18
+ (0, _classCallCheck2.default)(this, SocketMessageMetrics);
19
+ (0, _defineProperty2.default)(this, "messageCount", 0);
20
+ (0, _defineProperty2.default)(this, "totalMessageSize", 0);
21
+ (0, _defineProperty2.default)(this, "metricsIntervalID", undefined);
22
+ (0, _defineProperty2.default)(this, "socketMessageMetricsListener", function (event) {
23
+ _this.messageCount++;
24
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
25
+ args[_key - 1] = arguments[_key];
26
+ }
27
+ _this.totalMessageSize += Buffer.byteLength(JSON.stringify(args), 'utf8');
28
+ });
29
+ (0, _defineProperty2.default)(this, "setupSocketMessageMetrics", function () {
30
+ if (_this.metricsIntervalID !== undefined) {
31
+ logger('calling setupSocketMessageMetrics function with metricsIntervalID that is not undefined');
32
+ return;
33
+ }
34
+ _this.socket.onAnyOutgoing(_this.socketMessageMetricsListener);
35
+
36
+ // send metrics every 60 seconds
37
+ _this.metricsIntervalID = window.setInterval(function () {
38
+ _this.analyticsHelper.sendActionEvent(_const.EVENT_ACTION.WEBSOCKET_MESSAGE_VOLUME_METRIC, _const.EVENT_STATUS.INFO, {
39
+ messageCount: _this.messageCount,
40
+ totalMessageSize: _this.totalMessageSize
41
+ });
42
+ _this.messageCount = 0;
43
+ _this.totalMessageSize = 0;
44
+ }, WEBSOCKET_MESSAGE_VOLUME_METRIC_SEND_INTERVAL_MS);
45
+ });
46
+ (0, _defineProperty2.default)(this, "closeSocketMessageMetrics", function () {
47
+ clearInterval(_this.metricsIntervalID);
48
+ _this.metricsIntervalID = undefined;
49
+ _this.socket.offAnyOutgoing(_this.socketMessageMetricsListener);
50
+ });
51
+ this.socket = socket;
52
+ this.analyticsHelper = analyticsHelper;
53
+ });
54
+ exports.SocketMessageMetrics = SocketMessageMetrics;
package/dist/cjs/index.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "PROVIDER_ERROR_CODE", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _errorTypes.PROVIDER_ERROR_CODE;
9
+ return _collab.PROVIDER_ERROR_CODE;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "Provider", {
@@ -16,4 +16,4 @@ Object.defineProperty(exports, "Provider", {
16
16
  }
17
17
  });
18
18
  var _provider = require("./provider");
19
- var _errorTypes = require("./errors/error-types");
19
+ var _collab = require("@atlaskit/editor-common/collab");
package/dist/cjs/types.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AcknowledgementResponseTypes = void 0;
7
- // types from editor common
7
+ // Re-export values for the /types entry point to this package
8
8
  // types from editor common end
9
9
  // Initial draft
10
10
  // Channel
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = "@atlaskit/collab-provider";
8
8
  exports.name = name;
9
- var version = "9.7.0";
9
+ var version = "9.7.2";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "9.7.0",
3
+ "version": "9.7.2",
4
4
  "sideEffects": false
5
5
  }
@@ -9,6 +9,8 @@ import { createDocInitExp } from './analytics/ufo';
9
9
  import { socketIOReasons } from './disconnected-reason-mapper';
10
10
  import Network from './connectivity/network';
11
11
  import { NotConnectedError, NotInitializedError, INTERNAL_ERROR_CODE } from './errors/error-types';
12
+ import { SocketMessageMetrics } from './helpers/socket-message-metrics';
13
+ import { getCollabProviderFeatureFlag } from './feature-flags';
12
14
  const logger = createLogger('Channel', 'green');
13
15
  export class Channel extends Emitter {
14
16
  constructor(config, analyticsHelper) {
@@ -93,6 +95,9 @@ export class Channel extends Emitter {
93
95
  });
94
96
  _defineProperty(this, "onConnect", () => {
95
97
  var _this$analyticsHelper5;
98
+ if (getCollabProviderFeatureFlag('socketMessageMetricsFF', this.config.featureFlags) && this.socketMessageMetrics) {
99
+ this.socketMessageMetrics.setupSocketMessageMetrics();
100
+ }
96
101
  this.connected = true;
97
102
  logger('Connected.', this.socket.id);
98
103
  const measure = stopMeasure(MEASURE_NAME.SOCKET_CONNECT, this.analyticsHelper);
@@ -350,6 +355,9 @@ export class Channel extends Emitter {
350
355
  };
351
356
  }
352
357
  this.socket = createSocket(`${url}/session/${documentAri}`, auth, this.config.productInfo);
358
+ if (this.socket && this.analyticsHelper) {
359
+ this.socketMessageMetrics = new SocketMessageMetrics(this.socket, this.analyticsHelper);
360
+ }
353
361
 
354
362
  // Due to https://github.com/socketio/socket.io-client/issues/1473,
355
363
  // reconnect no longer fired on the socket.
@@ -400,6 +408,9 @@ export class Channel extends Emitter {
400
408
  this.emit('status', data);
401
409
  });
402
410
  this.socket.on('disconnect', async reason => {
411
+ if (getCollabProviderFeatureFlag('socketMessageMetricsFF', this.config.featureFlags) && this.socketMessageMetrics) {
412
+ this.socketMessageMetrics.closeSocketMessageMetrics();
413
+ }
403
414
  this.connected = false;
404
415
  logger(`disconnect reason: ${reason}`);
405
416
  this.emit('disconnect', {
@@ -1,3 +1,5 @@
1
+ import { DisconnectReason } from '@atlaskit/editor-common/collab';
2
+
1
3
  // See https://socket.io/docs/v3/client-socket-instance#disconnect for emitted reasons
2
4
  export const socketIOReasons = {
3
5
  IO_CLIENT_DISCONNECT: 'io client disconnect',
@@ -11,15 +13,6 @@ export const socketIOReasons = {
11
13
  PING_TIMEOUT: 'ping timeout' // The connection has encountered an error (example: the server was killed during a HTTP long-polling cycle)
12
14
  };
13
15
 
14
- export let DisconnectReason = /*#__PURE__*/function (DisconnectReason) {
15
- DisconnectReason["CLIENT_DISCONNECT"] = "CLIENT_DISCONNECT";
16
- DisconnectReason["SERVER_DISCONNECT"] = "SERVER_DISCONNECT";
17
- DisconnectReason["SOCKET_CLOSED"] = "SOCKET_CLOSED";
18
- DisconnectReason["SOCKET_ERROR"] = "SOCKET_ERROR";
19
- DisconnectReason["SOCKET_TIMEOUT"] = "SOCKET_TIMEOUT";
20
- DisconnectReason["UNKNOWN_DISCONNECT"] = "UNKNOWN_DISCONNECT";
21
- return DisconnectReason;
22
- }({});
23
16
  export const disconnectedReasonMapper = reason => {
24
17
  switch (reason) {
25
18
  case socketIOReasons.IO_CLIENT_DISCONNECT:
@@ -1,5 +1,6 @@
1
1
  import { NCS_ERROR_CODE } from './error-types';
2
- import { INTERNAL_ERROR_CODE, PROVIDER_ERROR_CODE } from './error-types';
2
+ import { INTERNAL_ERROR_CODE } from './error-types';
3
+ import { PROVIDER_ERROR_CODE } from '@atlaskit/editor-common/collab';
3
4
 
4
5
  /*
5
6
  * Maps internal collab provider errors to an emitted error format