@atlaskit/editor-synced-block-provider 2.10.5 → 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 (62) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/clients/block-service/blockService.js +5 -4
  3. package/dist/cjs/clients/confluence/sourceInfo.js +20 -17
  4. package/dist/cjs/hooks/useFetchSyncBlockData.js +20 -11
  5. package/dist/cjs/hooks/useHandleContentChanges.js +1 -5
  6. package/dist/cjs/index.js +2 -2
  7. package/dist/cjs/providers/block-service/blockServiceAPI.js +17 -26
  8. package/dist/cjs/providers/confluence/confluenceContentAPI.js +0 -15
  9. package/dist/cjs/providers/syncBlockProvider.js +31 -41
  10. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +138 -63
  11. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +93 -43
  12. package/dist/cjs/store-manager/syncBlockStoreManager.js +3 -3
  13. package/dist/cjs/utils/errorHandling.js +31 -1
  14. package/dist/es2019/clients/block-service/blockService.js +5 -4
  15. package/dist/es2019/clients/confluence/sourceInfo.js +13 -8
  16. package/dist/es2019/hooks/useFetchSyncBlockData.js +15 -7
  17. package/dist/es2019/hooks/useHandleContentChanges.js +1 -5
  18. package/dist/es2019/index.js +1 -1
  19. package/dist/es2019/providers/block-service/blockServiceAPI.js +13 -20
  20. package/dist/es2019/providers/confluence/confluenceContentAPI.js +1 -14
  21. package/dist/es2019/providers/syncBlockProvider.js +31 -45
  22. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +124 -49
  23. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +65 -24
  24. package/dist/es2019/store-manager/syncBlockStoreManager.js +3 -3
  25. package/dist/es2019/utils/errorHandling.js +17 -1
  26. package/dist/esm/clients/block-service/blockService.js +5 -4
  27. package/dist/esm/clients/confluence/sourceInfo.js +19 -16
  28. package/dist/esm/hooks/useFetchSyncBlockData.js +20 -11
  29. package/dist/esm/hooks/useHandleContentChanges.js +1 -5
  30. package/dist/esm/index.js +1 -1
  31. package/dist/esm/providers/block-service/blockServiceAPI.js +17 -26
  32. package/dist/esm/providers/confluence/confluenceContentAPI.js +1 -16
  33. package/dist/esm/providers/syncBlockProvider.js +32 -42
  34. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +138 -63
  35. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +93 -43
  36. package/dist/esm/store-manager/syncBlockStoreManager.js +3 -3
  37. package/dist/esm/utils/errorHandling.js +30 -0
  38. package/dist/types/clients/block-service/blockService.d.ts +0 -2
  39. package/dist/types/clients/confluence/sourceInfo.d.ts +2 -1
  40. package/dist/types/hooks/useFetchSyncBlockData.d.ts +2 -1
  41. package/dist/types/index.d.ts +2 -2
  42. package/dist/types/providers/block-service/blockServiceAPI.d.ts +7 -5
  43. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -3
  44. package/dist/types/providers/syncBlockProvider.d.ts +12 -9
  45. package/dist/types/providers/types.d.ts +9 -9
  46. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +6 -2
  47. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +3 -1
  48. package/dist/types/store-manager/syncBlockStoreManager.d.ts +2 -1
  49. package/dist/types/utils/errorHandling.d.ts +10 -0
  50. package/dist/types-ts4.5/clients/block-service/blockService.d.ts +0 -2
  51. package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +2 -1
  52. package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +2 -1
  53. package/dist/types-ts4.5/index.d.ts +2 -2
  54. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +7 -5
  55. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -3
  56. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +12 -9
  57. package/dist/types-ts4.5/providers/types.d.ts +9 -9
  58. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +6 -2
  59. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +3 -1
  60. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +2 -1
  61. package/dist/types-ts4.5/utils/errorHandling.d.ts +10 -0
  62. package/package.json +2 -8
@@ -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);
@@ -121,34 +133,54 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
121
133
  return refreshSubscriptions;
122
134
  }())
123
135
  }, {
124
- key: "retrieveSyncBlockSourceInfo",
125
- value: function retrieveSyncBlockSourceInfo(resourceId) {
136
+ key: "fetchSyncBlockSourceInfo",
137
+ value: function fetchSyncBlockSourceInfo(resourceId) {
126
138
  var _this = this;
127
- if (!resourceId || !this.dataProvider) {
128
- return;
129
- }
130
-
131
- // TODO: EDITOR-3312 - retrieve the source info based on the source sync block product
132
-
133
- // if the sync block is a reference block, we need to fetch the URL to the source
134
- // we could optimise this further by checking if the sync block is on the same page as the source
135
- if (!this.syncBlockURLRequests.get(resourceId)) {
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
+ }
136
147
  this.syncBlockURLRequests.set(resourceId, true);
137
- this.dataProvider.retrieveSyncBlockSourceInfo((0, _utils.createSyncBlockNode)('', resourceId)).then(function (sourceInfo) {
138
- var existingSyncBlock = _this.getFromCache(resourceId);
139
- if (existingSyncBlock && existingSyncBlock.data) {
140
- existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
141
- sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
142
- sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
143
- });
144
- _this.updateCache(existingSyncBlock);
145
- if (sourceInfo !== null && sourceInfo !== void 0 && sourceInfo.title) {
146
- _this.updateSourceTitleSubscriptions(existingSyncBlock.resourceId, sourceInfo.title);
147
- }
148
+ var existingSyncBlock = this.getFromCache(resourceId);
149
+ if (!existingSyncBlock) {
150
+ throw new Error('No existing sync block to fetch source info for');
151
+ }
152
+
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) {
155
+ return;
156
+ }
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');
163
+ }
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);
148
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));
149
175
  }).finally(function () {
150
- _this.syncBlockURLRequests.set(resourceId, false);
176
+ _this.syncBlockURLRequests.delete(resourceId);
151
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));
152
184
  }
153
185
  }
154
186
 
@@ -192,19 +224,16 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
192
224
  return this.dataProvider.fetchNodesData(nodesToFetch);
193
225
  case 8:
194
226
  data = _context3.sent;
195
- if (data) {
196
- _context3.next = 11;
197
- break;
198
- }
199
- throw new Error('Failed to fetch sync block node data');
200
- case 11:
201
227
  resolvedData = [];
202
228
  data.forEach(function (syncBlockInstance) {
203
- var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
204
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'));
205
232
  return;
206
233
  }
207
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));
208
237
  _this2.updateCache(syncBlockInstance);
209
238
  resolvedData.push(syncBlockInstance);
210
239
  return;
@@ -213,14 +242,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
213
242
  var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
214
243
  _this2.updateCache(resolvedSyncBlockInstance);
215
244
  resolvedData.push(resolvedSyncBlockInstance);
216
-
217
- // fetch source URL and title if not already present
218
- if ((!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) || !((_resolvedSyncBlockIns2 = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns2 !== void 0 && _resolvedSyncBlockIns2.sourceTitle)) && resolvedSyncBlockInstance.resourceId) {
219
- _this2.retrieveSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
220
- }
245
+ _this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
221
246
  });
222
247
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
223
- case 14:
248
+ case 12:
224
249
  case "end":
225
250
  return _context3.stop();
226
251
  }
@@ -231,6 +256,19 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
231
256
  }
232
257
  return fetchSyncBlocksData;
233
258
  }())
259
+ }, {
260
+ key: "updateCacheWithSourceInfo",
261
+ value: function updateCacheWithSourceInfo(resourceId, sourceInfo) {
262
+ var existingSyncBlock = this.getFromCache(resourceId);
263
+ if (existingSyncBlock && existingSyncBlock.data) {
264
+ existingSyncBlock.data.sourceURL = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
265
+ existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
266
+ sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
267
+ sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
268
+ });
269
+ this.updateCache(existingSyncBlock);
270
+ }
271
+ }
234
272
  }, {
235
273
  key: "updateCache",
236
274
  value: function updateCache(syncBlock) {
@@ -279,7 +317,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
279
317
  if (cachedData) {
280
318
  callback(cachedData);
281
319
  } else {
282
- 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
+ });
283
327
  }
284
328
  return function () {
285
329
  var resourceSubscriptions = _this3.subscriptions.get(resourceId);
@@ -332,17 +376,26 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
332
376
  }, {
333
377
  key: "subscribe",
334
378
  value: function subscribe(node, callback) {
335
- // check node is a sync block, as we only support sync block subscriptions
336
- if (node.type.name !== 'syncBlock') {
337
- return function () {};
338
- }
339
- var _node$attrs2 = node.attrs,
340
- resourceId = _node$attrs2.resourceId,
341
- localId = _node$attrs2.localId;
342
- 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));
343
397
  return function () {};
344
398
  }
345
- return this.subscribeToSyncBlock(resourceId, localId, callback);
346
399
  }
347
400
 
348
401
  /**
@@ -364,6 +417,12 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
364
417
  key: "getProviderFactory",
365
418
  value: function getProviderFactory(resourceId) {
366
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));
367
426
  return undefined;
368
427
  }
369
428
  var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
@@ -379,25 +438,40 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
379
438
  this.providerFactories.set(resourceId, providerFactory);
380
439
  }
381
440
  if (providerCreator) {
382
- 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
+ }
383
450
  }
384
451
  return providerFactory;
385
452
  }
386
453
  }, {
387
454
  key: "retrieveDynamicProviders",
388
455
  value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
456
+ var _syncBlock$data2, _syncBlock$data3, _syncBlock$data4, _syncBlock$data5;
389
457
  if (!this.dataProvider) {
390
- return;
458
+ throw new Error('Data provider not set');
391
459
  }
392
460
  var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
393
461
  var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
394
462
  if (hasMediaProvider && hasEmojiProvider) {
395
463
  return;
396
464
  }
397
- var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
398
- if (!parentInfo) {
465
+ var syncBlock = this.getFromCache(resourceId);
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'));
399
469
  return;
400
470
  }
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);
472
+ if (!parentInfo) {
473
+ throw new Error('Unable to retrive sync block parent info');
474
+ }
401
475
  var contentId = parentInfo.contentId,
402
476
  contentProduct = parentInfo.contentProduct;
403
477
  if (!hasMediaProvider) {
@@ -437,6 +511,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
437
511
  providerFactory.destroy();
438
512
  });
439
513
  this.providerFactories.clear();
514
+ this.fireAnalyticsEvent = undefined;
440
515
  }
441
516
  }]);
442
517
  }();
@@ -11,7 +11,9 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
11
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
13
  var _uuid = _interopRequireDefault(require("uuid"));
14
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
14
15
  var _rebaseTransaction2 = require("../common/rebase-transaction");
16
+ var _errorHandling = require("../utils/errorHandling");
15
17
  var _utils = require("../utils/utils");
16
18
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
17
19
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
@@ -20,7 +22,7 @@ var _utils = require("../utils/utils");
20
22
  // Handles caching, debouncing updates, and publish/subscribe for local changes.
21
23
  // Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
22
24
  var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PURE__*/function () {
23
- function SourceSyncBlockStoreManager(dataProvider) {
25
+ function SourceSyncBlockStoreManager(dataProvider, fireAnalyticsEvent) {
24
26
  var _this = this;
25
27
  (0, _classCallCheck2.default)(this, SourceSyncBlockStoreManager);
26
28
  (0, _defineProperty2.default)(this, "setPendingDeletion", function (Ids, value) {
@@ -31,6 +33,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
31
33
  });
32
34
  this.dataProvider = dataProvider;
33
35
  this.syncBlockCache = new Map();
36
+ this.fireAnalyticsEvent = fireAnalyticsEvent;
34
37
  }
35
38
  return (0, _createClass2.default)(SourceSyncBlockStoreManager, [{
36
39
  key: "isSourceBlock",
@@ -45,18 +48,27 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
45
48
  }, {
46
49
  key: "updateSyncBlockData",
47
50
  value: function updateSyncBlockData(syncBlockNode) {
48
- if (!this.isSourceBlock(syncBlockNode)) {
49
- throw new Error('Invalid sync block node type provided for updateSyncBlockData');
50
- }
51
- var _syncBlockNode$attrs = syncBlockNode.attrs,
52
- localId = _syncBlockNode$attrs.localId,
53
- resourceId = _syncBlockNode$attrs.resourceId;
54
- if (!localId || !resourceId) {
55
- throw new Error('Local ID or resource ID is not set');
51
+ try {
52
+ if (!this.isSourceBlock(syncBlockNode)) {
53
+ throw new Error('Invalid sync block node type provided for updateSyncBlockData');
54
+ }
55
+ var _syncBlockNode$attrs = syncBlockNode.attrs,
56
+ localId = _syncBlockNode$attrs.localId,
57
+ resourceId = _syncBlockNode$attrs.resourceId;
58
+ if (!localId || !resourceId) {
59
+ throw new Error('Local ID or resource ID is not set');
60
+ }
61
+ var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
62
+ this.syncBlockCache.set(resourceId, syncBlockData);
63
+ return true;
64
+ } catch (error) {
65
+ var _this$fireAnalyticsEv;
66
+ (0, _monitoring.logException)(error, {
67
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
68
+ });
69
+ (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, (0, _errorHandling.updateCacheErrorPayload)(error.message));
70
+ return false;
56
71
  }
57
- var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
58
- this.syncBlockCache.set(resourceId, syncBlockData);
59
- return true;
60
72
  }
61
73
 
62
74
  /**
@@ -68,7 +80,8 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
68
80
  key: "flush",
69
81
  value: (function () {
70
82
  var _flush = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
71
- var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults;
83
+ var _this2 = this;
84
+ var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults, _this$fireAnalyticsEv2;
72
85
  return _regenerator.default.wrap(function _callee$(_context) {
73
86
  while (1) switch (_context.prev = _context.next) {
74
87
  case 0:
@@ -104,18 +117,37 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
104
117
  return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
105
118
  case 10:
106
119
  writeResults = _context.sent;
107
- return _context.abrupt("return", writeResults.every(function (result) {
120
+ if (!writeResults.every(function (result) {
108
121
  return result.resourceId !== undefined;
109
- }));
110
- case 14:
111
- _context.prev = 14;
112
- _context.t0 = _context["catch"](0);
122
+ })) {
123
+ _context.next = 15;
124
+ break;
125
+ }
126
+ return _context.abrupt("return", true);
127
+ case 15:
128
+ writeResults.filter(function (result) {
129
+ return result.resourceId === undefined;
130
+ }).forEach(function (result) {
131
+ var _this2$fireAnalyticsE;
132
+ (_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, (0, _errorHandling.updateErrorPayload)(result.error || 'Failed to write data'));
133
+ });
113
134
  return _context.abrupt("return", false);
114
135
  case 17:
136
+ _context.next = 24;
137
+ break;
138
+ case 19:
139
+ _context.prev = 19;
140
+ _context.t0 = _context["catch"](0);
141
+ (0, _monitoring.logException)(_context.t0, {
142
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
143
+ });
144
+ (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, (0, _errorHandling.updateErrorPayload)(_context.t0.message));
145
+ return _context.abrupt("return", false);
146
+ case 24:
115
147
  case "end":
116
148
  return _context.stop();
117
149
  }
118
- }, _callee, this, [[0, 14]]);
150
+ }, _callee, this, [[0, 19]]);
119
151
  }));
120
152
  function flush() {
121
153
  return _flush.apply(this, arguments);
@@ -168,10 +200,10 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
168
200
  }, {
169
201
  key: "registerConfirmationCallback",
170
202
  value: function registerConfirmationCallback(callback) {
171
- var _this2 = this;
203
+ var _this3 = this;
172
204
  this.confirmationCallback = callback;
173
205
  return function () {
174
- _this2.confirmationCallback = undefined;
206
+ _this3.confirmationCallback = undefined;
175
207
  };
176
208
  }
177
209
  }, {
@@ -191,7 +223,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
191
223
  var localId = (0, _uuid.default)();
192
224
  var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
193
225
  if (!this.dataProvider || !sourceId) {
194
- throw new Error('Provider of sync block plugin is not set');
226
+ throw new Error('Data provider not set or source id not set');
195
227
  }
196
228
  var resourceId = this.dataProvider.generateResourceId(sourceId, localId);
197
229
  return {
@@ -207,7 +239,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
207
239
  }, {
208
240
  key: "createBodiedSyncBlockNode",
209
241
  value: function createBodiedSyncBlockNode(attrs) {
210
- var _this3 = this;
242
+ var _this4 = this;
211
243
  try {
212
244
  if (!this.dataProvider) {
213
245
  throw new Error('Data provider not set');
@@ -222,35 +254,44 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
222
254
  results.forEach(function (result) {
223
255
  var resourceId = result.resourceId;
224
256
  if (resourceId) {
225
- _this3.commitPendingCreation(true);
257
+ _this4.commitPendingCreation(true);
226
258
  } else {
227
- _this3.commitPendingCreation(false);
228
- // TODO: EDITOR-1921 - add error analytics
259
+ var _this4$fireAnalyticsE;
260
+ _this4.commitPendingCreation(false);
261
+ (_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, (0, _errorHandling.createErrorPayload)(result.error || 'Failed to create bodied sync block'));
229
262
  }
230
263
  });
231
- }).catch(function (_reason) {
232
- _this3.commitPendingCreation(false);
233
- // TODO: EDITOR-1921 - add error analytics
264
+ }).catch(function (error) {
265
+ var _this4$fireAnalyticsE2;
266
+ _this4.commitPendingCreation(false);
267
+ (0, _monitoring.logException)(error, {
268
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
269
+ });
270
+ (_this4$fireAnalyticsE2 = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE2 === void 0 || _this4$fireAnalyticsE2.call(_this4, (0, _errorHandling.createErrorPayload)(error.message));
234
271
  });
235
272
  this.registerPendingCreation(resourceId);
236
273
  } catch (error) {
274
+ var _this$fireAnalyticsEv3;
237
275
  if (this.hasPendingCreation()) {
238
276
  this.commitPendingCreation(false);
239
277
  }
240
- // TODO: EDITOR-1921 - add error analytics
278
+ (0, _monitoring.logException)(error, {
279
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
280
+ });
281
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, (0, _errorHandling.createErrorPayload)(error.message));
241
282
  }
242
283
  }
243
284
  }, {
244
285
  key: "deleteSyncBlocksWithConfirmation",
245
286
  value: function () {
246
287
  var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(tr, syncBlockIds) {
247
- var _this4 = this;
248
- var confirmed, _this$editorView, results, callback;
288
+ var _this5 = this;
289
+ var confirmed, _this$editorView, results, callback, _this$fireAnalyticsEv4;
249
290
  return _regenerator.default.wrap(function _callee2$(_context2) {
250
291
  while (1) switch (_context2.prev = _context2.next) {
251
292
  case 0:
252
293
  if (!this.confirmationCallback) {
253
- _context2.next = 22;
294
+ _context2.next = 24;
254
295
  break;
255
296
  }
256
297
  this.confirmationTransaction = tr;
@@ -259,7 +300,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
259
300
  case 4:
260
301
  confirmed = _context2.sent;
261
302
  if (!confirmed) {
262
- _context2.next = 21;
303
+ _context2.next = 23;
263
304
  break;
264
305
  }
265
306
  (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
@@ -271,7 +312,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
271
312
  throw new Error('Data provider not set');
272
313
  case 10:
273
314
  syncBlockIds.forEach(function (Ids) {
274
- _this4.setPendingDeletion(Ids, true);
315
+ _this5.setPendingDeletion(Ids, true);
275
316
  });
276
317
  _context2.next = 13;
277
318
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
@@ -283,27 +324,35 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
283
324
  return result.success;
284
325
  })) {
285
326
  callback = function callback(Ids) {
286
- return _this4.syncBlockCache.delete(Ids.resourceId);
327
+ return _this5.syncBlockCache.delete(Ids.resourceId);
287
328
  };
288
329
  } else {
289
330
  callback = function callback(Ids) {
290
- _this4.setPendingDeletion(Ids, false);
331
+ _this5.setPendingDeletion(Ids, false);
291
332
  };
292
- // TODO: EDITOR-1921 - add error analytics
333
+ results.filter(function (result) {
334
+ return result.resourceId === undefined;
335
+ }).forEach(function (result) {
336
+ var _this5$fireAnalyticsE;
337
+ (_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, (0, _errorHandling.deleteErrorPayload)(result.error || 'Failed to delete synced block'));
338
+ });
293
339
  }
294
340
  syncBlockIds.forEach(callback);
295
- _context2.next = 21;
341
+ _context2.next = 23;
296
342
  break;
297
343
  case 18:
298
344
  _context2.prev = 18;
299
345
  _context2.t0 = _context2["catch"](7);
300
346
  syncBlockIds.forEach(function (Ids) {
301
- _this4.setPendingDeletion(Ids, false);
347
+ _this5.setPendingDeletion(Ids, false);
348
+ });
349
+ (0, _monitoring.logException)(_context2.t0, {
350
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
302
351
  });
303
- // TODO: EDITOR-1921 - add error analytics
304
- case 21:
352
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.deleteErrorPayload)(_context2.t0.message));
353
+ case 23:
305
354
  this.confirmationTransaction = undefined;
306
- case 22:
355
+ case 24:
307
356
  case "end":
308
357
  return _context2.stop();
309
358
  }
@@ -332,6 +381,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
332
381
  this.creationCallback = undefined;
333
382
  this.dataProvider = undefined;
334
383
  this.editorView = undefined;
384
+ this.fireAnalyticsEvent = undefined;
335
385
  }
336
386
  }]);
337
387
  }();
@@ -15,12 +15,12 @@ var _sourceSyncBlockStoreManager = require("./sourceSyncBlockStoreManager");
15
15
  // SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
16
16
  // Can be used in both editor and renderer contexts.
17
17
  var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/function () {
18
- function SyncBlockStoreManager(dataProvider) {
18
+ function SyncBlockStoreManager(dataProvider, fireAnalyticsEvent) {
19
19
  (0, _classCallCheck2.default)(this, SyncBlockStoreManager);
20
20
  // In future, if reference manager needs to reach to source manager and read it's current in memorey cache
21
21
  // we can pass the source manager as a parameter to the reference manager constructor
22
- this.sourceSyncBlockStoreManager = new _sourceSyncBlockStoreManager.SourceSyncBlockStoreManager(dataProvider);
23
- this.referenceSyncBlockStoreManager = new _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager(dataProvider);
22
+ this.sourceSyncBlockStoreManager = new _sourceSyncBlockStoreManager.SourceSyncBlockStoreManager(dataProvider, fireAnalyticsEvent);
23
+ this.referenceSyncBlockStoreManager = new _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager(dataProvider, fireAnalyticsEvent);
24
24
  }
25
25
  return (0, _createClass2.default)(SyncBlockStoreManager, [{
26
26
  key: "referenceManager",