@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
@@ -9,8 +9,10 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
9
9
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10
10
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
11
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
+ import { logException } from '@atlaskit/editor-common/monitoring';
12
13
  import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
13
14
  import { SyncBlockError } from '../common/types';
15
+ import { fetchErrorPayload, getSourceInfoErrorPayload } from '../utils/errorHandling';
14
16
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
15
17
  import { createSyncBlockNode } from '../utils/utils';
16
18
 
@@ -20,7 +22,7 @@ import { createSyncBlockNode } from '../utils/utils';
20
22
  // Handles fetching source URL and title for sync blocks.
21
23
  // Can be used in both editor and renderer contexts.
22
24
  export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
23
- function ReferenceSyncBlockStoreManager(dataProvider) {
25
+ function ReferenceSyncBlockStoreManager(dataProvider, fireAnalyticsEvent) {
24
26
  _classCallCheck(this, ReferenceSyncBlockStoreManager);
25
27
  _defineProperty(this, "isRefreshingSubscriptions", false);
26
28
  this.syncBlockCache = new Map();
@@ -29,17 +31,23 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
29
31
  this.dataProvider = dataProvider;
30
32
  this.syncBlockURLRequests = new Map();
31
33
  this.providerFactories = new Map();
34
+ this.fireAnalyticsEvent = fireAnalyticsEvent;
32
35
  }
33
-
34
- /**
35
- * Refreshes the subscriptions for all sync blocks.
36
- * @returns {Promise<void>}
37
- */
38
36
  return _createClass(ReferenceSyncBlockStoreManager, [{
37
+ key: "updateFireAnalyticsEvent",
38
+ value: function updateFireAnalyticsEvent(fireAnalyticsEvent) {
39
+ this.fireAnalyticsEvent = fireAnalyticsEvent;
40
+ }
41
+
42
+ /**
43
+ * Refreshes the subscriptions for all sync blocks.
44
+ * @returns {Promise<void>}
45
+ */
46
+ }, {
39
47
  key: "refreshSubscriptions",
40
48
  value: (function () {
41
49
  var _refreshSubscriptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
42
- var syncBlocks, _iterator, _step, _loop;
50
+ var syncBlocks, _iterator, _step, _loop, _this$fireAnalyticsEv;
43
51
  return _regeneratorRuntime.wrap(function _callee$(_context2) {
44
52
  while (1) switch (_context2.prev = _context2.next) {
45
53
  case 0:
@@ -94,20 +102,24 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
94
102
  _context2.next = 23;
95
103
  return this.fetchSyncBlocksData(syncBlocks);
96
104
  case 23:
97
- _context2.next = 27;
105
+ _context2.next = 29;
98
106
  break;
99
107
  case 25:
100
108
  _context2.prev = 25;
101
109
  _context2.t2 = _context2["catch"](20);
102
- case 27:
103
- _context2.prev = 27;
110
+ logException(_context2.t2, {
111
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
112
+ });
113
+ (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, fetchErrorPayload(_context2.t2.message));
114
+ case 29:
115
+ _context2.prev = 29;
104
116
  this.isRefreshingSubscriptions = false;
105
- return _context2.finish(27);
106
- case 30:
117
+ return _context2.finish(29);
118
+ case 32:
107
119
  case "end":
108
120
  return _context2.stop();
109
121
  }
110
- }, _callee, this, [[5, 14, 17, 20], [20, 25, 27, 30]]);
122
+ }, _callee, this, [[5, 14, 17, 20], [20, 25, 29, 32]]);
111
123
  }));
112
124
  function refreshSubscriptions() {
113
125
  return _refreshSubscriptions.apply(this, arguments);
@@ -115,34 +127,54 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
115
127
  return refreshSubscriptions;
116
128
  }())
117
129
  }, {
118
- key: "retrieveSyncBlockSourceInfo",
119
- value: function retrieveSyncBlockSourceInfo(resourceId) {
130
+ key: "fetchSyncBlockSourceInfo",
131
+ value: function fetchSyncBlockSourceInfo(resourceId) {
120
132
  var _this = this;
121
- if (!resourceId || !this.dataProvider) {
122
- return;
123
- }
124
-
125
- // TODO: EDITOR-3312 - retrieve the source info based on the source sync block product
126
-
127
- // if the sync block is a reference block, we need to fetch the URL to the source
128
- // we could optimise this further by checking if the sync block is on the same page as the source
129
- if (!this.syncBlockURLRequests.get(resourceId)) {
133
+ try {
134
+ var _existingSyncBlock$da, _existingSyncBlock$da2;
135
+ if (!resourceId || !this.dataProvider) {
136
+ throw new Error('Data provider or resourceId not set');
137
+ }
138
+ if (this.syncBlockURLRequests.get(resourceId)) {
139
+ return;
140
+ }
130
141
  this.syncBlockURLRequests.set(resourceId, true);
131
- this.dataProvider.retrieveSyncBlockSourceInfo(createSyncBlockNode('', resourceId)).then(function (sourceInfo) {
132
- var existingSyncBlock = _this.getFromCache(resourceId);
133
- if (existingSyncBlock && existingSyncBlock.data) {
134
- existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
135
- sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
136
- sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
137
- });
138
- _this.updateCache(existingSyncBlock);
139
- if (sourceInfo !== null && sourceInfo !== void 0 && sourceInfo.title) {
140
- _this.updateSourceTitleSubscriptions(existingSyncBlock.resourceId, sourceInfo.title);
141
- }
142
+ var existingSyncBlock = this.getFromCache(resourceId);
143
+ if (!existingSyncBlock) {
144
+ throw new Error('No existing sync block to fetch source info for');
145
+ }
146
+
147
+ // skip if source URL and title are already present
148
+ 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) {
149
+ return;
150
+ }
151
+ var _ref = existingSyncBlock.data || {},
152
+ sourceAri = _ref.sourceAri,
153
+ product = _ref.product,
154
+ blockInstanceId = _ref.blockInstanceId;
155
+ if (!sourceAri || !product || !blockInstanceId) {
156
+ throw new Error('SourceAri, product or blockInstanceId missing');
157
+ }
158
+ this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(function (sourceInfo) {
159
+ if (!sourceInfo) {
160
+ return;
161
+ }
162
+ _this.updateCacheWithSourceInfo(resourceId, sourceInfo);
163
+ if (sourceInfo.title) {
164
+ _this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
142
165
  }
166
+ }).catch(function (error) {
167
+ var _this$fireAnalyticsEv2;
168
+ (_this$fireAnalyticsEv2 = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(_this, getSourceInfoErrorPayload(error.message));
143
169
  }).finally(function () {
144
- _this.syncBlockURLRequests.set(resourceId, false);
170
+ _this.syncBlockURLRequests.delete(resourceId);
145
171
  });
172
+ } catch (error) {
173
+ var _this$fireAnalyticsEv3;
174
+ logException(error, {
175
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
176
+ });
177
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload(error.message));
146
178
  }
147
179
  }
148
180
 
@@ -186,19 +218,16 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
186
218
  return this.dataProvider.fetchNodesData(nodesToFetch);
187
219
  case 8:
188
220
  data = _context3.sent;
189
- if (data) {
190
- _context3.next = 11;
191
- break;
192
- }
193
- throw new Error('Failed to fetch sync block node data');
194
- case 11:
195
221
  resolvedData = [];
196
222
  data.forEach(function (syncBlockInstance) {
197
- var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
198
223
  if (!syncBlockInstance.resourceId) {
224
+ var _this2$fireAnalyticsE;
225
+ (_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
199
226
  return;
200
227
  }
201
228
  if (syncBlockInstance.error) {
229
+ var _this2$fireAnalyticsE2;
230
+ (_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, fetchErrorPayload(syncBlockInstance.error));
202
231
  _this2.updateCache(syncBlockInstance);
203
232
  resolvedData.push(syncBlockInstance);
204
233
  return;
@@ -207,14 +236,10 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
207
236
  var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
208
237
  _this2.updateCache(resolvedSyncBlockInstance);
209
238
  resolvedData.push(resolvedSyncBlockInstance);
210
-
211
- // fetch source URL and title if not already present
212
- if ((!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) || !((_resolvedSyncBlockIns2 = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns2 !== void 0 && _resolvedSyncBlockIns2.sourceTitle)) && resolvedSyncBlockInstance.resourceId) {
213
- _this2.retrieveSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
214
- }
239
+ _this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
215
240
  });
216
241
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
217
- case 14:
242
+ case 12:
218
243
  case "end":
219
244
  return _context3.stop();
220
245
  }
@@ -225,6 +250,19 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
225
250
  }
226
251
  return fetchSyncBlocksData;
227
252
  }())
253
+ }, {
254
+ key: "updateCacheWithSourceInfo",
255
+ value: function updateCacheWithSourceInfo(resourceId, sourceInfo) {
256
+ var existingSyncBlock = this.getFromCache(resourceId);
257
+ if (existingSyncBlock && existingSyncBlock.data) {
258
+ existingSyncBlock.data.sourceURL = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
259
+ existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
260
+ sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
261
+ sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
262
+ });
263
+ this.updateCache(existingSyncBlock);
264
+ }
265
+ }
228
266
  }, {
229
267
  key: "updateCache",
230
268
  value: function updateCache(syncBlock) {
@@ -273,7 +311,13 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
273
311
  if (cachedData) {
274
312
  callback(cachedData);
275
313
  } else {
276
- this.fetchSyncBlocksData([createSyncBlockNode(localId, resourceId)]).catch(function () {});
314
+ this.fetchSyncBlocksData([createSyncBlockNode(localId, resourceId)]).catch(function (error) {
315
+ var _this3$fireAnalyticsE;
316
+ logException(error, {
317
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
318
+ });
319
+ (_this3$fireAnalyticsE = _this3.fireAnalyticsEvent) === null || _this3$fireAnalyticsE === void 0 || _this3$fireAnalyticsE.call(_this3, fetchErrorPayload(error.message));
320
+ });
277
321
  }
278
322
  return function () {
279
323
  var resourceSubscriptions = _this3.subscriptions.get(resourceId);
@@ -326,17 +370,26 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
326
370
  }, {
327
371
  key: "subscribe",
328
372
  value: function subscribe(node, callback) {
329
- // check node is a sync block, as we only support sync block subscriptions
330
- if (node.type.name !== 'syncBlock') {
331
- return function () {};
332
- }
333
- var _node$attrs2 = node.attrs,
334
- resourceId = _node$attrs2.resourceId,
335
- localId = _node$attrs2.localId;
336
- if (!localId || !resourceId) {
373
+ try {
374
+ // check node is a sync block, as we only support sync block subscriptions
375
+ if (node.type.name !== 'syncBlock') {
376
+ throw new Error('Only sync block node subscriptions are supported');
377
+ }
378
+ var _node$attrs2 = node.attrs,
379
+ resourceId = _node$attrs2.resourceId,
380
+ localId = _node$attrs2.localId;
381
+ if (!localId || !resourceId) {
382
+ throw new Error('Missing local id or resource id');
383
+ }
384
+ return this.subscribeToSyncBlock(resourceId, localId, callback);
385
+ } catch (error) {
386
+ var _this$fireAnalyticsEv4;
387
+ logException(error, {
388
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
389
+ });
390
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, fetchErrorPayload(error.message));
337
391
  return function () {};
338
392
  }
339
- return this.subscribeToSyncBlock(resourceId, localId, callback);
340
393
  }
341
394
 
342
395
  /**
@@ -358,6 +411,12 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
358
411
  key: "getProviderFactory",
359
412
  value: function getProviderFactory(resourceId) {
360
413
  if (!this.dataProvider) {
414
+ var _this$fireAnalyticsEv5;
415
+ var error = new Error('Data provider not set');
416
+ logException(error, {
417
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
418
+ });
419
+ (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, fetchErrorPayload(error.message));
361
420
  return undefined;
362
421
  }
363
422
  var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
@@ -373,25 +432,40 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
373
432
  this.providerFactories.set(resourceId, providerFactory);
374
433
  }
375
434
  if (providerCreator) {
376
- this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
435
+ try {
436
+ this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
437
+ } catch (error) {
438
+ var _this$fireAnalyticsEv6;
439
+ logException(error, {
440
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
441
+ });
442
+ (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, fetchErrorPayload(error.message));
443
+ }
377
444
  }
378
445
  return providerFactory;
379
446
  }
380
447
  }, {
381
448
  key: "retrieveDynamicProviders",
382
449
  value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
450
+ var _syncBlock$data2, _syncBlock$data3, _syncBlock$data4, _syncBlock$data5;
383
451
  if (!this.dataProvider) {
384
- return;
452
+ throw new Error('Data provider not set');
385
453
  }
386
454
  var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
387
455
  var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
388
456
  if (hasMediaProvider && hasEmojiProvider) {
389
457
  return;
390
458
  }
391
- var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
392
- if (!parentInfo) {
459
+ var syncBlock = this.getFromCache(resourceId);
460
+ 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)) {
461
+ var _this$fireAnalyticsEv7;
462
+ (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, fetchErrorPayload('Sync block or source ari or product not found'));
393
463
  return;
394
464
  }
465
+ 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);
466
+ if (!parentInfo) {
467
+ throw new Error('Unable to retrive sync block parent info');
468
+ }
395
469
  var contentId = parentInfo.contentId,
396
470
  contentProduct = parentInfo.contentProduct;
397
471
  if (!hasMediaProvider) {
@@ -431,6 +505,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
431
505
  providerFactory.destroy();
432
506
  });
433
507
  this.providerFactories.clear();
508
+ this.fireAnalyticsEvent = undefined;
434
509
  }
435
510
  }]);
436
511
  }();
@@ -5,7 +5,9 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
7
7
  import uuid from 'uuid';
8
+ import { logException } from '@atlaskit/editor-common/monitoring';
8
9
  import { rebaseTransaction as _rebaseTransaction } from '../common/rebase-transaction';
10
+ import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
9
11
  import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _createBodiedSyncBlockNode } from '../utils/utils';
10
12
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
11
13
  // Designed to manage local in-memory state and synchronize with an external data provider.
@@ -13,7 +15,7 @@ import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _cr
13
15
  // Handles caching, debouncing updates, and publish/subscribe for local changes.
14
16
  // Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
15
17
  export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
16
- function SourceSyncBlockStoreManager(dataProvider) {
18
+ function SourceSyncBlockStoreManager(dataProvider, fireAnalyticsEvent) {
17
19
  var _this = this;
18
20
  _classCallCheck(this, SourceSyncBlockStoreManager);
19
21
  _defineProperty(this, "setPendingDeletion", function (Ids, value) {
@@ -24,6 +26,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
24
26
  });
25
27
  this.dataProvider = dataProvider;
26
28
  this.syncBlockCache = new Map();
29
+ this.fireAnalyticsEvent = fireAnalyticsEvent;
27
30
  }
28
31
  return _createClass(SourceSyncBlockStoreManager, [{
29
32
  key: "isSourceBlock",
@@ -38,18 +41,27 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
38
41
  }, {
39
42
  key: "updateSyncBlockData",
40
43
  value: function updateSyncBlockData(syncBlockNode) {
41
- if (!this.isSourceBlock(syncBlockNode)) {
42
- throw new Error('Invalid sync block node type provided for updateSyncBlockData');
43
- }
44
- var _syncBlockNode$attrs = syncBlockNode.attrs,
45
- localId = _syncBlockNode$attrs.localId,
46
- resourceId = _syncBlockNode$attrs.resourceId;
47
- if (!localId || !resourceId) {
48
- throw new Error('Local ID or resource ID is not set');
44
+ try {
45
+ if (!this.isSourceBlock(syncBlockNode)) {
46
+ throw new Error('Invalid sync block node type provided for updateSyncBlockData');
47
+ }
48
+ var _syncBlockNode$attrs = syncBlockNode.attrs,
49
+ localId = _syncBlockNode$attrs.localId,
50
+ resourceId = _syncBlockNode$attrs.resourceId;
51
+ if (!localId || !resourceId) {
52
+ throw new Error('Local ID or resource ID is not set');
53
+ }
54
+ var syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
55
+ this.syncBlockCache.set(resourceId, syncBlockData);
56
+ return true;
57
+ } catch (error) {
58
+ var _this$fireAnalyticsEv;
59
+ logException(error, {
60
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
61
+ });
62
+ (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, updateCacheErrorPayload(error.message));
63
+ return false;
49
64
  }
50
- var syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
51
- this.syncBlockCache.set(resourceId, syncBlockData);
52
- return true;
53
65
  }
54
66
 
55
67
  /**
@@ -61,7 +73,8 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
61
73
  key: "flush",
62
74
  value: (function () {
63
75
  var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
64
- var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults;
76
+ var _this2 = this;
77
+ var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults, _this$fireAnalyticsEv2;
65
78
  return _regeneratorRuntime.wrap(function _callee$(_context) {
66
79
  while (1) switch (_context.prev = _context.next) {
67
80
  case 0:
@@ -97,18 +110,37 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
97
110
  return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
98
111
  case 10:
99
112
  writeResults = _context.sent;
100
- return _context.abrupt("return", writeResults.every(function (result) {
113
+ if (!writeResults.every(function (result) {
101
114
  return result.resourceId !== undefined;
102
- }));
103
- case 14:
104
- _context.prev = 14;
105
- _context.t0 = _context["catch"](0);
115
+ })) {
116
+ _context.next = 15;
117
+ break;
118
+ }
119
+ return _context.abrupt("return", true);
120
+ case 15:
121
+ writeResults.filter(function (result) {
122
+ return result.resourceId === undefined;
123
+ }).forEach(function (result) {
124
+ var _this2$fireAnalyticsE;
125
+ (_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, updateErrorPayload(result.error || 'Failed to write data'));
126
+ });
106
127
  return _context.abrupt("return", false);
107
128
  case 17:
129
+ _context.next = 24;
130
+ break;
131
+ case 19:
132
+ _context.prev = 19;
133
+ _context.t0 = _context["catch"](0);
134
+ logException(_context.t0, {
135
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
136
+ });
137
+ (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, updateErrorPayload(_context.t0.message));
138
+ return _context.abrupt("return", false);
139
+ case 24:
108
140
  case "end":
109
141
  return _context.stop();
110
142
  }
111
- }, _callee, this, [[0, 14]]);
143
+ }, _callee, this, [[0, 19]]);
112
144
  }));
113
145
  function flush() {
114
146
  return _flush.apply(this, arguments);
@@ -161,10 +193,10 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
161
193
  }, {
162
194
  key: "registerConfirmationCallback",
163
195
  value: function registerConfirmationCallback(callback) {
164
- var _this2 = this;
196
+ var _this3 = this;
165
197
  this.confirmationCallback = callback;
166
198
  return function () {
167
- _this2.confirmationCallback = undefined;
199
+ _this3.confirmationCallback = undefined;
168
200
  };
169
201
  }
170
202
  }, {
@@ -184,7 +216,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
184
216
  var localId = uuid();
185
217
  var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
186
218
  if (!this.dataProvider || !sourceId) {
187
- throw new Error('Provider of sync block plugin is not set');
219
+ throw new Error('Data provider not set or source id not set');
188
220
  }
189
221
  var resourceId = this.dataProvider.generateResourceId(sourceId, localId);
190
222
  return {
@@ -200,7 +232,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
200
232
  }, {
201
233
  key: "createBodiedSyncBlockNode",
202
234
  value: function createBodiedSyncBlockNode(attrs) {
203
- var _this3 = this;
235
+ var _this4 = this;
204
236
  try {
205
237
  if (!this.dataProvider) {
206
238
  throw new Error('Data provider not set');
@@ -215,35 +247,44 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
215
247
  results.forEach(function (result) {
216
248
  var resourceId = result.resourceId;
217
249
  if (resourceId) {
218
- _this3.commitPendingCreation(true);
250
+ _this4.commitPendingCreation(true);
219
251
  } else {
220
- _this3.commitPendingCreation(false);
221
- // TODO: EDITOR-1921 - add error analytics
252
+ var _this4$fireAnalyticsE;
253
+ _this4.commitPendingCreation(false);
254
+ (_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, createErrorPayload(result.error || 'Failed to create bodied sync block'));
222
255
  }
223
256
  });
224
- }).catch(function (_reason) {
225
- _this3.commitPendingCreation(false);
226
- // TODO: EDITOR-1921 - add error analytics
257
+ }).catch(function (error) {
258
+ var _this4$fireAnalyticsE2;
259
+ _this4.commitPendingCreation(false);
260
+ logException(error, {
261
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
262
+ });
263
+ (_this4$fireAnalyticsE2 = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE2 === void 0 || _this4$fireAnalyticsE2.call(_this4, createErrorPayload(error.message));
227
264
  });
228
265
  this.registerPendingCreation(resourceId);
229
266
  } catch (error) {
267
+ var _this$fireAnalyticsEv3;
230
268
  if (this.hasPendingCreation()) {
231
269
  this.commitPendingCreation(false);
232
270
  }
233
- // TODO: EDITOR-1921 - add error analytics
271
+ logException(error, {
272
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
273
+ });
274
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, createErrorPayload(error.message));
234
275
  }
235
276
  }
236
277
  }, {
237
278
  key: "deleteSyncBlocksWithConfirmation",
238
279
  value: function () {
239
280
  var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tr, syncBlockIds) {
240
- var _this4 = this;
241
- var confirmed, _this$editorView, results, callback;
281
+ var _this5 = this;
282
+ var confirmed, _this$editorView, results, callback, _this$fireAnalyticsEv4;
242
283
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
243
284
  while (1) switch (_context2.prev = _context2.next) {
244
285
  case 0:
245
286
  if (!this.confirmationCallback) {
246
- _context2.next = 22;
287
+ _context2.next = 24;
247
288
  break;
248
289
  }
249
290
  this.confirmationTransaction = tr;
@@ -252,7 +293,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
252
293
  case 4:
253
294
  confirmed = _context2.sent;
254
295
  if (!confirmed) {
255
- _context2.next = 21;
296
+ _context2.next = 23;
256
297
  break;
257
298
  }
258
299
  (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
@@ -264,7 +305,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
264
305
  throw new Error('Data provider not set');
265
306
  case 10:
266
307
  syncBlockIds.forEach(function (Ids) {
267
- _this4.setPendingDeletion(Ids, true);
308
+ _this5.setPendingDeletion(Ids, true);
268
309
  });
269
310
  _context2.next = 13;
270
311
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
@@ -276,27 +317,35 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
276
317
  return result.success;
277
318
  })) {
278
319
  callback = function callback(Ids) {
279
- return _this4.syncBlockCache.delete(Ids.resourceId);
320
+ return _this5.syncBlockCache.delete(Ids.resourceId);
280
321
  };
281
322
  } else {
282
323
  callback = function callback(Ids) {
283
- _this4.setPendingDeletion(Ids, false);
324
+ _this5.setPendingDeletion(Ids, false);
284
325
  };
285
- // TODO: EDITOR-1921 - add error analytics
326
+ results.filter(function (result) {
327
+ return result.resourceId === undefined;
328
+ }).forEach(function (result) {
329
+ var _this5$fireAnalyticsE;
330
+ (_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, deleteErrorPayload(result.error || 'Failed to delete synced block'));
331
+ });
286
332
  }
287
333
  syncBlockIds.forEach(callback);
288
- _context2.next = 21;
334
+ _context2.next = 23;
289
335
  break;
290
336
  case 18:
291
337
  _context2.prev = 18;
292
338
  _context2.t0 = _context2["catch"](7);
293
339
  syncBlockIds.forEach(function (Ids) {
294
- _this4.setPendingDeletion(Ids, false);
340
+ _this5.setPendingDeletion(Ids, false);
341
+ });
342
+ logException(_context2.t0, {
343
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
295
344
  });
296
- // TODO: EDITOR-1921 - add error analytics
297
- case 21:
345
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, deleteErrorPayload(_context2.t0.message));
346
+ case 23:
298
347
  this.confirmationTransaction = undefined;
299
- case 22:
348
+ case 24:
300
349
  case "end":
301
350
  return _context2.stop();
302
351
  }
@@ -325,6 +374,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
325
374
  this.creationCallback = undefined;
326
375
  this.dataProvider = undefined;
327
376
  this.editorView = undefined;
377
+ this.fireAnalyticsEvent = undefined;
328
378
  }
329
379
  }]);
330
380
  }();
@@ -9,12 +9,12 @@ import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
9
9
  // SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
10
10
  // Can be used in both editor and renderer contexts.
11
11
  export var SyncBlockStoreManager = /*#__PURE__*/function () {
12
- function SyncBlockStoreManager(dataProvider) {
12
+ function SyncBlockStoreManager(dataProvider, fireAnalyticsEvent) {
13
13
  _classCallCheck(this, SyncBlockStoreManager);
14
14
  // In future, if reference manager needs to reach to source manager and read it's current in memorey cache
15
15
  // we can pass the source manager as a parameter to the reference manager constructor
16
- this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider);
17
- this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider);
16
+ this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider, fireAnalyticsEvent);
17
+ this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider, fireAnalyticsEvent);
18
18
  }
19
19
  return _createClass(SyncBlockStoreManager, [{
20
20
  key: "referenceManager",