@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
@@ -3,7 +3,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import uuid from 'uuid';
4
4
  import { logException } from '@atlaskit/editor-common/monitoring';
5
5
  import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
6
- import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode } from '../utils/utils';
6
+ import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
7
7
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
8
8
  // Designed to manage local in-memory state and synchronize with an external data provider.
9
9
  // Supports create, flush, and delete operations for source sync blocks.
@@ -172,21 +172,19 @@ export class SourceSyncBlockStoreManager {
172
172
  resourceId,
173
173
  localId: blockInstanceId
174
174
  } = attrs;
175
- this.dataProvider.writeNodesData([createBodiedSyncBlockNode(blockInstanceId, resourceId)], [{
175
+ this.dataProvider.createNodeData({
176
176
  content: [],
177
177
  blockInstanceId,
178
178
  resourceId: resourceId
179
- }]).then(results => {
180
- results.forEach(result => {
181
- const resourceId = result.resourceId;
182
- if (resourceId) {
183
- this.commitPendingCreation(true);
184
- } else {
185
- var _this$fireAnalyticsEv4;
186
- this.commitPendingCreation(false);
187
- (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 ? void 0 : _this$fireAnalyticsEv4.call(this, createErrorPayload(result.error || 'Failed to create bodied sync block'));
188
- }
189
- });
179
+ }).then(result => {
180
+ const resourceId = result.resourceId;
181
+ if (resourceId) {
182
+ this.commitPendingCreation(true);
183
+ } else {
184
+ var _this$fireAnalyticsEv4;
185
+ this.commitPendingCreation(false);
186
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 ? void 0 : _this$fireAnalyticsEv4.call(this, createErrorPayload(result.error || 'Failed to create bodied sync block'));
187
+ }
190
188
  }).catch(error => {
191
189
  var _this$fireAnalyticsEv5;
192
190
  this.commitPendingCreation(false);
@@ -1,3 +1,4 @@
1
+ import { SyncBlockError } from '../common/types';
1
2
  /**
2
3
  * Merges two SyncBlockInstance objects,
3
4
  * currently it only preserves the sourceURL from the old result,
@@ -10,13 +11,16 @@
10
11
  */
11
12
  export const resolveSyncBlockInstance = (oldResult, newResult) => {
12
13
  var _newResult$data, _oldResult$data, _newResult$data2, _oldResult$data2;
13
- // if the old result has no data, we simple return the new result
14
+ // if the old result has no data, we simply return the new result
14
15
  if (!oldResult.data) {
15
16
  return newResult;
16
17
  } else if (!newResult.data) {
17
- // if the new result has no data, we simply return the old result
18
- // TODO: EDITOR-2533 - handle this case based on the error type and whether we should keep old data or not
19
- return oldResult;
18
+ // return the old result if there was an error, e.g. network error, but not if not found or forbidden
19
+ if (newResult.error === SyncBlockError.Errored) {
20
+ return oldResult;
21
+ } else {
22
+ return newResult;
23
+ }
20
24
  }
21
25
 
22
26
  // otherwise, we merge the two results, preserving the sourceURL and sourceTitle from the old result if it exists
@@ -14,15 +14,6 @@ export const createSyncBlockNode = (localId, resourceId) => {
14
14
  }
15
15
  };
16
16
  };
17
- export const createBodiedSyncBlockNode = (localId, resourceId) => {
18
- return {
19
- type: 'bodiedSyncBlock',
20
- attrs: {
21
- localId,
22
- resourceId
23
- }
24
- };
25
- };
26
17
  export const convertSyncBlockJSONNodeToSyncBlockNode = node => {
27
18
  if (node.type !== 'syncBlock' || !node.attrs || !('localId' in node.attrs) || !('resourceId' in node.attrs) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
28
19
  return undefined;
@@ -203,88 +203,121 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
203
203
  _context3.prev = 7;
204
204
  _context3.t0 = _context3["catch"](1);
205
205
  if (!(_context3.t0 instanceof BlockError)) {
206
- _context3.next = 16;
206
+ _context3.next = 11;
207
207
  break;
208
208
  }
209
- if (!(_context3.t0.status === 404)) {
210
- _context3.next = 15;
211
- break;
212
- }
213
- _context3.next = 13;
214
- return createSyncedBlock({
215
- blockAri: resourceId,
216
- blockInstanceId: data.blockInstanceId,
217
- sourceAri: this.sourceAri,
218
- product: this.product,
219
- content: JSON.stringify(data.content)
220
- });
221
- case 13:
222
- _context3.next = 16;
223
- break;
224
- case 15:
225
209
  return _context3.abrupt("return", {
226
210
  error: mapBlockError(_context3.t0),
227
211
  resourceId: resourceId
228
212
  });
229
- case 16:
213
+ case 11:
230
214
  return _context3.abrupt("return", {
231
215
  error: stringifyError(_context3.t0),
232
216
  resourceId: resourceId
233
217
  });
234
- case 17:
218
+ case 12:
235
219
  case "end":
236
220
  return _context3.stop();
237
221
  }
238
- }, _callee3, this, [[1, 7]]);
222
+ }, _callee3, null, [[1, 7]]);
239
223
  }));
240
224
  function writeData(_x3) {
241
225
  return _writeData.apply(this, arguments);
242
226
  }
243
227
  return writeData;
244
- }() // soft deletes the source synced block
228
+ }()
245
229
  }, {
246
- key: "deleteData",
230
+ key: "createData",
247
231
  value: function () {
248
- var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(resourceId) {
232
+ var _createData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(data) {
233
+ var resourceId;
249
234
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
250
235
  while (1) switch (_context4.prev = _context4.next) {
251
236
  case 0:
252
- _context4.prev = 0;
253
- _context4.next = 3;
237
+ resourceId = data.resourceId;
238
+ _context4.prev = 1;
239
+ _context4.next = 4;
240
+ return createSyncedBlock({
241
+ blockAri: resourceId,
242
+ blockInstanceId: data.blockInstanceId,
243
+ sourceAri: this.sourceAri,
244
+ product: this.product,
245
+ content: JSON.stringify(data.content)
246
+ });
247
+ case 4:
248
+ return _context4.abrupt("return", {
249
+ resourceId: resourceId
250
+ });
251
+ case 7:
252
+ _context4.prev = 7;
253
+ _context4.t0 = _context4["catch"](1);
254
+ if (!(_context4.t0 instanceof BlockError)) {
255
+ _context4.next = 11;
256
+ break;
257
+ }
258
+ return _context4.abrupt("return", {
259
+ error: mapBlockError(_context4.t0),
260
+ resourceId: resourceId
261
+ });
262
+ case 11:
263
+ return _context4.abrupt("return", {
264
+ error: stringifyError(_context4.t0),
265
+ resourceId: resourceId
266
+ });
267
+ case 12:
268
+ case "end":
269
+ return _context4.stop();
270
+ }
271
+ }, _callee4, this, [[1, 7]]);
272
+ }));
273
+ function createData(_x4) {
274
+ return _createData.apply(this, arguments);
275
+ }
276
+ return createData;
277
+ }() // soft deletes the source synced block
278
+ }, {
279
+ key: "deleteData",
280
+ value: function () {
281
+ var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resourceId) {
282
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
283
+ while (1) switch (_context5.prev = _context5.next) {
284
+ case 0:
285
+ _context5.prev = 0;
286
+ _context5.next = 3;
254
287
  return deleteSyncedBlock({
255
288
  blockAri: resourceId
256
289
  });
257
290
  case 3:
258
- return _context4.abrupt("return", {
291
+ return _context5.abrupt("return", {
259
292
  resourceId: resourceId,
260
293
  success: true,
261
294
  error: undefined
262
295
  });
263
296
  case 6:
264
- _context4.prev = 6;
265
- _context4.t0 = _context4["catch"](0);
266
- if (!(_context4.t0 instanceof BlockError)) {
267
- _context4.next = 10;
297
+ _context5.prev = 6;
298
+ _context5.t0 = _context5["catch"](0);
299
+ if (!(_context5.t0 instanceof BlockError)) {
300
+ _context5.next = 10;
268
301
  break;
269
302
  }
270
- return _context4.abrupt("return", {
303
+ return _context5.abrupt("return", {
271
304
  resourceId: resourceId,
272
305
  success: false,
273
- error: mapBlockError(_context4.t0)
306
+ error: mapBlockError(_context5.t0)
274
307
  });
275
308
  case 10:
276
- return _context4.abrupt("return", {
309
+ return _context5.abrupt("return", {
277
310
  resourceId: resourceId,
278
311
  success: false,
279
- error: stringifyError(_context4.t0)
312
+ error: stringifyError(_context5.t0)
280
313
  });
281
314
  case 11:
282
315
  case "end":
283
- return _context4.stop();
316
+ return _context5.stop();
284
317
  }
285
- }, _callee4, null, [[0, 6]]);
318
+ }, _callee5, null, [[0, 6]]);
286
319
  }));
287
- function deleteData(_x4) {
320
+ function deleteData(_x5) {
288
321
  return _deleteData.apply(this, arguments);
289
322
  }
290
323
  return deleteData;
@@ -254,37 +254,23 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
254
254
  resourceId: resourceId
255
255
  });
256
256
  case 23:
257
- if (updateResult) {
258
- _context3.next = 27;
259
- break;
260
- }
261
- return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType).then(function () {
262
- return {
263
- resourceId: resourceId
264
- };
265
- }, function (error) {
266
- return {
267
- error: error
268
- };
269
- }));
270
- case 27:
271
257
  return _context3.abrupt("return", {
272
258
  error: "Failed to update ".concat(pageType, " content property")
273
259
  });
274
- case 28:
275
- _context3.next = 33;
260
+ case 24:
261
+ _context3.next = 29;
276
262
  break;
277
- case 30:
278
- _context3.prev = 30;
263
+ case 26:
264
+ _context3.prev = 26;
279
265
  _context3.t1 = _context3["catch"](9);
280
266
  return _context3.abrupt("return", {
281
267
  error: "Failed to write ".concat(pageType)
282
268
  });
283
- case 33:
269
+ case 29:
284
270
  case "end":
285
271
  return _context3.stop();
286
272
  }
287
- }, _callee3, this, [[1, 5], [9, 30]]);
273
+ }, _callee3, this, [[1, 5], [9, 26]]);
288
274
  }));
289
275
  function writeData(_x6) {
290
276
  return _writeData.apply(this, arguments);
@@ -292,28 +278,80 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
292
278
  return writeData;
293
279
  }()
294
280
  }, {
295
- key: "deleteData",
281
+ key: "createData",
296
282
  value: function () {
297
- var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(resourceId) {
298
- var deletePayload, deleteResult, match, _match2, pageId, pageType, localId, key, options, _stringifyError;
283
+ var _createData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(syncBlockData) {
284
+ var match, resourceId, _match2, pageId, pageType, localId, key, sourceAri, syncBlockDataWithSourceDocumentAri;
299
285
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
300
286
  while (1) switch (_context4.prev = _context4.next) {
301
287
  case 0:
302
- _context4.prev = 0;
288
+ resourceId = syncBlockData.resourceId;
289
+ _context4.prev = 1;
303
290
  match = getPageIdAndTypeFromConfluencePageAri(resourceId);
304
- _context4.next = 7;
291
+ _context4.next = 8;
305
292
  break;
306
- case 4:
307
- _context4.prev = 4;
308
- _context4.t0 = _context4["catch"](0);
293
+ case 5:
294
+ _context4.prev = 5;
295
+ _context4.t0 = _context4["catch"](1);
296
+ return _context4.abrupt("return", {
297
+ error: stringifyError(_context4.t0)
298
+ });
299
+ case 8:
300
+ _match2 = match, pageId = _match2.id, pageType = _match2.type;
301
+ _context4.prev = 9;
302
+ localId = getLocalIdFromConfluencePageAri(resourceId);
303
+ key = getContentPropertyKey(this.config.contentPropertyKey, localId);
304
+ sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
305
+ syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, syncBlockData), {}, {
306
+ product: 'confluence-page',
307
+ sourceAri: sourceAri
308
+ });
309
+ _context4.next = 16;
310
+ return this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType);
311
+ case 16:
309
312
  return _context4.abrupt("return", {
313
+ resourceId: resourceId
314
+ });
315
+ case 19:
316
+ _context4.prev = 19;
317
+ _context4.t1 = _context4["catch"](9);
318
+ return _context4.abrupt("return", Promise.resolve({
319
+ error: stringifyError(_context4.t1)
320
+ }));
321
+ case 22:
322
+ case "end":
323
+ return _context4.stop();
324
+ }
325
+ }, _callee4, this, [[1, 5], [9, 19]]);
326
+ }));
327
+ function createData(_x7) {
328
+ return _createData.apply(this, arguments);
329
+ }
330
+ return createData;
331
+ }()
332
+ }, {
333
+ key: "deleteData",
334
+ value: function () {
335
+ var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resourceId) {
336
+ var deletePayload, deleteResult, match, _match3, pageId, pageType, localId, key, options, _stringifyError;
337
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
338
+ while (1) switch (_context5.prev = _context5.next) {
339
+ case 0:
340
+ _context5.prev = 0;
341
+ match = getPageIdAndTypeFromConfluencePageAri(resourceId);
342
+ _context5.next = 7;
343
+ break;
344
+ case 4:
345
+ _context5.prev = 4;
346
+ _context5.t0 = _context5["catch"](0);
347
+ return _context5.abrupt("return", {
310
348
  resourceId: resourceId,
311
349
  success: false,
312
- error: stringifyError(_context4.t0)
350
+ error: stringifyError(_context5.t0)
313
351
  });
314
352
  case 7:
315
- _match2 = match, pageId = _match2.id, pageType = _match2.type;
316
- _context4.prev = 8;
353
+ _match3 = match, pageId = _match3.id, pageType = _match3.type;
354
+ _context5.prev = 8;
317
355
  localId = getLocalIdFromConfluencePageAri(resourceId);
318
356
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
319
357
  options = {
@@ -322,34 +360,34 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
322
360
  cloudId: this.config.cloudId,
323
361
  pageType: pageType
324
362
  };
325
- _context4.next = 14;
363
+ _context5.next = 14;
326
364
  return deleteContentProperty(options);
327
365
  case 14:
328
- deletePayload = _context4.sent;
366
+ deletePayload = _context5.sent;
329
367
  deleteResult = isBlogPageType(pageType) ? deletePayload.data.confluence.deleteBlogPostProperty : deletePayload.data.confluence.deletePageProperty;
330
- _context4.next = 21;
368
+ _context5.next = 21;
331
369
  break;
332
370
  case 18:
333
- _context4.prev = 18;
334
- _context4.t1 = _context4["catch"](8);
335
- return _context4.abrupt("return", {
371
+ _context5.prev = 18;
372
+ _context5.t1 = _context5["catch"](8);
373
+ return _context5.abrupt("return", {
336
374
  resourceId: resourceId,
337
375
  success: false,
338
- error: (_stringifyError = stringifyError(_context4.t1)) !== null && _stringifyError !== void 0 ? _stringifyError : "Fail to delete ".concat(pageType, " content property")
376
+ error: (_stringifyError = stringifyError(_context5.t1)) !== null && _stringifyError !== void 0 ? _stringifyError : "Fail to delete ".concat(pageType, " content property")
339
377
  });
340
378
  case 21:
341
- return _context4.abrupt("return", {
379
+ return _context5.abrupt("return", {
342
380
  resourceId: resourceId,
343
381
  success: deleteResult.success,
344
382
  error: deleteResult.errors.join()
345
383
  });
346
384
  case 22:
347
385
  case "end":
348
- return _context4.stop();
386
+ return _context5.stop();
349
387
  }
350
- }, _callee4, this, [[0, 4], [8, 18]]);
388
+ }, _callee5, this, [[0, 4], [8, 18]]);
351
389
  }));
352
- function deleteData(_x7) {
390
+ function deleteData(_x8) {
353
391
  return _deleteData.apply(this, arguments);
354
392
  }
355
393
  return deleteData;
@@ -143,7 +143,19 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
143
143
  return _writeNodesData.apply(this, arguments);
144
144
  }
145
145
  return writeNodesData;
146
- }()
146
+ }())
147
+ }, {
148
+ key: "createNodeData",
149
+ value: function createNodeData(data) {
150
+ return this.writeProvider.createData(data).then(function (result) {
151
+ return result;
152
+ }, function (error) {
153
+ return {
154
+ error: error
155
+ };
156
+ });
157
+ }
158
+
147
159
  /**
148
160
  * Delete the data from the write provider
149
161
  *
@@ -151,7 +163,6 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
151
163
  *
152
164
  * @returns Array of {resourceId?: string, error?: string}.
153
165
  */
154
- )
155
166
  }, {
156
167
  key: "deleteNodesData",
157
168
  value: (function () {
@@ -227,17 +227,15 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
227
227
  (_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'));
228
228
  return;
229
229
  }
230
+ var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
231
+ var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
232
+ _this2.updateCache(resolvedSyncBlockInstance);
233
+ resolvedData.push(resolvedSyncBlockInstance);
230
234
  if (syncBlockInstance.error) {
231
235
  var _this2$fireAnalyticsE2;
232
236
  (_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, fetchErrorPayload(syncBlockInstance.error));
233
- _this2.updateCache(syncBlockInstance);
234
- resolvedData.push(syncBlockInstance);
235
237
  return;
236
238
  }
237
- var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
238
- var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
239
- _this2.updateCache(resolvedSyncBlockInstance);
240
- resolvedData.push(resolvedSyncBlockInstance);
241
239
  _this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
242
240
  });
243
241
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
@@ -7,7 +7,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
7
7
  import uuid from 'uuid';
8
8
  import { logException } from '@atlaskit/editor-common/monitoring';
9
9
  import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
10
- import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _createBodiedSyncBlockNode } from '../utils/utils';
10
+ import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
11
11
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
12
12
  // Designed to manage local in-memory state and synchronize with an external data provider.
13
13
  // Supports create, flush, and delete operations for source sync blocks.
@@ -233,21 +233,19 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
233
233
  }
234
234
  var resourceId = attrs.resourceId,
235
235
  blockInstanceId = attrs.localId;
236
- this.dataProvider.writeNodesData([_createBodiedSyncBlockNode(blockInstanceId, resourceId)], [{
236
+ this.dataProvider.createNodeData({
237
237
  content: [],
238
238
  blockInstanceId: blockInstanceId,
239
239
  resourceId: resourceId
240
- }]).then(function (results) {
241
- results.forEach(function (result) {
242
- var resourceId = result.resourceId;
243
- if (resourceId) {
244
- _this4.commitPendingCreation(true);
245
- } else {
246
- var _this4$fireAnalyticsE;
247
- _this4.commitPendingCreation(false);
248
- (_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, createErrorPayload(result.error || 'Failed to create bodied sync block'));
249
- }
250
- });
240
+ }).then(function (result) {
241
+ var resourceId = result.resourceId;
242
+ if (resourceId) {
243
+ _this4.commitPendingCreation(true);
244
+ } else {
245
+ var _this4$fireAnalyticsE;
246
+ _this4.commitPendingCreation(false);
247
+ (_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, createErrorPayload(result.error || 'Failed to create bodied sync block'));
248
+ }
251
249
  }).catch(function (error) {
252
250
  var _this4$fireAnalyticsE2;
253
251
  _this4.commitPendingCreation(false);
@@ -1,6 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  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; }
3
3
  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) { _defineProperty(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; }
4
+ import { SyncBlockError } from '../common/types';
4
5
  /**
5
6
  * Merges two SyncBlockInstance objects,
6
7
  * currently it only preserves the sourceURL from the old result,
@@ -13,13 +14,16 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
13
14
  */
14
15
  export var resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResult, newResult) {
15
16
  var _newResult$data, _oldResult$data, _newResult$data2, _oldResult$data2;
16
- // if the old result has no data, we simple return the new result
17
+ // if the old result has no data, we simply return the new result
17
18
  if (!oldResult.data) {
18
19
  return newResult;
19
20
  } else if (!newResult.data) {
20
- // if the new result has no data, we simply return the old result
21
- // TODO: EDITOR-2533 - handle this case based on the error type and whether we should keep old data or not
22
- return oldResult;
21
+ // return the old result if there was an error, e.g. network error, but not if not found or forbidden
22
+ if (newResult.error === SyncBlockError.Errored) {
23
+ return oldResult;
24
+ } else {
25
+ return newResult;
26
+ }
23
27
  }
24
28
 
25
29
  // otherwise, we merge the two results, preserving the sourceURL and sourceTitle from the old result if it exists
@@ -14,15 +14,6 @@ export var createSyncBlockNode = function createSyncBlockNode(localId, resourceI
14
14
  }
15
15
  };
16
16
  };
17
- export var createBodiedSyncBlockNode = function createBodiedSyncBlockNode(localId, resourceId) {
18
- return {
19
- type: 'bodiedSyncBlock',
20
- attrs: {
21
- localId: localId,
22
- resourceId: resourceId
23
- }
24
- };
25
- };
26
17
  export var convertSyncBlockJSONNodeToSyncBlockNode = function convertSyncBlockJSONNodeToSyncBlockNode(node) {
27
18
  if (node.type !== 'syncBlock' || !node.attrs || !('localId' in node.attrs) || !('resourceId' in node.attrs) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
28
19
  return undefined;
@@ -15,6 +15,7 @@ declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
15
15
  private product;
16
16
  constructor(sourceAri: string, product: SyncBlockProduct);
17
17
  writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
18
+ createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
18
19
  deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
19
20
  generateResourceId(sourceAri: string, localId: string): string;
20
21
  }
@@ -23,6 +23,7 @@ declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
23
23
  constructor(config: ContentAPIConfig);
24
24
  private createNewContentProperty;
25
25
  writeData(syncBlockData: SyncBlockData): Promise<WriteSyncBlockResult>;
26
+ createData(syncBlockData: SyncBlockData): Promise<WriteSyncBlockResult>;
26
27
  deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
27
28
  generateResourceId(sourceId: string, localId: string): string;
28
29
  }
@@ -51,6 +51,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
51
51
  * resourceId: resource id of the node if write successfully , error: reason for when write failed
52
52
  */
53
53
  writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
54
+ createNodeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
54
55
  /**
55
56
  * Delete the data from the write provider
56
57
  *
@@ -40,6 +40,7 @@ export interface ADFFetchProvider {
40
40
  fetchData: (resourceId: ResourceId) => Promise<SyncBlockInstance>;
41
41
  }
42
42
  export interface ADFWriteProvider {
43
+ createData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
43
44
  deleteData: (resourceId: ResourceId) => Promise<DeleteSyncBlockResult>;
44
45
  generateResourceId: (sourceId: string, localId: string) => ResourceId;
45
46
  writeData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
@@ -63,6 +64,7 @@ export type SyncedBlockRendererProviderOptions = {
63
64
  };
64
65
  export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockInstance> {
65
66
  abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
67
+ abstract createNodeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
66
68
  abstract deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
67
69
  abstract getSourceId(): ResourceId;
68
70
  abstract fetchSyncBlockSourceInfo(localId: BlockInstanceId, sourceAri: string, sourceProduct: SyncBlockProduct, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): Promise<SyncBlockSourceInfo | undefined>;
@@ -3,7 +3,6 @@ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode } from '../common/types';
4
4
  export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode) => SyncBlockData;
5
5
  export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
6
- export declare const createBodiedSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
7
6
  export declare const convertSyncBlockJSONNodeToSyncBlockNode: (node: JSONNode) => SyncBlockNode | undefined;
8
7
  export declare const convertPMNodeToSyncBlockNode: (node: PMNode) => SyncBlockNode | undefined;
9
8
  export declare const convertPMNodesToSyncBlockNodes: (nodes: PMNode[]) => SyncBlockNode[];
@@ -15,6 +15,7 @@ declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
15
15
  private product;
16
16
  constructor(sourceAri: string, product: SyncBlockProduct);
17
17
  writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
18
+ createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
18
19
  deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
19
20
  generateResourceId(sourceAri: string, localId: string): string;
20
21
  }
@@ -23,6 +23,7 @@ declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
23
23
  constructor(config: ContentAPIConfig);
24
24
  private createNewContentProperty;
25
25
  writeData(syncBlockData: SyncBlockData): Promise<WriteSyncBlockResult>;
26
+ createData(syncBlockData: SyncBlockData): Promise<WriteSyncBlockResult>;
26
27
  deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
27
28
  generateResourceId(sourceId: string, localId: string): string;
28
29
  }
@@ -51,6 +51,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
51
51
  * resourceId: resource id of the node if write successfully , error: reason for when write failed
52
52
  */
53
53
  writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
54
+ createNodeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
54
55
  /**
55
56
  * Delete the data from the write provider
56
57
  *