@atlaskit/editor-synced-block-provider 2.12.1 → 2.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/providers/block-service/blockServiceAPI.js +70 -37
  3. package/dist/cjs/providers/confluence/confluenceContentAPI.js +80 -42
  4. package/dist/cjs/providers/syncBlockProvider.js +13 -2
  5. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +4 -6
  6. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +10 -12
  7. package/dist/cjs/utils/resolveSyncBlockInstance.js +8 -4
  8. package/dist/cjs/utils/utils.js +1 -10
  9. package/dist/es2019/providers/block-service/blockServiceAPI.js +32 -15
  10. package/dist/es2019/providers/confluence/confluenceContentAPI.js +35 -10
  11. package/dist/es2019/providers/syncBlockProvider.js +5 -0
  12. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +4 -6
  13. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +11 -13
  14. package/dist/es2019/utils/resolveSyncBlockInstance.js +8 -4
  15. package/dist/es2019/utils/utils.js +0 -9
  16. package/dist/esm/providers/block-service/blockServiceAPI.js +70 -37
  17. package/dist/esm/providers/confluence/confluenceContentAPI.js +80 -42
  18. package/dist/esm/providers/syncBlockProvider.js +13 -2
  19. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +4 -6
  20. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +11 -13
  21. package/dist/esm/utils/resolveSyncBlockInstance.js +8 -4
  22. package/dist/esm/utils/utils.js +0 -9
  23. package/dist/types/providers/block-service/blockServiceAPI.d.ts +1 -0
  24. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +1 -0
  25. package/dist/types/providers/syncBlockProvider.d.ts +1 -0
  26. package/dist/types/providers/types.d.ts +2 -0
  27. package/dist/types/utils/utils.d.ts +0 -1
  28. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +1 -0
  29. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +1 -0
  30. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +1 -0
  31. package/dist/types-ts4.5/providers/types.d.ts +2 -0
  32. package/dist/types-ts4.5/utils/utils.d.ts +0 -1
  33. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 2.12.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`fd932d0fad4a5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fd932d0fad4a5) -
8
+ [ux] EDITOR-3693 separate sync block creation and update into different provider calls
9
+ - [`1f90e6ac4a228`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1f90e6ac4a228) -
10
+ [ux] EDITOR-3662 fix sync block error merging logic to retain old information on error
11
+
3
12
  ## 2.12.1
4
13
 
5
14
  ### Patch Changes
@@ -210,88 +210,121 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
210
210
  _context3.prev = 7;
211
211
  _context3.t0 = _context3["catch"](1);
212
212
  if (!(_context3.t0 instanceof _blockService.BlockError)) {
213
- _context3.next = 16;
213
+ _context3.next = 11;
214
214
  break;
215
215
  }
216
- if (!(_context3.t0.status === 404)) {
217
- _context3.next = 15;
218
- break;
219
- }
220
- _context3.next = 13;
221
- return (0, _blockService.createSyncedBlock)({
222
- blockAri: resourceId,
223
- blockInstanceId: data.blockInstanceId,
224
- sourceAri: this.sourceAri,
225
- product: this.product,
226
- content: JSON.stringify(data.content)
227
- });
228
- case 13:
229
- _context3.next = 16;
230
- break;
231
- case 15:
232
216
  return _context3.abrupt("return", {
233
217
  error: mapBlockError(_context3.t0),
234
218
  resourceId: resourceId
235
219
  });
236
- case 16:
220
+ case 11:
237
221
  return _context3.abrupt("return", {
238
222
  error: (0, _errorHandling.stringifyError)(_context3.t0),
239
223
  resourceId: resourceId
240
224
  });
241
- case 17:
225
+ case 12:
242
226
  case "end":
243
227
  return _context3.stop();
244
228
  }
245
- }, _callee3, this, [[1, 7]]);
229
+ }, _callee3, null, [[1, 7]]);
246
230
  }));
247
231
  function writeData(_x3) {
248
232
  return _writeData.apply(this, arguments);
249
233
  }
250
234
  return writeData;
251
- }() // soft deletes the source synced block
235
+ }()
252
236
  }, {
253
- key: "deleteData",
237
+ key: "createData",
254
238
  value: function () {
255
- var _deleteData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(resourceId) {
239
+ var _createData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(data) {
240
+ var resourceId;
256
241
  return _regenerator.default.wrap(function _callee4$(_context4) {
257
242
  while (1) switch (_context4.prev = _context4.next) {
258
243
  case 0:
259
- _context4.prev = 0;
260
- _context4.next = 3;
244
+ resourceId = data.resourceId;
245
+ _context4.prev = 1;
246
+ _context4.next = 4;
247
+ return (0, _blockService.createSyncedBlock)({
248
+ blockAri: resourceId,
249
+ blockInstanceId: data.blockInstanceId,
250
+ sourceAri: this.sourceAri,
251
+ product: this.product,
252
+ content: JSON.stringify(data.content)
253
+ });
254
+ case 4:
255
+ return _context4.abrupt("return", {
256
+ resourceId: resourceId
257
+ });
258
+ case 7:
259
+ _context4.prev = 7;
260
+ _context4.t0 = _context4["catch"](1);
261
+ if (!(_context4.t0 instanceof _blockService.BlockError)) {
262
+ _context4.next = 11;
263
+ break;
264
+ }
265
+ return _context4.abrupt("return", {
266
+ error: mapBlockError(_context4.t0),
267
+ resourceId: resourceId
268
+ });
269
+ case 11:
270
+ return _context4.abrupt("return", {
271
+ error: (0, _errorHandling.stringifyError)(_context4.t0),
272
+ resourceId: resourceId
273
+ });
274
+ case 12:
275
+ case "end":
276
+ return _context4.stop();
277
+ }
278
+ }, _callee4, this, [[1, 7]]);
279
+ }));
280
+ function createData(_x4) {
281
+ return _createData.apply(this, arguments);
282
+ }
283
+ return createData;
284
+ }() // soft deletes the source synced block
285
+ }, {
286
+ key: "deleteData",
287
+ value: function () {
288
+ var _deleteData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(resourceId) {
289
+ return _regenerator.default.wrap(function _callee5$(_context5) {
290
+ while (1) switch (_context5.prev = _context5.next) {
291
+ case 0:
292
+ _context5.prev = 0;
293
+ _context5.next = 3;
261
294
  return (0, _blockService.deleteSyncedBlock)({
262
295
  blockAri: resourceId
263
296
  });
264
297
  case 3:
265
- return _context4.abrupt("return", {
298
+ return _context5.abrupt("return", {
266
299
  resourceId: resourceId,
267
300
  success: true,
268
301
  error: undefined
269
302
  });
270
303
  case 6:
271
- _context4.prev = 6;
272
- _context4.t0 = _context4["catch"](0);
273
- if (!(_context4.t0 instanceof _blockService.BlockError)) {
274
- _context4.next = 10;
304
+ _context5.prev = 6;
305
+ _context5.t0 = _context5["catch"](0);
306
+ if (!(_context5.t0 instanceof _blockService.BlockError)) {
307
+ _context5.next = 10;
275
308
  break;
276
309
  }
277
- return _context4.abrupt("return", {
310
+ return _context5.abrupt("return", {
278
311
  resourceId: resourceId,
279
312
  success: false,
280
- error: mapBlockError(_context4.t0)
313
+ error: mapBlockError(_context5.t0)
281
314
  });
282
315
  case 10:
283
- return _context4.abrupt("return", {
316
+ return _context5.abrupt("return", {
284
317
  resourceId: resourceId,
285
318
  success: false,
286
- error: (0, _errorHandling.stringifyError)(_context4.t0)
319
+ error: (0, _errorHandling.stringifyError)(_context5.t0)
287
320
  });
288
321
  case 11:
289
322
  case "end":
290
- return _context4.stop();
323
+ return _context5.stop();
291
324
  }
292
- }, _callee4, null, [[0, 6]]);
325
+ }, _callee5, null, [[0, 6]]);
293
326
  }));
294
- function deleteData(_x4) {
327
+ function deleteData(_x5) {
295
328
  return _deleteData.apply(this, arguments);
296
329
  }
297
330
  return deleteData;
@@ -260,37 +260,23 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
260
260
  resourceId: resourceId
261
261
  });
262
262
  case 23:
263
- if (updateResult) {
264
- _context3.next = 27;
265
- break;
266
- }
267
- return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType).then(function () {
268
- return {
269
- resourceId: resourceId
270
- };
271
- }, function (error) {
272
- return {
273
- error: error
274
- };
275
- }));
276
- case 27:
277
263
  return _context3.abrupt("return", {
278
264
  error: "Failed to update ".concat(pageType, " content property")
279
265
  });
280
- case 28:
281
- _context3.next = 33;
266
+ case 24:
267
+ _context3.next = 29;
282
268
  break;
283
- case 30:
284
- _context3.prev = 30;
269
+ case 26:
270
+ _context3.prev = 26;
285
271
  _context3.t1 = _context3["catch"](9);
286
272
  return _context3.abrupt("return", {
287
273
  error: "Failed to write ".concat(pageType)
288
274
  });
289
- case 33:
275
+ case 29:
290
276
  case "end":
291
277
  return _context3.stop();
292
278
  }
293
- }, _callee3, this, [[1, 5], [9, 30]]);
279
+ }, _callee3, this, [[1, 5], [9, 26]]);
294
280
  }));
295
281
  function writeData(_x6) {
296
282
  return _writeData.apply(this, arguments);
@@ -298,28 +284,80 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
298
284
  return writeData;
299
285
  }()
300
286
  }, {
301
- key: "deleteData",
287
+ key: "createData",
302
288
  value: function () {
303
- var _deleteData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(resourceId) {
304
- var deletePayload, deleteResult, match, _match2, pageId, pageType, localId, key, options, _stringifyError;
289
+ var _createData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(syncBlockData) {
290
+ var match, resourceId, _match2, pageId, pageType, localId, key, sourceAri, syncBlockDataWithSourceDocumentAri;
305
291
  return _regenerator.default.wrap(function _callee4$(_context4) {
306
292
  while (1) switch (_context4.prev = _context4.next) {
307
293
  case 0:
308
- _context4.prev = 0;
294
+ resourceId = syncBlockData.resourceId;
295
+ _context4.prev = 1;
309
296
  match = (0, _ari.getPageIdAndTypeFromConfluencePageAri)(resourceId);
310
- _context4.next = 7;
297
+ _context4.next = 8;
311
298
  break;
312
- case 4:
313
- _context4.prev = 4;
314
- _context4.t0 = _context4["catch"](0);
299
+ case 5:
300
+ _context4.prev = 5;
301
+ _context4.t0 = _context4["catch"](1);
302
+ return _context4.abrupt("return", {
303
+ error: (0, _errorHandling.stringifyError)(_context4.t0)
304
+ });
305
+ case 8:
306
+ _match2 = match, pageId = _match2.id, pageType = _match2.type;
307
+ _context4.prev = 9;
308
+ localId = (0, _ari.getLocalIdFromConfluencePageAri)(resourceId);
309
+ key = getContentPropertyKey(this.config.contentPropertyKey, localId);
310
+ sourceAri = (0, _ari.getConfluencePageAri)(pageId, this.config.cloudId, pageType);
311
+ syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, syncBlockData), {}, {
312
+ product: 'confluence-page',
313
+ sourceAri: sourceAri
314
+ });
315
+ _context4.next = 16;
316
+ return this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType);
317
+ case 16:
315
318
  return _context4.abrupt("return", {
319
+ resourceId: resourceId
320
+ });
321
+ case 19:
322
+ _context4.prev = 19;
323
+ _context4.t1 = _context4["catch"](9);
324
+ return _context4.abrupt("return", Promise.resolve({
325
+ error: (0, _errorHandling.stringifyError)(_context4.t1)
326
+ }));
327
+ case 22:
328
+ case "end":
329
+ return _context4.stop();
330
+ }
331
+ }, _callee4, this, [[1, 5], [9, 19]]);
332
+ }));
333
+ function createData(_x7) {
334
+ return _createData.apply(this, arguments);
335
+ }
336
+ return createData;
337
+ }()
338
+ }, {
339
+ key: "deleteData",
340
+ value: function () {
341
+ var _deleteData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(resourceId) {
342
+ var deletePayload, deleteResult, match, _match3, pageId, pageType, localId, key, options, _stringifyError;
343
+ return _regenerator.default.wrap(function _callee5$(_context5) {
344
+ while (1) switch (_context5.prev = _context5.next) {
345
+ case 0:
346
+ _context5.prev = 0;
347
+ match = (0, _ari.getPageIdAndTypeFromConfluencePageAri)(resourceId);
348
+ _context5.next = 7;
349
+ break;
350
+ case 4:
351
+ _context5.prev = 4;
352
+ _context5.t0 = _context5["catch"](0);
353
+ return _context5.abrupt("return", {
316
354
  resourceId: resourceId,
317
355
  success: false,
318
- error: (0, _errorHandling.stringifyError)(_context4.t0)
356
+ error: (0, _errorHandling.stringifyError)(_context5.t0)
319
357
  });
320
358
  case 7:
321
- _match2 = match, pageId = _match2.id, pageType = _match2.type;
322
- _context4.prev = 8;
359
+ _match3 = match, pageId = _match3.id, pageType = _match3.type;
360
+ _context5.prev = 8;
323
361
  localId = (0, _ari.getLocalIdFromConfluencePageAri)(resourceId);
324
362
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
325
363
  options = {
@@ -328,34 +366,34 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
328
366
  cloudId: this.config.cloudId,
329
367
  pageType: pageType
330
368
  };
331
- _context4.next = 14;
369
+ _context5.next = 14;
332
370
  return (0, _contentProperty3.deleteContentProperty)(options);
333
371
  case 14:
334
- deletePayload = _context4.sent;
372
+ deletePayload = _context5.sent;
335
373
  deleteResult = (0, _utils.isBlogPageType)(pageType) ? deletePayload.data.confluence.deleteBlogPostProperty : deletePayload.data.confluence.deletePageProperty;
336
- _context4.next = 21;
374
+ _context5.next = 21;
337
375
  break;
338
376
  case 18:
339
- _context4.prev = 18;
340
- _context4.t1 = _context4["catch"](8);
341
- return _context4.abrupt("return", {
377
+ _context5.prev = 18;
378
+ _context5.t1 = _context5["catch"](8);
379
+ return _context5.abrupt("return", {
342
380
  resourceId: resourceId,
343
381
  success: false,
344
- error: (_stringifyError = (0, _errorHandling.stringifyError)(_context4.t1)) !== null && _stringifyError !== void 0 ? _stringifyError : "Fail to delete ".concat(pageType, " content property")
382
+ error: (_stringifyError = (0, _errorHandling.stringifyError)(_context5.t1)) !== null && _stringifyError !== void 0 ? _stringifyError : "Fail to delete ".concat(pageType, " content property")
345
383
  });
346
384
  case 21:
347
- return _context4.abrupt("return", {
385
+ return _context5.abrupt("return", {
348
386
  resourceId: resourceId,
349
387
  success: deleteResult.success,
350
388
  error: deleteResult.errors.join()
351
389
  });
352
390
  case 22:
353
391
  case "end":
354
- return _context4.stop();
392
+ return _context5.stop();
355
393
  }
356
- }, _callee4, this, [[0, 4], [8, 18]]);
394
+ }, _callee5, this, [[0, 4], [8, 18]]);
357
395
  }));
358
- function deleteData(_x7) {
396
+ function deleteData(_x8) {
359
397
  return _deleteData.apply(this, arguments);
360
398
  }
361
399
  return deleteData;
@@ -150,7 +150,19 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
150
150
  return _writeNodesData.apply(this, arguments);
151
151
  }
152
152
  return writeNodesData;
153
- }()
153
+ }())
154
+ }, {
155
+ key: "createNodeData",
156
+ value: function createNodeData(data) {
157
+ return this.writeProvider.createData(data).then(function (result) {
158
+ return result;
159
+ }, function (error) {
160
+ return {
161
+ error: error
162
+ };
163
+ });
164
+ }
165
+
154
166
  /**
155
167
  * Delete the data from the write provider
156
168
  *
@@ -158,7 +170,6 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
158
170
  *
159
171
  * @returns Array of {resourceId?: string, error?: string}.
160
172
  */
161
- )
162
173
  }, {
163
174
  key: "deleteNodesData",
164
175
  value: (function () {
@@ -233,17 +233,15 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
233
233
  (_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'));
234
234
  return;
235
235
  }
236
+ var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
237
+ var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
238
+ _this2.updateCache(resolvedSyncBlockInstance);
239
+ resolvedData.push(resolvedSyncBlockInstance);
236
240
  if (syncBlockInstance.error) {
237
241
  var _this2$fireAnalyticsE2;
238
242
  (_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error));
239
- _this2.updateCache(syncBlockInstance);
240
- resolvedData.push(syncBlockInstance);
241
243
  return;
242
244
  }
243
- var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
244
- var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
245
- _this2.updateCache(resolvedSyncBlockInstance);
246
- resolvedData.push(resolvedSyncBlockInstance);
247
245
  _this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
248
246
  });
249
247
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
@@ -240,21 +240,19 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
240
240
  }
241
241
  var resourceId = attrs.resourceId,
242
242
  blockInstanceId = attrs.localId;
243
- this.dataProvider.writeNodesData([(0, _utils.createBodiedSyncBlockNode)(blockInstanceId, resourceId)], [{
243
+ this.dataProvider.createNodeData({
244
244
  content: [],
245
245
  blockInstanceId: blockInstanceId,
246
246
  resourceId: resourceId
247
- }]).then(function (results) {
248
- results.forEach(function (result) {
249
- var resourceId = result.resourceId;
250
- if (resourceId) {
251
- _this4.commitPendingCreation(true);
252
- } else {
253
- var _this4$fireAnalyticsE;
254
- _this4.commitPendingCreation(false);
255
- (_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, (0, _errorHandling.createErrorPayload)(result.error || 'Failed to create bodied sync block'));
256
- }
257
- });
247
+ }).then(function (result) {
248
+ var resourceId = result.resourceId;
249
+ if (resourceId) {
250
+ _this4.commitPendingCreation(true);
251
+ } else {
252
+ var _this4$fireAnalyticsE;
253
+ _this4.commitPendingCreation(false);
254
+ (_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, (0, _errorHandling.createErrorPayload)(result.error || 'Failed to create bodied sync block'));
255
+ }
258
256
  }).catch(function (error) {
259
257
  var _this4$fireAnalyticsE2;
260
258
  _this4.commitPendingCreation(false);
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.resolveSyncBlockInstance = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _types = require("../common/types");
9
10
  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; }
10
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
12
  /**
@@ -20,13 +21,16 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
20
21
  */
21
22
  var resolveSyncBlockInstance = exports.resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResult, newResult) {
22
23
  var _newResult$data, _oldResult$data, _newResult$data2, _oldResult$data2;
23
- // if the old result has no data, we simple return the new result
24
+ // if the old result has no data, we simply return the new result
24
25
  if (!oldResult.data) {
25
26
  return newResult;
26
27
  } else if (!newResult.data) {
27
- // if the new result has no data, we simply return the old result
28
- // TODO: EDITOR-2533 - handle this case based on the error type and whether we should keep old data or not
29
- return oldResult;
28
+ // return the old result if there was an error, e.g. network error, but not if not found or forbidden
29
+ if (newResult.error === _types.SyncBlockError.Errored) {
30
+ return oldResult;
31
+ } else {
32
+ return newResult;
33
+ }
30
34
  }
31
35
 
32
36
  // otherwise, we merge the two results, preserving the sourceURL and sourceTitle from the old result if it exists
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createSyncBlockNode = exports.createBodiedSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = void 0;
6
+ exports.createSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = void 0;
7
7
  var convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
8
8
  return {
9
9
  blockInstanceId: node.attrs.localId,
@@ -20,15 +20,6 @@ var createSyncBlockNode = exports.createSyncBlockNode = function createSyncBlock
20
20
  }
21
21
  };
22
22
  };
23
- var createBodiedSyncBlockNode = exports.createBodiedSyncBlockNode = function createBodiedSyncBlockNode(localId, resourceId) {
24
- return {
25
- type: 'bodiedSyncBlock',
26
- attrs: {
27
- localId: localId,
28
- resourceId: resourceId
29
- }
30
- };
31
- };
32
23
  var convertSyncBlockJSONNodeToSyncBlockNode = exports.convertSyncBlockJSONNodeToSyncBlockNode = function convertSyncBlockJSONNodeToSyncBlockNode(node) {
33
24
  if (node.type !== 'syncBlock' || !node.attrs || !('localId' in node.attrs) || !('resourceId' in node.attrs) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
34
25
  return undefined;
@@ -138,21 +138,38 @@ class BlockServiceADFWriteProvider {
138
138
  };
139
139
  } catch (error) {
140
140
  if (error instanceof BlockError) {
141
- if (error.status === 404) {
142
- // Create the block
143
- await createSyncedBlock({
144
- blockAri: resourceId,
145
- blockInstanceId: data.blockInstanceId,
146
- sourceAri: this.sourceAri,
147
- product: this.product,
148
- content: JSON.stringify(data.content)
149
- });
150
- } else {
151
- return {
152
- error: mapBlockError(error),
153
- resourceId
154
- };
155
- }
141
+ return {
142
+ error: mapBlockError(error),
143
+ resourceId
144
+ };
145
+ }
146
+ return {
147
+ error: stringifyError(error),
148
+ resourceId
149
+ };
150
+ }
151
+ }
152
+ async createData(data) {
153
+ const {
154
+ resourceId
155
+ } = data;
156
+ try {
157
+ await createSyncedBlock({
158
+ blockAri: resourceId,
159
+ blockInstanceId: data.blockInstanceId,
160
+ sourceAri: this.sourceAri,
161
+ product: this.product,
162
+ content: JSON.stringify(data.content)
163
+ });
164
+ return {
165
+ resourceId
166
+ };
167
+ } catch (error) {
168
+ if (error instanceof BlockError) {
169
+ return {
170
+ error: mapBlockError(error),
171
+ resourceId
172
+ };
156
173
  }
157
174
  return {
158
175
  error: stringifyError(error),
@@ -182,16 +182,6 @@ class ConfluenceADFWriteProvider {
182
182
  return {
183
183
  resourceId
184
184
  };
185
- } else if (!updateResult) {
186
- return this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType).then(() => {
187
- return {
188
- resourceId
189
- };
190
- }, error => {
191
- return {
192
- error
193
- };
194
- });
195
185
  } else {
196
186
  return {
197
187
  error: `Failed to update ${pageType} content property`
@@ -203,6 +193,41 @@ class ConfluenceADFWriteProvider {
203
193
  };
204
194
  }
205
195
  }
196
+ async createData(syncBlockData) {
197
+ let match;
198
+ const {
199
+ resourceId
200
+ } = syncBlockData;
201
+ try {
202
+ match = getPageIdAndTypeFromConfluencePageAri(resourceId);
203
+ } catch (error) {
204
+ return {
205
+ error: stringifyError(error)
206
+ };
207
+ }
208
+ const {
209
+ id: pageId,
210
+ type: pageType
211
+ } = match;
212
+ try {
213
+ const localId = getLocalIdFromConfluencePageAri(resourceId);
214
+ const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
215
+ const sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
216
+ const syncBlockDataWithSourceDocumentAri = {
217
+ ...syncBlockData,
218
+ product: 'confluence-page',
219
+ sourceAri
220
+ };
221
+ await this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType);
222
+ return {
223
+ resourceId
224
+ };
225
+ } catch (error) {
226
+ return Promise.resolve({
227
+ error: stringifyError(error)
228
+ });
229
+ }
230
+ }
206
231
  async deleteData(resourceId) {
207
232
  let deletePayload, deleteResult, match;
208
233
  try {
@@ -98,6 +98,11 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
98
98
  }
99
99
  });
100
100
  }
101
+ createNodeData(data) {
102
+ return this.writeProvider.createData(data).then(result => result, error => ({
103
+ error
104
+ }));
105
+ }
101
106
 
102
107
  /**
103
108
  * Delete the data from the write provider
@@ -139,17 +139,15 @@ export class ReferenceSyncBlockStoreManager {
139
139
  (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
140
140
  return;
141
141
  }
142
+ const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
143
+ const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
144
+ this.updateCache(resolvedSyncBlockInstance);
145
+ resolvedData.push(resolvedSyncBlockInstance);
142
146
  if (syncBlockInstance.error) {
143
147
  var _this$fireAnalyticsEv6;
144
148
  (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, fetchErrorPayload(syncBlockInstance.error));
145
- this.updateCache(syncBlockInstance);
146
- resolvedData.push(syncBlockInstance);
147
149
  return;
148
150
  }
149
- const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
150
- const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
151
- this.updateCache(resolvedSyncBlockInstance);
152
- resolvedData.push(resolvedSyncBlockInstance);
153
151
  this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
154
152
  });
155
153
  return [...resolvedData, ...blocksWithNotFoundError];