@atlaskit/editor-synced-block-provider 2.10.6 → 2.11.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 (52) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/clients/block-service/blockService.js +5 -4
  3. package/dist/cjs/clients/confluence/sourceInfo.js +18 -15
  4. package/dist/cjs/hooks/useFetchSyncBlockData.js +20 -11
  5. package/dist/cjs/hooks/useHandleContentChanges.js +1 -5
  6. package/dist/cjs/providers/block-service/blockServiceAPI.js +17 -12
  7. package/dist/cjs/providers/syncBlockProvider.js +4 -4
  8. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +118 -66
  9. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +93 -43
  10. package/dist/cjs/store-manager/syncBlockStoreManager.js +3 -3
  11. package/dist/cjs/utils/errorHandling.js +31 -1
  12. package/dist/es2019/clients/block-service/blockService.js +5 -4
  13. package/dist/es2019/clients/confluence/sourceInfo.js +13 -8
  14. package/dist/es2019/hooks/useFetchSyncBlockData.js +15 -7
  15. package/dist/es2019/hooks/useHandleContentChanges.js +1 -5
  16. package/dist/es2019/providers/block-service/blockServiceAPI.js +13 -8
  17. package/dist/es2019/providers/syncBlockProvider.js +4 -4
  18. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +105 -51
  19. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +65 -24
  20. package/dist/es2019/store-manager/syncBlockStoreManager.js +3 -3
  21. package/dist/es2019/utils/errorHandling.js +17 -1
  22. package/dist/esm/clients/block-service/blockService.js +5 -4
  23. package/dist/esm/clients/confluence/sourceInfo.js +18 -15
  24. package/dist/esm/hooks/useFetchSyncBlockData.js +20 -11
  25. package/dist/esm/hooks/useHandleContentChanges.js +1 -5
  26. package/dist/esm/providers/block-service/blockServiceAPI.js +17 -12
  27. package/dist/esm/providers/syncBlockProvider.js +4 -4
  28. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +118 -66
  29. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +93 -43
  30. package/dist/esm/store-manager/syncBlockStoreManager.js +3 -3
  31. package/dist/esm/utils/errorHandling.js +30 -0
  32. package/dist/types/clients/block-service/blockService.d.ts +0 -2
  33. package/dist/types/clients/confluence/sourceInfo.d.ts +2 -1
  34. package/dist/types/hooks/useFetchSyncBlockData.d.ts +2 -1
  35. package/dist/types/providers/block-service/blockServiceAPI.d.ts +6 -3
  36. package/dist/types/providers/syncBlockProvider.d.ts +2 -1
  37. package/dist/types/providers/types.d.ts +2 -1
  38. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +4 -1
  39. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +3 -1
  40. package/dist/types/store-manager/syncBlockStoreManager.d.ts +2 -1
  41. package/dist/types/utils/errorHandling.d.ts +10 -0
  42. package/dist/types-ts4.5/clients/block-service/blockService.d.ts +0 -2
  43. package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +2 -1
  44. package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +2 -1
  45. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +6 -3
  46. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -1
  47. package/dist/types-ts4.5/providers/types.d.ts +2 -1
  48. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +4 -1
  49. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +3 -1
  50. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +2 -1
  51. package/dist/types-ts4.5/utils/errorHandling.d.ts +10 -0
  52. package/package.json +2 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 2.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`1ed7afa478690`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1ed7afa478690) -
8
+ Update the blocks endpoint calls to match API design
9
+
10
+ ### Patch Changes
11
+
12
+ - [`0cc1855e9071d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0cc1855e9071d) -
13
+ EDITOR-1921 add analytics for sync block provider failures
14
+ - Updated dependencies
15
+
3
16
  ## 2.10.6
4
17
 
5
18
  ### Patch Changes
@@ -39,7 +39,7 @@ var getSyncedBlockContent = exports.getSyncedBlockContent = /*#__PURE__*/functio
39
39
  case 0:
40
40
  blockAri = _ref.blockAri;
41
41
  _context.next = 3;
42
- return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(blockAri), {
42
+ return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri)), {
43
43
  method: 'GET',
44
44
  headers: COMMON_HEADERS
45
45
  });
@@ -73,7 +73,7 @@ var deleteSyncedBlock = exports.deleteSyncedBlock = /*#__PURE__*/function () {
73
73
  case 0:
74
74
  blockAri = _ref3.blockAri;
75
75
  _context2.next = 3;
76
- return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(blockAri), {
76
+ return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri)), {
77
77
  method: 'DELETE',
78
78
  headers: COMMON_HEADERS
79
79
  });
@@ -102,7 +102,7 @@ var updateSyncedBlock = exports.updateSyncedBlock = /*#__PURE__*/function () {
102
102
  case 0:
103
103
  blockAri = _ref5.blockAri, content = _ref5.content;
104
104
  _context3.next = 3;
105
- return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(blockAri), {
105
+ return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri)), {
106
106
  method: 'PUT',
107
107
  headers: COMMON_HEADERS,
108
108
  body: JSON.stringify({
@@ -134,10 +134,11 @@ var createSyncedBlock = exports.createSyncedBlock = /*#__PURE__*/function () {
134
134
  case 0:
135
135
  blockAri = _ref7.blockAri, blockInstanceId = _ref7.blockInstanceId, sourceAri = _ref7.sourceAri, product = _ref7.product, content = _ref7.content;
136
136
  _context4.next = 3;
137
- return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(blockAri), {
137
+ return fetch("".concat(BLOCK_SERVICE_API_URL, "/block"), {
138
138
  method: 'POST',
139
139
  headers: COMMON_HEADERS,
140
140
  body: JSON.stringify({
141
+ blockAri: blockAri,
141
142
  blockInstanceId: blockInstanceId,
142
143
  sourceAri: sourceAri,
143
144
  product: product,
@@ -8,6 +8,8 @@ exports.fetchConfluencePageInfo = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
12
+ var _errorHandling = require("../../utils/errorHandling");
11
13
  var _ari = require("./ari");
12
14
  var _utils = require("./utils");
13
15
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -69,7 +71,7 @@ var getConfluenceSourceInfo = /*#__PURE__*/function () {
69
71
  };
70
72
  }();
71
73
  var fetchConfluencePageInfo = exports.fetchConfluencePageInfo = /*#__PURE__*/function () {
72
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pageAri, localId) {
74
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pageAri, localId, fireAnalyticsEvent) {
73
75
  var _response$data, _contentData$space, _getPageIdAndTypeFrom, pageType, response, contentData, title, url, _ref3, base;
74
76
  return _regenerator.default.wrap(function _callee2$(_context2) {
75
77
  while (1) switch (_context2.prev = _context2.next) {
@@ -81,15 +83,9 @@ var fetchConfluencePageInfo = exports.fetchConfluencePageInfo = /*#__PURE__*/fun
81
83
  case 4:
82
84
  response = _context2.sent;
83
85
  contentData = (_response$data = response.data) === null || _response$data === void 0 || (_response$data = _response$data.content) === null || _response$data === void 0 || (_response$data = _response$data.nodes) === null || _response$data === void 0 ? void 0 : _response$data[0];
84
- if (contentData) {
85
- _context2.next = 8;
86
- break;
87
- }
88
- throw new Error("Failed to get content data");
89
- case 8:
90
- title = contentData.title;
91
- _ref3 = contentData.links || {}, base = _ref3.base;
92
- if (base && (_contentData$space = contentData.space) !== null && _contentData$space !== void 0 && _contentData$space.key && contentData.id) {
86
+ title = contentData === null || contentData === void 0 ? void 0 : contentData.title;
87
+ _ref3 = (contentData === null || contentData === void 0 ? void 0 : contentData.links) || {}, base = _ref3.base;
88
+ if (base && contentData !== null && contentData !== void 0 && (_contentData$space = contentData.space) !== null && _contentData$space !== void 0 && _contentData$space.key && contentData !== null && contentData !== void 0 && contentData.id) {
93
89
  if ((0, _utils.isBlogPageType)(pageType)) {
94
90
  url = "".concat(base, "/spaces/").concat(contentData.space.key, "/blog/edit-v2/").concat(contentData.id);
95
91
  } else if (contentData.subType === 'live') {
@@ -99,21 +95,28 @@ var fetchConfluencePageInfo = exports.fetchConfluencePageInfo = /*#__PURE__*/fun
99
95
  }
100
96
  }
101
97
  url = url && localId ? "".concat(url, "#block-").concat(localId) : url;
98
+ if (!title || !url) {
99
+ fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 || fireAnalyticsEvent((0, _errorHandling.getSourceInfoErrorPayload)('Failed to get confluence page source info'));
100
+ }
102
101
  return _context2.abrupt("return", Promise.resolve({
103
102
  title: title,
104
103
  url: url
105
104
  }));
106
- case 15:
107
- _context2.prev = 15;
105
+ case 14:
106
+ _context2.prev = 14;
108
107
  _context2.t0 = _context2["catch"](0);
108
+ (0, _monitoring.logException)(_context2.t0, {
109
+ location: 'editor-synced-block-provider/sourceInfo'
110
+ });
111
+ fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 || fireAnalyticsEvent((0, _errorHandling.getSourceInfoErrorPayload)(_context2.t0.message));
109
112
  return _context2.abrupt("return", Promise.resolve(undefined));
110
- case 18:
113
+ case 19:
111
114
  case "end":
112
115
  return _context2.stop();
113
116
  }
114
- }, _callee2, null, [[0, 15]]);
117
+ }, _callee2, null, [[0, 14]]);
115
118
  }));
116
- return function fetchConfluencePageInfo(_x2, _x3) {
119
+ return function fetchConfluencePageInfo(_x2, _x3, _x4) {
117
120
  return _ref2.apply(this, arguments);
118
121
  };
119
122
  }();
@@ -9,9 +9,11 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
  var _react = require("react");
12
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
12
13
  var _types = require("../common/types");
14
+ var _errorHandling = require("../utils/errorHandling");
13
15
  var _utils = require("../utils/utils");
14
- var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId) {
16
+ var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId, fireAnalyticsEvent) {
15
17
  var _useState = (0, _react.useState)(null),
16
18
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
17
19
  syncBlockInstance = _useState2[0],
@@ -31,36 +33,43 @@ var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyn
31
33
  }
32
34
  return _context.abrupt("return");
33
35
  case 2:
36
+ _context.prev = 2;
34
37
  syncBlockNode = resourceId && localId ? (0, _utils.createSyncBlockNode)(localId, resourceId) : null;
35
38
  if (syncBlockNode) {
36
- _context.next = 5;
39
+ _context.next = 6;
37
40
  break;
38
41
  }
39
- return _context.abrupt("return");
40
- case 5:
42
+ throw new Error('Failed to create sync block node from resourceid and localid');
43
+ case 6:
41
44
  setIsLoading(true);
42
- _context.prev = 6;
45
+
46
+ // Fetch sync block data, the `subscribeToSyncBlock` will update the state once data is fetched
43
47
  _context.next = 9;
44
48
  return manager.referenceManager.fetchSyncBlocksData([syncBlockNode]);
45
49
  case 9:
46
- _context.next = 14;
50
+ _context.next = 16;
47
51
  break;
48
52
  case 11:
49
53
  _context.prev = 11;
50
- _context.t0 = _context["catch"](6);
54
+ _context.t0 = _context["catch"](2);
55
+ (0, _monitoring.logException)(_context.t0, {
56
+ location: 'editor-synced-block-provider/useFetchSyncBlockData'
57
+ });
58
+ fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 || fireAnalyticsEvent((0, _errorHandling.fetchErrorPayload)(_context.t0.message));
59
+
51
60
  // Set error state if fetching fails
52
61
  setSyncBlockInstance({
53
62
  resourceId: resourceId || '',
54
63
  error: _types.SyncBlockError.Errored
55
64
  });
56
- case 14:
65
+ case 16:
57
66
  setIsLoading(false);
58
- case 15:
67
+ case 17:
59
68
  case "end":
60
69
  return _context.stop();
61
70
  }
62
- }, _callee, null, [[6, 11]]);
63
- })), [isLoading, localId, manager.referenceManager, resourceId]);
71
+ }, _callee, null, [[2, 11]]);
72
+ })), [isLoading, localId, manager.referenceManager, resourceId, fireAnalyticsEvent]);
64
73
  (0, _react.useEffect)(function () {
65
74
  var unsubscribe = manager.referenceManager.subscribeToSyncBlock(resourceId || '', localId || '', function (data) {
66
75
  setSyncBlockInstance(data);
@@ -7,10 +7,6 @@ exports.useHandleContentChanges = void 0;
7
7
  var _react = require("react");
8
8
  var useHandleContentChanges = exports.useHandleContentChanges = function useHandleContentChanges(manager, syncBlockNode) {
9
9
  (0, _react.useEffect)(function () {
10
- try {
11
- manager.sourceManager.updateSyncBlockData(syncBlockNode);
12
- } catch (_unused) {
13
- //TODO: EDITOR-1921 - add error analytics
14
- }
10
+ manager.sourceManager.updateSyncBlockData(syncBlockNode);
15
11
  }, [manager, syncBlockNode]);
16
12
  };
@@ -102,13 +102,16 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
102
102
  * ADFWriteProvider implementation that writes synced block data to Block Service API
103
103
  */
104
104
  var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
105
- function BlockServiceADFWriteProvider() {
105
+ function BlockServiceADFWriteProvider(sourceAri, product) {
106
106
  (0, _classCallCheck2.default)(this, BlockServiceADFWriteProvider);
107
+ this.sourceAri = sourceAri;
108
+ this.product = product;
107
109
  }
110
+
111
+ // it will first try to update and if it can't (404) then it will try to create
108
112
  return (0, _createClass2.default)(BlockServiceADFWriteProvider, [{
109
113
  key: "writeData",
110
- value: // it will first try to update and if it can't (404) then it will try to create
111
- function () {
114
+ value: function () {
112
115
  var _writeData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(data) {
113
116
  var resourceId;
114
117
  return _regenerator.default.wrap(function _callee2$(_context2) {
@@ -140,8 +143,8 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
140
143
  return (0, _blockService.createSyncedBlock)({
141
144
  blockAri: resourceId,
142
145
  blockInstanceId: data.blockInstanceId,
143
- sourceAri: resourceId,
144
- product: 'confluence-page',
146
+ sourceAri: this.sourceAri,
147
+ product: this.product,
145
148
  content: JSON.stringify(data.content)
146
149
  });
147
150
  case 13:
@@ -161,7 +164,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
161
164
  case "end":
162
165
  return _context2.stop();
163
166
  }
164
- }, _callee2, null, [[1, 7]]);
167
+ }, _callee2, this, [[1, 7]]);
165
168
  }));
166
169
  function writeData(_x2) {
167
170
  return _writeData.apply(this, arguments);
@@ -217,22 +220,24 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
217
220
  }()
218
221
  }, {
219
222
  key: "generateResourceId",
220
- value: function generateResourceId(sourceId, localId) {
221
- return (0, _ari.blockResourceIdFromSourceAndLocalId)(sourceId, localId);
223
+ value: function generateResourceId(sourceAri, localId) {
224
+ return (0, _ari.blockResourceIdFromSourceAndLocalId)(sourceAri, localId);
222
225
  }
223
226
  }]);
224
227
  }();
225
228
  /**
226
229
  * Factory function to create both providers with shared configuration
227
230
  */
228
- var createBlockServiceAPIProviders = function createBlockServiceAPIProviders() {
231
+ var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(sourceAri, product) {
229
232
  var fetchProvider = new BlockServiceADFFetchProvider();
230
- var writeProvider = new BlockServiceADFWriteProvider();
233
+ var writeProvider = new BlockServiceADFWriteProvider(sourceAri, product);
231
234
  return {
232
235
  fetchProvider: fetchProvider,
233
236
  writeProvider: writeProvider
234
237
  };
235
238
  };
236
- var useMemoizedBlockServiceAPIProviders = exports.useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServiceAPIProviders() {
237
- return (0, _react.useMemo)(createBlockServiceAPIProviders, []);
239
+ var useMemoizedBlockServiceAPIProviders = exports.useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServiceAPIProviders(sourceAri, product) {
240
+ return (0, _react.useMemo)(function () {
241
+ return createBlockServiceAPIProviders(sourceAri, product);
242
+ }, [sourceAri, product]);
238
243
  };
@@ -91,7 +91,7 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
91
91
  return data;
92
92
  }, function () {
93
93
  return {
94
- status: _types.SyncBlockError.Errored,
94
+ error: _types.SyncBlockError.Errored,
95
95
  resourceId: resourceId
96
96
  };
97
97
  });
@@ -219,13 +219,13 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
219
219
  */
220
220
  }, {
221
221
  key: "fetchSyncBlockSourceInfo",
222
- value: function fetchSyncBlockSourceInfo(localId, sourceAri, sourceProduct) {
222
+ value: function fetchSyncBlockSourceInfo(localId, sourceAri, sourceProduct, fireAnalyticsEvent) {
223
223
  if (!sourceAri || !sourceProduct) {
224
- return Promise.resolve(undefined);
224
+ return Promise.reject(new Error('Source ari or source product is undefined'));
225
225
  }
226
226
  switch (sourceProduct) {
227
227
  case 'confluence-page':
228
- return (0, _sourceInfo.fetchConfluencePageInfo)(sourceAri, localId);
228
+ return (0, _sourceInfo.fetchConfluencePageInfo)(sourceAri, localId, fireAnalyticsEvent);
229
229
  case 'jira-work-item':
230
230
  return Promise.reject(new Error('Jira work item source product not supported'));
231
231
  default:
@@ -11,8 +11,10 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
11
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
13
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
14
15
  var _providerFactory = require("@atlaskit/editor-common/provider-factory");
15
16
  var _types = require("../common/types");
17
+ var _errorHandling = require("../utils/errorHandling");
16
18
  var _resolveSyncBlockInstance = require("../utils/resolveSyncBlockInstance");
17
19
  var _utils = require("../utils/utils");
18
20
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -26,7 +28,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
26
28
  // Handles fetching source URL and title for sync blocks.
27
29
  // Can be used in both editor and renderer contexts.
28
30
  var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
29
- function ReferenceSyncBlockStoreManager(dataProvider) {
31
+ function ReferenceSyncBlockStoreManager(dataProvider, fireAnalyticsEvent) {
30
32
  (0, _classCallCheck2.default)(this, ReferenceSyncBlockStoreManager);
31
33
  (0, _defineProperty2.default)(this, "isRefreshingSubscriptions", false);
32
34
  this.syncBlockCache = new Map();
@@ -35,17 +37,23 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
35
37
  this.dataProvider = dataProvider;
36
38
  this.syncBlockURLRequests = new Map();
37
39
  this.providerFactories = new Map();
40
+ this.fireAnalyticsEvent = fireAnalyticsEvent;
38
41
  }
39
-
40
- /**
41
- * Refreshes the subscriptions for all sync blocks.
42
- * @returns {Promise<void>}
43
- */
44
42
  return (0, _createClass2.default)(ReferenceSyncBlockStoreManager, [{
43
+ key: "updateFireAnalyticsEvent",
44
+ value: function updateFireAnalyticsEvent(fireAnalyticsEvent) {
45
+ this.fireAnalyticsEvent = fireAnalyticsEvent;
46
+ }
47
+
48
+ /**
49
+ * Refreshes the subscriptions for all sync blocks.
50
+ * @returns {Promise<void>}
51
+ */
52
+ }, {
45
53
  key: "refreshSubscriptions",
46
54
  value: (function () {
47
55
  var _refreshSubscriptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
48
- var syncBlocks, _iterator, _step, _loop;
56
+ var syncBlocks, _iterator, _step, _loop, _this$fireAnalyticsEv;
49
57
  return _regenerator.default.wrap(function _callee$(_context2) {
50
58
  while (1) switch (_context2.prev = _context2.next) {
51
59
  case 0:
@@ -100,20 +108,24 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
100
108
  _context2.next = 23;
101
109
  return this.fetchSyncBlocksData(syncBlocks);
102
110
  case 23:
103
- _context2.next = 27;
111
+ _context2.next = 29;
104
112
  break;
105
113
  case 25:
106
114
  _context2.prev = 25;
107
115
  _context2.t2 = _context2["catch"](20);
108
- case 27:
109
- _context2.prev = 27;
116
+ (0, _monitoring.logException)(_context2.t2, {
117
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
118
+ });
119
+ (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, (0, _errorHandling.fetchErrorPayload)(_context2.t2.message));
120
+ case 29:
121
+ _context2.prev = 29;
110
122
  this.isRefreshingSubscriptions = false;
111
- return _context2.finish(27);
112
- case 30:
123
+ return _context2.finish(29);
124
+ case 32:
113
125
  case "end":
114
126
  return _context2.stop();
115
127
  }
116
- }, _callee, this, [[5, 14, 17, 20], [20, 25, 27, 30]]);
128
+ }, _callee, this, [[5, 14, 17, 20], [20, 25, 29, 32]]);
117
129
  }));
118
130
  function refreshSubscriptions() {
119
131
  return _refreshSubscriptions.apply(this, arguments);
@@ -123,43 +135,53 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
123
135
  }, {
124
136
  key: "fetchSyncBlockSourceInfo",
125
137
  value: function fetchSyncBlockSourceInfo(resourceId) {
126
- var _existingSyncBlock$da,
127
- _existingSyncBlock$da2,
128
- _this = this;
129
- if (!resourceId || !this.dataProvider) {
130
- return;
131
- }
132
- if (this.syncBlockURLRequests.get(resourceId)) {
133
- return;
134
- }
135
- this.syncBlockURLRequests.set(resourceId, true);
136
- var existingSyncBlock = this.getFromCache(resourceId);
137
- if (!existingSyncBlock) {
138
- return;
139
- }
138
+ var _this = this;
139
+ try {
140
+ var _existingSyncBlock$da, _existingSyncBlock$da2;
141
+ if (!resourceId || !this.dataProvider) {
142
+ throw new Error('Data provider or resourceId not set');
143
+ }
144
+ if (this.syncBlockURLRequests.get(resourceId)) {
145
+ return;
146
+ }
147
+ this.syncBlockURLRequests.set(resourceId, true);
148
+ var existingSyncBlock = this.getFromCache(resourceId);
149
+ if (!existingSyncBlock) {
150
+ throw new Error('No existing sync block to fetch source info for');
151
+ }
140
152
 
141
- // skip if source URL and title are already present
142
- if ((_existingSyncBlock$da = existingSyncBlock.data) !== null && _existingSyncBlock$da !== void 0 && _existingSyncBlock$da.sourceURL && (_existingSyncBlock$da2 = existingSyncBlock.data) !== null && _existingSyncBlock$da2 !== void 0 && _existingSyncBlock$da2.sourceTitle) {
143
- return;
144
- }
145
- var _ref = existingSyncBlock.data || {},
146
- sourceAri = _ref.sourceAri,
147
- product = _ref.product,
148
- blockInstanceId = _ref.blockInstanceId;
149
- if (!sourceAri || !product || !blockInstanceId) {
150
- return;
151
- }
152
- this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product).then(function (sourceInfo) {
153
- if (!sourceInfo) {
153
+ // skip if source URL and title are already present
154
+ if ((_existingSyncBlock$da = existingSyncBlock.data) !== null && _existingSyncBlock$da !== void 0 && _existingSyncBlock$da.sourceURL && (_existingSyncBlock$da2 = existingSyncBlock.data) !== null && _existingSyncBlock$da2 !== void 0 && _existingSyncBlock$da2.sourceTitle) {
154
155
  return;
155
156
  }
156
- _this.updateCacheWithSourceInfo(resourceId, sourceInfo);
157
- if (sourceInfo.title) {
158
- _this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
157
+ var _ref = existingSyncBlock.data || {},
158
+ sourceAri = _ref.sourceAri,
159
+ product = _ref.product,
160
+ blockInstanceId = _ref.blockInstanceId;
161
+ if (!sourceAri || !product || !blockInstanceId) {
162
+ throw new Error('SourceAri, product or blockInstanceId missing');
159
163
  }
160
- }).finally(function () {
161
- _this.syncBlockURLRequests.delete(resourceId);
162
- });
164
+ this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(function (sourceInfo) {
165
+ if (!sourceInfo) {
166
+ return;
167
+ }
168
+ _this.updateCacheWithSourceInfo(resourceId, sourceInfo);
169
+ if (sourceInfo.title) {
170
+ _this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
171
+ }
172
+ }).catch(function (error) {
173
+ var _this$fireAnalyticsEv2;
174
+ (_this$fireAnalyticsEv2 = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(_this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message));
175
+ }).finally(function () {
176
+ _this.syncBlockURLRequests.delete(resourceId);
177
+ });
178
+ } catch (error) {
179
+ var _this$fireAnalyticsEv3;
180
+ (0, _monitoring.logException)(error, {
181
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
182
+ });
183
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message));
184
+ }
163
185
  }
164
186
 
165
187
  /**
@@ -202,18 +224,16 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
202
224
  return this.dataProvider.fetchNodesData(nodesToFetch);
203
225
  case 8:
204
226
  data = _context3.sent;
205
- if (data) {
206
- _context3.next = 11;
207
- break;
208
- }
209
- throw new Error('Failed to fetch sync block node data');
210
- case 11:
211
227
  resolvedData = [];
212
228
  data.forEach(function (syncBlockInstance) {
213
229
  if (!syncBlockInstance.resourceId) {
230
+ var _this2$fireAnalyticsE;
231
+ (_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
214
232
  return;
215
233
  }
216
234
  if (syncBlockInstance.error) {
235
+ var _this2$fireAnalyticsE2;
236
+ (_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error));
217
237
  _this2.updateCache(syncBlockInstance);
218
238
  resolvedData.push(syncBlockInstance);
219
239
  return;
@@ -225,7 +245,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
225
245
  _this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
226
246
  });
227
247
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
228
- case 14:
248
+ case 12:
229
249
  case "end":
230
250
  return _context3.stop();
231
251
  }
@@ -297,7 +317,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
297
317
  if (cachedData) {
298
318
  callback(cachedData);
299
319
  } else {
300
- this.fetchSyncBlocksData([(0, _utils.createSyncBlockNode)(localId, resourceId)]).catch(function () {});
320
+ this.fetchSyncBlocksData([(0, _utils.createSyncBlockNode)(localId, resourceId)]).catch(function (error) {
321
+ var _this3$fireAnalyticsE;
322
+ (0, _monitoring.logException)(error, {
323
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
324
+ });
325
+ (_this3$fireAnalyticsE = _this3.fireAnalyticsEvent) === null || _this3$fireAnalyticsE === void 0 || _this3$fireAnalyticsE.call(_this3, (0, _errorHandling.fetchErrorPayload)(error.message));
326
+ });
301
327
  }
302
328
  return function () {
303
329
  var resourceSubscriptions = _this3.subscriptions.get(resourceId);
@@ -350,17 +376,26 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
350
376
  }, {
351
377
  key: "subscribe",
352
378
  value: function subscribe(node, callback) {
353
- // check node is a sync block, as we only support sync block subscriptions
354
- if (node.type.name !== 'syncBlock') {
355
- return function () {};
356
- }
357
- var _node$attrs2 = node.attrs,
358
- resourceId = _node$attrs2.resourceId,
359
- localId = _node$attrs2.localId;
360
- if (!localId || !resourceId) {
379
+ try {
380
+ // check node is a sync block, as we only support sync block subscriptions
381
+ if (node.type.name !== 'syncBlock') {
382
+ throw new Error('Only sync block node subscriptions are supported');
383
+ }
384
+ var _node$attrs2 = node.attrs,
385
+ resourceId = _node$attrs2.resourceId,
386
+ localId = _node$attrs2.localId;
387
+ if (!localId || !resourceId) {
388
+ throw new Error('Missing local id or resource id');
389
+ }
390
+ return this.subscribeToSyncBlock(resourceId, localId, callback);
391
+ } catch (error) {
392
+ var _this$fireAnalyticsEv4;
393
+ (0, _monitoring.logException)(error, {
394
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
395
+ });
396
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
361
397
  return function () {};
362
398
  }
363
- return this.subscribeToSyncBlock(resourceId, localId, callback);
364
399
  }
365
400
 
366
401
  /**
@@ -382,6 +417,12 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
382
417
  key: "getProviderFactory",
383
418
  value: function getProviderFactory(resourceId) {
384
419
  if (!this.dataProvider) {
420
+ var _this$fireAnalyticsEv5;
421
+ var error = new Error('Data provider not set');
422
+ (0, _monitoring.logException)(error, {
423
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
424
+ });
425
+ (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
385
426
  return undefined;
386
427
  }
387
428
  var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
@@ -397,7 +438,15 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
397
438
  this.providerFactories.set(resourceId, providerFactory);
398
439
  }
399
440
  if (providerCreator) {
400
- this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
441
+ try {
442
+ this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
443
+ } catch (error) {
444
+ var _this$fireAnalyticsEv6;
445
+ (0, _monitoring.logException)(error, {
446
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
447
+ });
448
+ (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
449
+ }
401
450
  }
402
451
  return providerFactory;
403
452
  }
@@ -406,7 +455,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
406
455
  value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
407
456
  var _syncBlock$data2, _syncBlock$data3, _syncBlock$data4, _syncBlock$data5;
408
457
  if (!this.dataProvider) {
409
- return;
458
+ throw new Error('Data provider not set');
410
459
  }
411
460
  var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
412
461
  var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
@@ -415,11 +464,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
415
464
  }
416
465
  var syncBlock = this.getFromCache(resourceId);
417
466
  if (!syncBlock || !((_syncBlock$data2 = syncBlock.data) !== null && _syncBlock$data2 !== void 0 && _syncBlock$data2.sourceAri) || !((_syncBlock$data3 = syncBlock.data) !== null && _syncBlock$data3 !== void 0 && _syncBlock$data3.product)) {
467
+ var _this$fireAnalyticsEv7;
468
+ (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, (0, _errorHandling.fetchErrorPayload)('Sync block or source ari or product not found'));
418
469
  return;
419
470
  }
420
471
  var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo((_syncBlock$data4 = syncBlock.data) === null || _syncBlock$data4 === void 0 ? void 0 : _syncBlock$data4.sourceAri, (_syncBlock$data5 = syncBlock.data) === null || _syncBlock$data5 === void 0 ? void 0 : _syncBlock$data5.product);
421
472
  if (!parentInfo) {
422
- return;
473
+ throw new Error('Unable to retrive sync block parent info');
423
474
  }
424
475
  var contentId = parentInfo.contentId,
425
476
  contentProduct = parentInfo.contentProduct;
@@ -460,6 +511,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
460
511
  providerFactory.destroy();
461
512
  });
462
513
  this.providerFactories.clear();
514
+ this.fireAnalyticsEvent = undefined;
463
515
  }
464
516
  }]);
465
517
  }();